cluster.go 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813
  1. package router
  2. import (
  3. "fmt"
  4. "github.com/go-chi/chi/v5"
  5. "github.com/porter-dev/porter/api/server/handlers/cluster"
  6. "github.com/porter-dev/porter/api/server/handlers/database"
  7. "github.com/porter-dev/porter/api/server/handlers/datastore"
  8. "github.com/porter-dev/porter/api/server/handlers/environment"
  9. "github.com/porter-dev/porter/api/server/handlers/environment_groups"
  10. "github.com/porter-dev/porter/api/server/shared"
  11. "github.com/porter-dev/porter/api/server/shared/config"
  12. "github.com/porter-dev/porter/api/server/shared/router"
  13. "github.com/porter-dev/porter/api/types"
  14. )
  15. func NewClusterScopedRegisterer(children ...*router.Registerer) *router.Registerer {
  16. return &router.Registerer{
  17. GetRoutes: GetClusterScopedRoutes,
  18. Children: children,
  19. }
  20. }
  21. func GetClusterScopedRoutes(
  22. r chi.Router,
  23. config *config.Config,
  24. basePath *types.Path,
  25. factory shared.APIEndpointFactory,
  26. children ...*router.Registerer,
  27. ) []*router.Route {
  28. routes, projPath := getClusterRoutes(r, config, basePath, factory)
  29. if len(children) > 0 {
  30. r.Route(projPath.RelativePath, func(r chi.Router) {
  31. for _, child := range children {
  32. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  33. routes = append(routes, childRoutes...)
  34. }
  35. })
  36. }
  37. return routes
  38. }
  39. func getClusterRoutes(
  40. r chi.Router,
  41. config *config.Config,
  42. basePath *types.Path,
  43. factory shared.APIEndpointFactory,
  44. ) ([]*router.Route, *types.Path) {
  45. relPath := "/clusters/{cluster_id}"
  46. newPath := &types.Path{
  47. Parent: basePath,
  48. RelativePath: relPath,
  49. }
  50. routes := make([]*router.Route, 0)
  51. // POST /api/projects/{project_id}/clusters -> project.NewCreateClusterManualHandler
  52. createEndpoint := factory.NewAPIEndpoint(
  53. &types.APIRequestMetadata{
  54. Verb: types.APIVerbCreate,
  55. Method: types.HTTPVerbPost,
  56. Path: &types.Path{
  57. Parent: basePath,
  58. RelativePath: "/clusters",
  59. },
  60. Scopes: []types.PermissionScope{
  61. types.UserScope,
  62. types.ProjectScope,
  63. },
  64. },
  65. )
  66. createHandler := cluster.NewCreateClusterManualHandler(
  67. config,
  68. factory.GetDecoderValidator(),
  69. factory.GetResultWriter(),
  70. )
  71. routes = append(routes, &router.Route{
  72. Endpoint: createEndpoint,
  73. Handler: createHandler,
  74. Router: r,
  75. })
  76. // POST /api/projects/{project_id}/clusters/candidates -> project.NewCreateClusterCandidateHandler
  77. createCandidateEndpoint := factory.NewAPIEndpoint(
  78. &types.APIRequestMetadata{
  79. Verb: types.APIVerbCreate,
  80. Method: types.HTTPVerbPost,
  81. Path: &types.Path{
  82. Parent: basePath,
  83. RelativePath: "/clusters/candidates",
  84. },
  85. Scopes: []types.PermissionScope{
  86. types.UserScope,
  87. types.ProjectScope,
  88. },
  89. CheckUsage: true,
  90. UsageMetric: types.Clusters,
  91. },
  92. )
  93. createCandidateHandler := cluster.NewCreateClusterCandidateHandler(
  94. config,
  95. factory.GetDecoderValidator(),
  96. factory.GetResultWriter(),
  97. )
  98. routes = append(routes, &router.Route{
  99. Endpoint: createCandidateEndpoint,
  100. Handler: createCandidateHandler,
  101. Router: r,
  102. })
  103. // GET /api/projects/{project_id}/clusters/candidates -> project.NewListClusterCandidatesHandler
  104. listCandidatesEndpoint := factory.NewAPIEndpoint(
  105. &types.APIRequestMetadata{
  106. Verb: types.APIVerbList,
  107. Method: types.HTTPVerbGet,
  108. Path: &types.Path{
  109. Parent: basePath,
  110. RelativePath: "/clusters/candidates",
  111. },
  112. Scopes: []types.PermissionScope{
  113. types.UserScope,
  114. types.ProjectScope,
  115. },
  116. },
  117. )
  118. listCandidatesHandler := cluster.NewListClusterCandidatesHandler(
  119. config,
  120. factory.GetResultWriter(),
  121. )
  122. routes = append(routes, &router.Route{
  123. Endpoint: listCandidatesEndpoint,
  124. Handler: listCandidatesHandler,
  125. Router: r,
  126. })
  127. // POST /api/projects/{project_id}/clusters/candidates/{candidate_id}/resolve -> project.NewResolveClusterCandidateHandler
  128. resolveCandidateEndpoint := factory.NewAPIEndpoint(
  129. &types.APIRequestMetadata{
  130. Verb: types.APIVerbCreate,
  131. Method: types.HTTPVerbPost,
  132. Path: &types.Path{
  133. Parent: basePath,
  134. RelativePath: fmt.Sprintf(
  135. "/clusters/candidates/{%s}/resolve",
  136. types.URLParamCandidateID,
  137. ),
  138. },
  139. Scopes: []types.PermissionScope{
  140. types.UserScope,
  141. types.ProjectScope,
  142. },
  143. CheckUsage: true,
  144. UsageMetric: types.Clusters,
  145. },
  146. )
  147. resolveCandidateHandler := cluster.NewResolveClusterCandidateHandler(
  148. config,
  149. factory.GetDecoderValidator(),
  150. factory.GetResultWriter(),
  151. )
  152. routes = append(routes, &router.Route{
  153. Endpoint: resolveCandidateEndpoint,
  154. Handler: resolveCandidateHandler,
  155. Router: r,
  156. })
  157. // POST /api/projects/{project_id}/clusters/{cluster_id} -> project.NewClusterUpdateHandler
  158. updateClusterEndpoint := factory.NewAPIEndpoint(
  159. &types.APIRequestMetadata{
  160. Verb: types.APIVerbUpdate,
  161. Method: types.HTTPVerbPost,
  162. Path: &types.Path{
  163. Parent: basePath,
  164. RelativePath: relPath,
  165. },
  166. Scopes: []types.PermissionScope{
  167. types.UserScope,
  168. types.ProjectScope,
  169. types.ClusterScope,
  170. },
  171. },
  172. )
  173. updateClusterHandler := cluster.NewClusterUpdateHandler(
  174. config,
  175. factory.GetDecoderValidator(),
  176. factory.GetResultWriter(),
  177. )
  178. routes = append(routes, &router.Route{
  179. Endpoint: updateClusterEndpoint,
  180. Handler: updateClusterHandler,
  181. Router: r,
  182. })
  183. // DELETE /api/projects/{project_id}/clusters/{cluster_id} -> project.NewClusterDeleteHandler
  184. deleteClusterEndpoint := factory.NewAPIEndpoint(
  185. &types.APIRequestMetadata{
  186. Verb: types.APIVerbDelete,
  187. Method: types.HTTPVerbDelete,
  188. Path: &types.Path{
  189. Parent: basePath,
  190. RelativePath: relPath,
  191. },
  192. Scopes: []types.PermissionScope{
  193. types.UserScope,
  194. types.ProjectScope,
  195. types.ClusterScope,
  196. },
  197. },
  198. )
  199. deleteClusterHandler := cluster.NewClusterDeleteHandler(
  200. config,
  201. factory.GetResultWriter(),
  202. )
  203. routes = append(routes, &router.Route{
  204. Endpoint: deleteClusterEndpoint,
  205. Handler: deleteClusterHandler,
  206. Router: r,
  207. })
  208. // GET /api/projects/{project_id}/clusters/{cluster_id} -> project.NewClusterGetHandler
  209. getEndpoint := factory.NewAPIEndpoint(
  210. &types.APIRequestMetadata{
  211. Verb: types.APIVerbGet,
  212. Method: types.HTTPVerbGet,
  213. Path: &types.Path{
  214. Parent: basePath,
  215. RelativePath: relPath,
  216. },
  217. Scopes: []types.PermissionScope{
  218. types.UserScope,
  219. types.ProjectScope,
  220. types.ClusterScope,
  221. },
  222. },
  223. )
  224. getHandler := cluster.NewClusterGetHandler(
  225. config,
  226. factory.GetResultWriter(),
  227. )
  228. routes = append(routes, &router.Route{
  229. Endpoint: getEndpoint,
  230. Handler: getHandler,
  231. Router: r,
  232. })
  233. // GET /api/projects/{project_id}/clusters/{cluster_id}/databases -> database.NewDatabaseListHandler
  234. listDatabaseEndpoint := factory.NewAPIEndpoint(
  235. &types.APIRequestMetadata{
  236. Verb: types.APIVerbList,
  237. Method: types.HTTPVerbGet,
  238. Path: &types.Path{
  239. Parent: basePath,
  240. RelativePath: relPath + "/databases",
  241. },
  242. Scopes: []types.PermissionScope{
  243. types.UserScope,
  244. types.ProjectScope,
  245. types.ClusterScope,
  246. },
  247. },
  248. )
  249. listDatabaseHandler := database.NewDatabaseListHandler(
  250. config,
  251. factory.GetResultWriter(),
  252. )
  253. routes = append(routes, &router.Route{
  254. Endpoint: listDatabaseEndpoint,
  255. Handler: listDatabaseHandler,
  256. Router: r,
  257. })
  258. // GET /api/projects/{project_id}/clusters/{cluster_id}/datastore/status -> datastore.NewStatusHandler
  259. datastoreStatusEndpoint := factory.NewAPIEndpoint(
  260. &types.APIRequestMetadata{
  261. Verb: types.APIVerbList,
  262. Method: types.HTTPVerbGet,
  263. Path: &types.Path{
  264. Parent: basePath,
  265. RelativePath: relPath + "/datastore/status",
  266. },
  267. Scopes: []types.PermissionScope{
  268. types.UserScope,
  269. types.ProjectScope,
  270. types.ClusterScope,
  271. },
  272. },
  273. )
  274. datastoreStatusHandler := datastore.NewStatusHandler(
  275. config,
  276. factory.GetDecoderValidator(),
  277. factory.GetResultWriter(),
  278. )
  279. routes = append(routes, &router.Route{
  280. Endpoint: datastoreStatusEndpoint,
  281. Handler: datastoreStatusHandler,
  282. Router: r,
  283. })
  284. if config.ServerConf.GithubIncomingWebhookSecret != "" {
  285. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments -> environment.NewListEnvironmentHandler
  286. listEnvEndpoint := factory.NewAPIEndpoint(
  287. &types.APIRequestMetadata{
  288. Verb: types.APIVerbGet,
  289. Method: types.HTTPVerbGet,
  290. Path: &types.Path{
  291. Parent: basePath,
  292. RelativePath: relPath + "/environments",
  293. },
  294. Scopes: []types.PermissionScope{
  295. types.UserScope,
  296. types.ProjectScope,
  297. types.ClusterScope,
  298. types.PreviewEnvironmentScope,
  299. },
  300. },
  301. )
  302. listEnvHandler := environment.NewListEnvironmentHandler(
  303. config,
  304. factory.GetResultWriter(),
  305. )
  306. routes = append(routes, &router.Route{
  307. Endpoint: listEnvEndpoint,
  308. Handler: listEnvHandler,
  309. Router: r,
  310. })
  311. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id} -> environment.NewGetEnvironmentHandler
  312. getEnvEndpoint := factory.NewAPIEndpoint(
  313. &types.APIRequestMetadata{
  314. Verb: types.APIVerbGet,
  315. Method: types.HTTPVerbGet,
  316. Path: &types.Path{
  317. Parent: basePath,
  318. RelativePath: relPath + "/environments/{environment_id}",
  319. },
  320. Scopes: []types.PermissionScope{
  321. types.UserScope,
  322. types.ProjectScope,
  323. types.ClusterScope,
  324. types.PreviewEnvironmentScope,
  325. },
  326. },
  327. )
  328. getEnvHandler := environment.NewGetEnvironmentHandler(
  329. config,
  330. factory.GetResultWriter(),
  331. )
  332. routes = append(routes, &router.Route{
  333. Endpoint: getEnvEndpoint,
  334. Handler: getEnvHandler,
  335. Router: r,
  336. })
  337. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/toggle_new_comment -> environment.NewToggleNewCommentHandler
  338. toggleNewCommentEndpoint := factory.NewAPIEndpoint(
  339. &types.APIRequestMetadata{
  340. Verb: types.APIVerbUpdate,
  341. Method: types.HTTPVerbPatch,
  342. Path: &types.Path{
  343. Parent: basePath,
  344. RelativePath: relPath + "/environments/{environment_id}/toggle_new_comment",
  345. },
  346. Scopes: []types.PermissionScope{
  347. types.UserScope,
  348. types.ProjectScope,
  349. types.ClusterScope,
  350. types.PreviewEnvironmentScope,
  351. },
  352. },
  353. )
  354. toggleNewCommentHandler := environment.NewToggleNewCommentHandler(
  355. config,
  356. factory.GetDecoderValidator(),
  357. factory.GetResultWriter(),
  358. )
  359. routes = append(routes, &router.Route{
  360. Endpoint: toggleNewCommentEndpoint,
  361. Handler: toggleNewCommentHandler,
  362. Router: r,
  363. })
  364. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/validate_porter_yaml -> environment.NewValidatePorterYAMLHandler
  365. validtatePorterYAMLEndpoint := factory.NewAPIEndpoint(
  366. &types.APIRequestMetadata{
  367. Verb: types.APIVerbGet,
  368. Method: types.HTTPVerbGet,
  369. Path: &types.Path{
  370. Parent: basePath,
  371. RelativePath: relPath + "/environments/{environment_id}/validate_porter_yaml",
  372. },
  373. Scopes: []types.PermissionScope{
  374. types.UserScope,
  375. types.ProjectScope,
  376. types.ClusterScope,
  377. types.PreviewEnvironmentScope,
  378. },
  379. },
  380. )
  381. validatePorterYAMLHandler := environment.NewValidatePorterYAMLHandler(
  382. config,
  383. factory.GetDecoderValidator(),
  384. factory.GetResultWriter(),
  385. )
  386. routes = append(routes, &router.Route{
  387. Endpoint: validtatePorterYAMLEndpoint,
  388. Handler: validatePorterYAMLHandler,
  389. Router: r,
  390. })
  391. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments -> environment.NewCreateDeploymentByClusterHandler
  392. createDeploymentEndpoint := factory.NewAPIEndpoint(
  393. &types.APIRequestMetadata{
  394. Verb: types.APIVerbCreate,
  395. Method: types.HTTPVerbPost,
  396. Path: &types.Path{
  397. Parent: basePath,
  398. RelativePath: relPath + "/deployments",
  399. },
  400. Scopes: []types.PermissionScope{
  401. types.UserScope,
  402. types.ProjectScope,
  403. types.ClusterScope,
  404. types.PreviewEnvironmentScope,
  405. },
  406. },
  407. )
  408. createDeploymentHandler := environment.NewCreateDeploymentByClusterHandler(
  409. config,
  410. factory.GetDecoderValidator(),
  411. factory.GetResultWriter(),
  412. )
  413. routes = append(routes, &router.Route{
  414. Endpoint: createDeploymentEndpoint,
  415. Handler: createDeploymentHandler,
  416. Router: r,
  417. })
  418. // GET /api/projects/{project_id}/clusters/{cluster_id}/deployments -> environment.NewListDeploymentsByClusterHandler
  419. listDeploymentsEndpoint := factory.NewAPIEndpoint(
  420. &types.APIRequestMetadata{
  421. Verb: types.APIVerbGet,
  422. Method: types.HTTPVerbGet,
  423. Path: &types.Path{
  424. Parent: basePath,
  425. RelativePath: relPath + "/deployments",
  426. },
  427. Scopes: []types.PermissionScope{
  428. types.UserScope,
  429. types.ProjectScope,
  430. types.ClusterScope,
  431. types.PreviewEnvironmentScope,
  432. },
  433. },
  434. )
  435. listDeploymentsHandler := environment.NewListDeploymentsByClusterHandler(
  436. config,
  437. factory.GetDecoderValidator(),
  438. factory.GetResultWriter(),
  439. )
  440. routes = append(routes, &router.Route{
  441. Endpoint: listDeploymentsEndpoint,
  442. Handler: listDeploymentsHandler,
  443. Router: r,
  444. })
  445. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/deployments -> environment.NewUpdateDeploymentByClusterHandler
  446. updateDeploymentEndpoint := factory.NewAPIEndpoint(
  447. &types.APIRequestMetadata{
  448. Verb: types.APIVerbUpdate,
  449. Method: types.HTTPVerbPatch,
  450. Path: &types.Path{
  451. Parent: basePath,
  452. RelativePath: relPath + "/deployments",
  453. },
  454. Scopes: []types.PermissionScope{
  455. types.UserScope,
  456. types.ProjectScope,
  457. types.ClusterScope,
  458. types.PreviewEnvironmentScope,
  459. },
  460. },
  461. )
  462. updateDeploymentHandler := environment.NewUpdateDeploymentByClusterHandler(
  463. config,
  464. factory.GetDecoderValidator(),
  465. factory.GetResultWriter(),
  466. )
  467. routes = append(routes, &router.Route{
  468. Endpoint: updateDeploymentEndpoint,
  469. Handler: updateDeploymentHandler,
  470. Router: r,
  471. })
  472. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/deployments/status -> environment.NewUpdateDeploymentStatusByClusterHandler
  473. updateDeploymentStatusEndpoint := factory.NewAPIEndpoint(
  474. &types.APIRequestMetadata{
  475. Verb: types.APIVerbUpdate,
  476. Method: types.HTTPVerbPatch,
  477. Path: &types.Path{
  478. Parent: basePath,
  479. RelativePath: relPath + "/deployments/status",
  480. },
  481. Scopes: []types.PermissionScope{
  482. types.UserScope,
  483. types.ProjectScope,
  484. types.ClusterScope,
  485. types.PreviewEnvironmentScope,
  486. },
  487. },
  488. )
  489. updateDeploymentStatusHandler := environment.NewUpdateDeploymentStatusByClusterHandler(
  490. config,
  491. factory.GetDecoderValidator(),
  492. factory.GetResultWriter(),
  493. )
  494. routes = append(routes, &router.Route{
  495. Endpoint: updateDeploymentStatusEndpoint,
  496. Handler: updateDeploymentStatusHandler,
  497. Router: r,
  498. })
  499. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/deployment -> environment.NewGetDeploymentByClusterHandler
  500. getDeploymentEndpoint := factory.NewAPIEndpoint(
  501. &types.APIRequestMetadata{
  502. Verb: types.APIVerbGet,
  503. Method: types.HTTPVerbGet,
  504. Path: &types.Path{
  505. Parent: basePath,
  506. RelativePath: relPath + "/environments/{environment_id}/deployment",
  507. },
  508. Scopes: []types.PermissionScope{
  509. types.UserScope,
  510. types.ProjectScope,
  511. types.ClusterScope,
  512. types.PreviewEnvironmentScope,
  513. },
  514. },
  515. )
  516. getDeploymentHandler := environment.NewGetDeploymentByEnvironmentHandler(
  517. config,
  518. factory.GetDecoderValidator(),
  519. factory.GetResultWriter(),
  520. )
  521. routes = append(routes, &router.Route{
  522. Endpoint: getDeploymentEndpoint,
  523. Handler: getDeploymentHandler,
  524. Router: r,
  525. })
  526. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/finalize ->
  527. // environment.NewFinalizeDeploymentByClusterHandler
  528. finalizeDeploymentEndpoint := factory.NewAPIEndpoint(
  529. &types.APIRequestMetadata{
  530. Verb: types.APIVerbCreate,
  531. Method: types.HTTPVerbPost,
  532. Path: &types.Path{
  533. Parent: basePath,
  534. RelativePath: relPath + "/deployments/finalize",
  535. },
  536. Scopes: []types.PermissionScope{
  537. types.UserScope,
  538. types.ProjectScope,
  539. types.ClusterScope,
  540. types.PreviewEnvironmentScope,
  541. },
  542. },
  543. )
  544. finalizeDeploymentHandler := environment.NewFinalizeDeploymentByClusterHandler(
  545. config,
  546. factory.GetDecoderValidator(),
  547. factory.GetResultWriter(),
  548. )
  549. routes = append(routes, &router.Route{
  550. Endpoint: finalizeDeploymentEndpoint,
  551. Handler: finalizeDeploymentHandler,
  552. Router: r,
  553. })
  554. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/finalize_errors ->
  555. // environment.NewFinalizeDeploymentWithErrorsHandler
  556. finalizeDeploymentWithErrorsEndpoint := factory.NewAPIEndpoint(
  557. &types.APIRequestMetadata{
  558. Verb: types.APIVerbCreate,
  559. Method: types.HTTPVerbPost,
  560. Path: &types.Path{
  561. Parent: basePath,
  562. RelativePath: relPath + "/deployments/finalize_errors",
  563. },
  564. Scopes: []types.PermissionScope{
  565. types.UserScope,
  566. types.ProjectScope,
  567. types.ClusterScope,
  568. types.PreviewEnvironmentScope,
  569. },
  570. },
  571. )
  572. finalizeDeploymentWithErrorsHandler := environment.NewFinalizeDeploymentWithErrorsByClusterHandler(
  573. config,
  574. factory.GetDecoderValidator(),
  575. factory.GetResultWriter(),
  576. )
  577. routes = append(routes, &router.Route{
  578. Endpoint: finalizeDeploymentWithErrorsEndpoint,
  579. Handler: finalizeDeploymentWithErrorsHandler,
  580. Router: r,
  581. })
  582. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/deployments/{deployment_id}/reenable -> environment.NewReenableDeploymentHandler
  583. reenableDeploymentEndpoint := factory.NewAPIEndpoint(
  584. &types.APIRequestMetadata{
  585. Verb: types.APIVerbUpdate,
  586. Method: types.HTTPVerbPatch,
  587. Path: &types.Path{
  588. Parent: basePath,
  589. RelativePath: relPath + "/deployments/{deployment_id}/reenable",
  590. },
  591. Scopes: []types.PermissionScope{
  592. types.UserScope,
  593. types.ProjectScope,
  594. types.ClusterScope,
  595. types.PreviewEnvironmentScope,
  596. },
  597. },
  598. )
  599. reenableDeploymentHandler := environment.NewReenableDeploymentHandler(
  600. config,
  601. factory.GetDecoderValidator(),
  602. factory.GetResultWriter(),
  603. )
  604. routes = append(routes, &router.Route{
  605. Endpoint: reenableDeploymentEndpoint,
  606. Handler: reenableDeploymentHandler,
  607. Router: r,
  608. })
  609. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/{deployment_id}/trigger_workflow -> environment.NewTriggerDeploymentWorkflowHandler
  610. triggerDeploymentWorkflowEndpoint := factory.NewAPIEndpoint(
  611. &types.APIRequestMetadata{
  612. Verb: types.APIVerbCreate,
  613. Method: types.HTTPVerbPost,
  614. Path: &types.Path{
  615. Parent: basePath,
  616. RelativePath: relPath + "/deployments/{deployment_id}/trigger_workflow",
  617. },
  618. Scopes: []types.PermissionScope{
  619. types.UserScope,
  620. types.ProjectScope,
  621. types.ClusterScope,
  622. types.PreviewEnvironmentScope,
  623. },
  624. },
  625. )
  626. triggerDeploymentWorkflowHandler := environment.NewTriggerDeploymentWorkflowHandler(
  627. config,
  628. factory.GetDecoderValidator(),
  629. factory.GetResultWriter(),
  630. )
  631. routes = append(routes, &router.Route{
  632. Endpoint: triggerDeploymentWorkflowEndpoint,
  633. Handler: triggerDeploymentWorkflowHandler,
  634. Router: r,
  635. })
  636. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/pull_request -> environment.NewEnablePullRequestHandler
  637. enablePullRequestEndpoint := factory.NewAPIEndpoint(
  638. &types.APIRequestMetadata{
  639. Verb: types.APIVerbCreate,
  640. Method: types.HTTPVerbPost,
  641. Path: &types.Path{
  642. Parent: basePath,
  643. RelativePath: relPath + "/deployments/pull_request",
  644. },
  645. Scopes: []types.PermissionScope{
  646. types.UserScope,
  647. types.ProjectScope,
  648. types.ClusterScope,
  649. types.PreviewEnvironmentScope,
  650. },
  651. },
  652. )
  653. enablePullRequestHandler := environment.NewEnablePullRequestHandler(
  654. config,
  655. factory.GetDecoderValidator(),
  656. factory.GetResultWriter(),
  657. )
  658. routes = append(routes, &router.Route{
  659. Endpoint: enablePullRequestEndpoint,
  660. Handler: enablePullRequestHandler,
  661. Router: r,
  662. })
  663. // POST /api/projects/{project_id}/clusters/{cluster_id}/rename -> cluster.NewRenameClusterHandler
  664. renameClusterEndpoint := factory.NewAPIEndpoint(
  665. &types.APIRequestMetadata{
  666. Verb: types.APIVerbCreate,
  667. Method: types.HTTPVerbPost,
  668. Path: &types.Path{
  669. Parent: basePath,
  670. RelativePath: relPath + "/rename",
  671. },
  672. Scopes: []types.PermissionScope{
  673. types.UserScope,
  674. types.ProjectScope,
  675. types.ClusterScope,
  676. },
  677. },
  678. )
  679. renameClusterHandler := cluster.NewRenameClusterHandler(
  680. config,
  681. factory.GetDecoderValidator(),
  682. factory.GetResultWriter(),
  683. )
  684. routes = append(routes, &router.Route{
  685. Endpoint: renameClusterEndpoint,
  686. Handler: renameClusterHandler,
  687. Router: r,
  688. })
  689. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/deployments/{deployment_id} ->
  690. // environment.NewDeleteDeploymentHandler
  691. deleteDeploymentEndpoint := factory.NewAPIEndpoint(
  692. &types.APIRequestMetadata{
  693. Verb: types.APIVerbDelete,
  694. Method: types.HTTPVerbDelete,
  695. Path: &types.Path{
  696. Parent: basePath,
  697. RelativePath: relPath + "/deployments/{deployment_id}",
  698. },
  699. Scopes: []types.PermissionScope{
  700. types.UserScope,
  701. types.ProjectScope,
  702. types.ClusterScope,
  703. types.PreviewEnvironmentScope,
  704. },
  705. },
  706. )
  707. deleteDeploymentHandler := environment.NewDeleteDeploymentHandler(
  708. config,
  709. factory.GetDecoderValidator(),
  710. factory.GetResultWriter(),
  711. )
  712. routes = append(routes, &router.Route{
  713. Endpoint: deleteDeploymentEndpoint,
  714. Handler: deleteDeploymentHandler,
  715. Router: r,
  716. })
  717. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/settings ->
  718. // environment.NewUpdateEnvironmentSettingsHandler
  719. updateEnvironmentSettingsEndpoint := factory.NewAPIEndpoint(
  720. &types.APIRequestMetadata{
  721. Verb: types.APIVerbUpdate,
  722. Method: types.HTTPVerbPatch,
  723. Path: &types.Path{
  724. Parent: basePath,
  725. RelativePath: relPath + "/environments/{environment_id}/settings",
  726. },
  727. Scopes: []types.PermissionScope{
  728. types.UserScope,
  729. types.ProjectScope,
  730. types.ClusterScope,
  731. },
  732. },
  733. )
  734. updateEnvironmentSettingsHandler := environment.NewUpdateEnvironmentSettingsHandler(
  735. config,
  736. factory.GetDecoderValidator(),
  737. factory.GetResultWriter(),
  738. )
  739. routes = append(routes, &router.Route{
  740. Endpoint: updateEnvironmentSettingsEndpoint,
  741. Handler: updateEnvironmentSettingsHandler,
  742. Router: r,
  743. })
  744. }
  745. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces -> cluster.NewClusterListNamespacesHandler
  746. listNamespacesEndpoint := factory.NewAPIEndpoint(
  747. &types.APIRequestMetadata{
  748. Verb: types.APIVerbGet,
  749. Method: types.HTTPVerbGet,
  750. Path: &types.Path{
  751. Parent: basePath,
  752. RelativePath: relPath + "/namespaces",
  753. },
  754. Scopes: []types.PermissionScope{
  755. types.UserScope,
  756. types.ProjectScope,
  757. types.ClusterScope,
  758. },
  759. },
  760. )
  761. listNamespacesHandler := cluster.NewListNamespacesHandler(
  762. config,
  763. factory.GetResultWriter(),
  764. )
  765. routes = append(routes, &router.Route{
  766. Endpoint: listNamespacesEndpoint,
  767. Handler: listNamespacesHandler,
  768. Router: r,
  769. })
  770. // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes -> cluster.NewListNodesHandler
  771. listNodesEndpoint := factory.NewAPIEndpoint(
  772. &types.APIRequestMetadata{
  773. Verb: types.APIVerbGet,
  774. Method: types.HTTPVerbGet,
  775. Path: &types.Path{
  776. Parent: basePath,
  777. RelativePath: relPath + "/nodes",
  778. },
  779. Scopes: []types.PermissionScope{
  780. types.UserScope,
  781. types.ProjectScope,
  782. types.ClusterScope,
  783. },
  784. },
  785. )
  786. listNodesHandler := cluster.NewListNodesHandler(
  787. config,
  788. factory.GetResultWriter(),
  789. )
  790. routes = append(routes, &router.Route{
  791. Endpoint: listNodesEndpoint,
  792. Handler: listNodesHandler,
  793. Router: r,
  794. })
  795. // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes/{node_name} -> cluster.NewGetNodeHandler
  796. getNodeEndpoint := factory.NewAPIEndpoint(
  797. &types.APIRequestMetadata{
  798. Verb: types.APIVerbGet,
  799. Method: types.HTTPVerbGet,
  800. Path: &types.Path{
  801. Parent: basePath,
  802. RelativePath: fmt.Sprintf("%s/nodes/{%s}", relPath, types.URLParamNodeName),
  803. },
  804. Scopes: []types.PermissionScope{
  805. types.UserScope,
  806. types.ProjectScope,
  807. types.ClusterScope,
  808. },
  809. },
  810. )
  811. getNodeHandler := cluster.NewGetNodeHandler(
  812. config,
  813. factory.GetResultWriter(),
  814. )
  815. routes = append(routes, &router.Route{
  816. Endpoint: getNodeEndpoint,
  817. Handler: getNodeHandler,
  818. Router: r,
  819. })
  820. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/create -> cluster.NewCreateNamespaceHandler
  821. createNamespaceEndpoint := factory.NewAPIEndpoint(
  822. &types.APIRequestMetadata{
  823. Verb: types.APIVerbCreate,
  824. Method: types.HTTPVerbPost,
  825. Path: &types.Path{
  826. Parent: basePath,
  827. RelativePath: relPath + "/namespaces/create",
  828. },
  829. Scopes: []types.PermissionScope{
  830. types.UserScope,
  831. types.ProjectScope,
  832. types.ClusterScope,
  833. },
  834. },
  835. )
  836. createNamespaceHandler := cluster.NewCreateNamespaceHandler(
  837. config,
  838. factory.GetDecoderValidator(),
  839. factory.GetResultWriter(),
  840. )
  841. routes = append(routes, &router.Route{
  842. Endpoint: createNamespaceEndpoint,
  843. Handler: createNamespaceHandler,
  844. Router: r,
  845. })
  846. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace} -> cluster.NewDeleteNamespaceHandler
  847. deleteNamespaceEndpoint := factory.NewAPIEndpoint(
  848. &types.APIRequestMetadata{
  849. Verb: types.APIVerbDelete,
  850. Method: types.HTTPVerbDelete,
  851. Path: &types.Path{
  852. Parent: basePath,
  853. RelativePath: fmt.Sprintf("%s/namespaces/{%s}", relPath, types.URLParamNamespace),
  854. },
  855. Scopes: []types.PermissionScope{
  856. types.UserScope,
  857. types.ProjectScope,
  858. types.ClusterScope,
  859. },
  860. },
  861. )
  862. deleteNamespaceHandler := cluster.NewDeleteNamespaceHandler(
  863. config,
  864. factory.GetDecoderValidator(),
  865. )
  866. routes = append(routes, &router.Route{
  867. Endpoint: deleteNamespaceEndpoint,
  868. Handler: deleteNamespaceHandler,
  869. Router: r,
  870. })
  871. if !config.ServerConf.DisableTemporaryKubeconfig {
  872. // GET /api/projects/{project_id}/clusters/{cluster_id}/kubeconfig -> cluster.NewGetTemporaryKubeconfigHandler
  873. getTemporaryKubeconfigEndpoint := factory.NewAPIEndpoint(
  874. &types.APIRequestMetadata{
  875. Verb: types.APIVerbUpdate, // we do not want users with no-write access to be able to use this
  876. Method: types.HTTPVerbGet,
  877. Path: &types.Path{
  878. Parent: basePath,
  879. RelativePath: relPath + "/kubeconfig",
  880. },
  881. Scopes: []types.PermissionScope{
  882. types.UserScope,
  883. types.ProjectScope,
  884. types.ClusterScope,
  885. },
  886. },
  887. )
  888. getTemporaryKubeconfigHandler := cluster.NewGetTemporaryKubeconfigHandler(
  889. config,
  890. factory.GetResultWriter(),
  891. )
  892. routes = append(routes, &router.Route{
  893. Endpoint: getTemporaryKubeconfigEndpoint,
  894. Handler: getTemporaryKubeconfigHandler,
  895. Router: r,
  896. })
  897. }
  898. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/detect -> cluster.NewDetectPrometheusInstalledHandler
  899. detectPrometheusInstalledEndpoint := factory.NewAPIEndpoint(
  900. &types.APIRequestMetadata{
  901. Verb: types.APIVerbGet,
  902. Method: types.HTTPVerbGet,
  903. Path: &types.Path{
  904. Parent: basePath,
  905. RelativePath: relPath + "/prometheus/detect",
  906. },
  907. Scopes: []types.PermissionScope{
  908. types.UserScope,
  909. types.ProjectScope,
  910. types.ClusterScope,
  911. },
  912. },
  913. )
  914. detectPrometheusInstalledHandler := cluster.NewDetectPrometheusInstalledHandler(config)
  915. routes = append(routes, &router.Route{
  916. Endpoint: detectPrometheusInstalledEndpoint,
  917. Handler: detectPrometheusInstalledHandler,
  918. Router: r,
  919. })
  920. // GET /api/projects/{project_id}/clusters/{cluster_id}/agent/detect -> cluster.NewDetectAgentInstalledHandler
  921. detectAgentInstalledEndpoint := factory.NewAPIEndpoint(
  922. &types.APIRequestMetadata{
  923. Verb: types.APIVerbGet,
  924. Method: types.HTTPVerbGet,
  925. Path: &types.Path{
  926. Parent: basePath,
  927. RelativePath: relPath + "/agent/detect",
  928. },
  929. Scopes: []types.PermissionScope{
  930. types.UserScope,
  931. types.ProjectScope,
  932. types.ClusterScope,
  933. },
  934. },
  935. )
  936. detectAgentInstalledHandler := cluster.NewDetectAgentInstalledHandler(config, factory.GetResultWriter())
  937. routes = append(routes, &router.Route{
  938. Endpoint: detectAgentInstalledEndpoint,
  939. Handler: detectAgentInstalledHandler,
  940. Router: r,
  941. })
  942. // POST /api/projects/{project_id}/clusters/{cluster_id}/agent/install -> cluster.NewInstallAgentHandler
  943. installAgentEndpoint := factory.NewAPIEndpoint(
  944. &types.APIRequestMetadata{
  945. Verb: types.APIVerbCreate,
  946. Method: types.HTTPVerbPost,
  947. Path: &types.Path{
  948. Parent: basePath,
  949. RelativePath: relPath + "/agent/install",
  950. },
  951. Scopes: []types.PermissionScope{
  952. types.UserScope,
  953. types.ProjectScope,
  954. types.ClusterScope,
  955. },
  956. },
  957. )
  958. installAgentHandler := cluster.NewInstallAgentHandler(
  959. config,
  960. factory.GetDecoderValidator(),
  961. factory.GetResultWriter(),
  962. )
  963. routes = append(routes, &router.Route{
  964. Endpoint: installAgentEndpoint,
  965. Handler: installAgentHandler,
  966. Router: r,
  967. })
  968. // GET /api/projects/{project_id}/clusters/{cluster_id}/agent/status -> cluster.NewGetAgentStatusHandler
  969. getAgentStatusEndpoint := factory.NewAPIEndpoint(
  970. &types.APIRequestMetadata{
  971. Verb: types.APIVerbGet,
  972. Method: types.HTTPVerbGet,
  973. Path: &types.Path{
  974. Parent: basePath,
  975. RelativePath: relPath + "/agent/status",
  976. },
  977. Scopes: []types.PermissionScope{
  978. types.UserScope,
  979. types.ProjectScope,
  980. types.ClusterScope,
  981. },
  982. },
  983. )
  984. getAgentStatusHandler := cluster.NewGetAgentStatusHandler(config, factory.GetResultWriter())
  985. routes = append(routes, &router.Route{
  986. Endpoint: getAgentStatusEndpoint,
  987. Handler: getAgentStatusHandler,
  988. Router: r,
  989. })
  990. // POST /api/projects/{project_id}/clusters/{cluster_id}/agent/upgrade -> cluster.NewInstallAgentHandler
  991. upgradeAgentEndpoint := factory.NewAPIEndpoint(
  992. &types.APIRequestMetadata{
  993. Verb: types.APIVerbCreate,
  994. Method: types.HTTPVerbPost,
  995. Path: &types.Path{
  996. Parent: basePath,
  997. RelativePath: relPath + "/agent/upgrade",
  998. },
  999. Scopes: []types.PermissionScope{
  1000. types.UserScope,
  1001. types.ProjectScope,
  1002. types.ClusterScope,
  1003. },
  1004. },
  1005. )
  1006. upgradeAgentHandler := cluster.NewUpgradeAgentHandler(
  1007. config,
  1008. factory.GetDecoderValidator(),
  1009. factory.GetResultWriter(),
  1010. )
  1011. routes = append(routes, &router.Route{
  1012. Endpoint: upgradeAgentEndpoint,
  1013. Handler: upgradeAgentHandler,
  1014. Router: r,
  1015. })
  1016. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/ingresses -> cluster.NewListNGINXIngressesHandler
  1017. listNGINXIngressesEndpoint := factory.NewAPIEndpoint(
  1018. &types.APIRequestMetadata{
  1019. Verb: types.APIVerbGet,
  1020. Method: types.HTTPVerbGet,
  1021. Path: &types.Path{
  1022. Parent: basePath,
  1023. RelativePath: relPath + "/prometheus/ingresses",
  1024. },
  1025. Scopes: []types.PermissionScope{
  1026. types.UserScope,
  1027. types.ProjectScope,
  1028. types.ClusterScope,
  1029. },
  1030. },
  1031. )
  1032. listNGINXIngressesHandler := cluster.NewListNGINXIngressesHandler(
  1033. config,
  1034. factory.GetResultWriter(),
  1035. )
  1036. routes = append(routes, &router.Route{
  1037. Endpoint: listNGINXIngressesEndpoint,
  1038. Handler: listNGINXIngressesHandler,
  1039. Router: r,
  1040. })
  1041. // GET /api/projects/{project_id}/clusters/{cluster_id}/metrics -> cluster.NewGetPodMetricsHandler
  1042. getPodMetricsEndpoint := factory.NewAPIEndpoint(
  1043. &types.APIRequestMetadata{
  1044. Verb: types.APIVerbGet,
  1045. Method: types.HTTPVerbGet,
  1046. Path: &types.Path{
  1047. Parent: basePath,
  1048. RelativePath: relPath + "/metrics",
  1049. },
  1050. Scopes: []types.PermissionScope{
  1051. types.UserScope,
  1052. types.ProjectScope,
  1053. types.ClusterScope,
  1054. },
  1055. },
  1056. )
  1057. getPodMetricsHandler := cluster.NewGetPodMetricsHandler(
  1058. config,
  1059. factory.GetDecoderValidator(),
  1060. factory.GetResultWriter(),
  1061. )
  1062. routes = append(routes, &router.Route{
  1063. Endpoint: getPodMetricsEndpoint,
  1064. Handler: getPodMetricsHandler,
  1065. Router: r,
  1066. })
  1067. // GET /api/projects/{project_id}/clusters/{cluster_id}/helm_release -> cluster.NewStreamHelmReleaseHandler
  1068. streamHelmReleaseEndpoint := factory.NewAPIEndpoint(
  1069. &types.APIRequestMetadata{
  1070. Verb: types.APIVerbGet,
  1071. Method: types.HTTPVerbGet,
  1072. Path: &types.Path{
  1073. Parent: basePath,
  1074. RelativePath: relPath + "/helm_release",
  1075. },
  1076. Scopes: []types.PermissionScope{
  1077. types.UserScope,
  1078. types.ProjectScope,
  1079. types.ClusterScope,
  1080. },
  1081. IsWebsocket: true,
  1082. },
  1083. )
  1084. streamHelmReleaseHandler := cluster.NewStreamHelmReleaseHandler(
  1085. config,
  1086. factory.GetDecoderValidator(),
  1087. factory.GetResultWriter(),
  1088. )
  1089. routes = append(routes, &router.Route{
  1090. Endpoint: streamHelmReleaseEndpoint,
  1091. Handler: streamHelmReleaseHandler,
  1092. Router: r,
  1093. })
  1094. // GET /api/projects/{project_id}/clusters/{cluster_id}/state -> cluster.NewClusterStatusHandler
  1095. clusterStatusEndpoint := factory.NewAPIEndpoint(
  1096. &types.APIRequestMetadata{
  1097. Verb: types.APIVerbGet,
  1098. Method: types.HTTPVerbGet,
  1099. Path: &types.Path{
  1100. Parent: basePath,
  1101. RelativePath: relPath + "/state",
  1102. },
  1103. Scopes: []types.PermissionScope{
  1104. types.UserScope,
  1105. types.ProjectScope,
  1106. types.ClusterScope,
  1107. },
  1108. },
  1109. )
  1110. clusterStatusHandler := cluster.NewClusterStatusHandler(
  1111. config,
  1112. factory.GetDecoderValidator(),
  1113. factory.GetResultWriter(),
  1114. )
  1115. routes = append(routes, &router.Route{
  1116. Endpoint: clusterStatusEndpoint,
  1117. Handler: clusterStatusHandler,
  1118. Router: r,
  1119. })
  1120. // GET /api/projects/{project_id}/clusters/{cluster_id}/{kind}/status -> cluster.NewStreamStatusHandler
  1121. streamStatusEndpoint := factory.NewAPIEndpoint(
  1122. &types.APIRequestMetadata{
  1123. Verb: types.APIVerbGet,
  1124. Method: types.HTTPVerbGet,
  1125. Path: &types.Path{
  1126. Parent: basePath,
  1127. RelativePath: fmt.Sprintf(
  1128. "%s/{%s}/status",
  1129. relPath,
  1130. types.URLParamKind,
  1131. ),
  1132. },
  1133. Scopes: []types.PermissionScope{
  1134. types.UserScope,
  1135. types.ProjectScope,
  1136. types.ClusterScope,
  1137. },
  1138. IsWebsocket: true,
  1139. },
  1140. )
  1141. streamStatusHandler := cluster.NewStreamStatusHandler(
  1142. config,
  1143. factory.GetDecoderValidator(),
  1144. factory.GetResultWriter(),
  1145. )
  1146. routes = append(routes, &router.Route{
  1147. Endpoint: streamStatusEndpoint,
  1148. Handler: streamStatusHandler,
  1149. Router: r,
  1150. })
  1151. // GET /api/projects/{project_id}/clusters/{cluster_id}/pods -> cluster.NewGetPodsHandler
  1152. getPodsEndpoint := factory.NewAPIEndpoint(
  1153. &types.APIRequestMetadata{
  1154. Verb: types.APIVerbGet,
  1155. Method: types.HTTPVerbGet,
  1156. Path: &types.Path{
  1157. Parent: basePath,
  1158. RelativePath: relPath + "/pods",
  1159. },
  1160. Scopes: []types.PermissionScope{
  1161. types.UserScope,
  1162. types.ProjectScope,
  1163. types.ClusterScope,
  1164. },
  1165. },
  1166. )
  1167. getPodsHandler := cluster.NewGetPodsHandler(
  1168. config,
  1169. factory.GetDecoderValidator(),
  1170. factory.GetResultWriter(),
  1171. )
  1172. routes = append(routes, &router.Route{
  1173. Endpoint: getPodsEndpoint,
  1174. Handler: getPodsHandler,
  1175. Router: r,
  1176. })
  1177. // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents -> cluster.NewListIncidentsHandler
  1178. listIncidentsEndpoint := factory.NewAPIEndpoint(
  1179. &types.APIRequestMetadata{
  1180. Verb: types.APIVerbGet,
  1181. Method: types.HTTPVerbGet,
  1182. Path: &types.Path{
  1183. Parent: basePath,
  1184. RelativePath: relPath + "/incidents",
  1185. },
  1186. Scopes: []types.PermissionScope{
  1187. types.UserScope,
  1188. types.ProjectScope,
  1189. types.ClusterScope,
  1190. },
  1191. },
  1192. )
  1193. listIncidentsHandler := cluster.NewListIncidentsHandler(
  1194. config,
  1195. factory.GetDecoderValidator(),
  1196. factory.GetResultWriter(),
  1197. )
  1198. routes = append(routes, &router.Route{
  1199. Endpoint: listIncidentsEndpoint,
  1200. Handler: listIncidentsHandler,
  1201. Router: r,
  1202. })
  1203. // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents/{incident_id} -> cluster.NewGetIncidentHandler
  1204. getIncidentEndpoint := factory.NewAPIEndpoint(
  1205. &types.APIRequestMetadata{
  1206. Verb: types.APIVerbGet,
  1207. Method: types.HTTPVerbGet,
  1208. Path: &types.Path{
  1209. Parent: basePath,
  1210. RelativePath: fmt.Sprintf("%s/incidents/{%s}", relPath, types.URLParamIncidentID),
  1211. },
  1212. Scopes: []types.PermissionScope{
  1213. types.UserScope,
  1214. types.ProjectScope,
  1215. types.ClusterScope,
  1216. },
  1217. },
  1218. )
  1219. getIncidentHandler := cluster.NewGetIncidentHandler(
  1220. config,
  1221. factory.GetDecoderValidator(),
  1222. factory.GetResultWriter(),
  1223. )
  1224. routes = append(routes, &router.Route{
  1225. Endpoint: getIncidentEndpoint,
  1226. Handler: getIncidentHandler,
  1227. Router: r,
  1228. })
  1229. // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents/events -> cluster.NewListIncidentEventsHandler
  1230. listIncidentEventsEndpoint := factory.NewAPIEndpoint(
  1231. &types.APIRequestMetadata{
  1232. Verb: types.APIVerbGet,
  1233. Method: types.HTTPVerbGet,
  1234. Path: &types.Path{
  1235. Parent: basePath,
  1236. RelativePath: fmt.Sprintf("%s/incidents/events", relPath),
  1237. },
  1238. Scopes: []types.PermissionScope{
  1239. types.UserScope,
  1240. types.ProjectScope,
  1241. types.ClusterScope,
  1242. },
  1243. },
  1244. )
  1245. listIncidentEventsHandler := cluster.NewListIncidentEventsHandler(
  1246. config,
  1247. factory.GetDecoderValidator(),
  1248. factory.GetResultWriter(),
  1249. )
  1250. routes = append(routes, &router.Route{
  1251. Endpoint: listIncidentEventsEndpoint,
  1252. Handler: listIncidentEventsHandler,
  1253. Router: r,
  1254. })
  1255. // GET /api/projects/{project_id}/clusters/{cluster_id}/logs -> cluster.NewGetLogsHandler
  1256. getLogsEndpoint := factory.NewAPIEndpoint(
  1257. &types.APIRequestMetadata{
  1258. Verb: types.APIVerbGet,
  1259. Method: types.HTTPVerbGet,
  1260. Path: &types.Path{
  1261. Parent: basePath,
  1262. RelativePath: fmt.Sprintf("%s/logs", relPath),
  1263. },
  1264. Scopes: []types.PermissionScope{
  1265. types.UserScope,
  1266. types.ProjectScope,
  1267. types.ClusterScope,
  1268. },
  1269. },
  1270. )
  1271. getLogsHandler := cluster.NewGetLogsHandler(
  1272. config,
  1273. factory.GetDecoderValidator(),
  1274. factory.GetResultWriter(),
  1275. )
  1276. routes = append(routes, &router.Route{
  1277. Endpoint: getLogsEndpoint,
  1278. Handler: getLogsHandler,
  1279. Router: r,
  1280. })
  1281. // GET /api/projects/{project_id}/clusters/{cluster_id}/logs/pod_values -> cluster.NewGetLogPodValuesHandler
  1282. getLogPodValuesEndpoint := factory.NewAPIEndpoint(
  1283. &types.APIRequestMetadata{
  1284. Verb: types.APIVerbGet,
  1285. Method: types.HTTPVerbGet,
  1286. Path: &types.Path{
  1287. Parent: basePath,
  1288. RelativePath: fmt.Sprintf("%s/logs/pod_values", relPath),
  1289. },
  1290. Scopes: []types.PermissionScope{
  1291. types.UserScope,
  1292. types.ProjectScope,
  1293. types.ClusterScope,
  1294. },
  1295. },
  1296. )
  1297. getLogPodValuesHandler := cluster.NewGetLogPodValuesHandler(
  1298. config,
  1299. factory.GetDecoderValidator(),
  1300. factory.GetResultWriter(),
  1301. )
  1302. routes = append(routes, &router.Route{
  1303. Endpoint: getLogPodValuesEndpoint,
  1304. Handler: getLogPodValuesHandler,
  1305. Router: r,
  1306. })
  1307. // GET /api/projects/{project_id}/clusters/{cluster_id}/logs/revision_values -> cluster.NewGetLogPodValuesHandler
  1308. getLogRevisionValuesEndpoint := factory.NewAPIEndpoint(
  1309. &types.APIRequestMetadata{
  1310. Verb: types.APIVerbGet,
  1311. Method: types.HTTPVerbGet,
  1312. Path: &types.Path{
  1313. Parent: basePath,
  1314. RelativePath: fmt.Sprintf("%s/logs/revision_values", relPath),
  1315. },
  1316. Scopes: []types.PermissionScope{
  1317. types.UserScope,
  1318. types.ProjectScope,
  1319. types.ClusterScope,
  1320. },
  1321. },
  1322. )
  1323. getLogRevisionValuesHandler := cluster.NewGetLogRevisionValuesHandler(
  1324. config,
  1325. factory.GetDecoderValidator(),
  1326. factory.GetResultWriter(),
  1327. )
  1328. routes = append(routes, &router.Route{
  1329. Endpoint: getLogRevisionValuesEndpoint,
  1330. Handler: getLogRevisionValuesHandler,
  1331. Router: r,
  1332. })
  1333. // GET /api/projects/{project_id}/clusters/{cluster_id}/events -> cluster.NewGetEventsHandler
  1334. getPorterEventsEndpoint := factory.NewAPIEndpoint(
  1335. &types.APIRequestMetadata{
  1336. Verb: types.APIVerbGet,
  1337. Method: types.HTTPVerbGet,
  1338. Path: &types.Path{
  1339. Parent: basePath,
  1340. RelativePath: fmt.Sprintf("%s/events", relPath),
  1341. },
  1342. Scopes: []types.PermissionScope{
  1343. types.UserScope,
  1344. types.ProjectScope,
  1345. types.ClusterScope,
  1346. },
  1347. },
  1348. )
  1349. getPorterEventsHandler := cluster.NewGetPorterEventsHandler(
  1350. config,
  1351. factory.GetDecoderValidator(),
  1352. factory.GetResultWriter(),
  1353. )
  1354. routes = append(routes, &router.Route{
  1355. Endpoint: getPorterEventsEndpoint,
  1356. Handler: getPorterEventsHandler,
  1357. Router: r,
  1358. })
  1359. // GET /api/projects/{project_id}/clusters/{cluster_id}/events/job -> cluster.NewGetPorterJobEventsHandler
  1360. getPorterJobEventsEndpoint := factory.NewAPIEndpoint(
  1361. &types.APIRequestMetadata{
  1362. Verb: types.APIVerbGet,
  1363. Method: types.HTTPVerbGet,
  1364. Path: &types.Path{
  1365. Parent: basePath,
  1366. RelativePath: fmt.Sprintf("%s/events/job", relPath),
  1367. },
  1368. Scopes: []types.PermissionScope{
  1369. types.UserScope,
  1370. types.ProjectScope,
  1371. types.ClusterScope,
  1372. },
  1373. },
  1374. )
  1375. getPorterJobEventsHandler := cluster.NewGetPorterJobEventsHandler(
  1376. config,
  1377. factory.GetDecoderValidator(),
  1378. factory.GetResultWriter(),
  1379. )
  1380. routes = append(routes, &router.Route{
  1381. Endpoint: getPorterJobEventsEndpoint,
  1382. Handler: getPorterJobEventsHandler,
  1383. Router: r,
  1384. })
  1385. // GET /api/projects/{project_id}/clusters/{cluster_id}/k8s_events -> cluster.NewGetEventsHandler
  1386. getK8sEventsEndpoint := factory.NewAPIEndpoint(
  1387. &types.APIRequestMetadata{
  1388. Verb: types.APIVerbGet,
  1389. Method: types.HTTPVerbGet,
  1390. Path: &types.Path{
  1391. Parent: basePath,
  1392. RelativePath: fmt.Sprintf("%s/k8s_events", relPath),
  1393. },
  1394. Scopes: []types.PermissionScope{
  1395. types.UserScope,
  1396. types.ProjectScope,
  1397. types.ClusterScope,
  1398. },
  1399. },
  1400. )
  1401. getK8sEventsHandler := cluster.NewGetKubernetesEventsHandler(
  1402. config,
  1403. factory.GetDecoderValidator(),
  1404. factory.GetResultWriter(),
  1405. )
  1406. routes = append(routes, &router.Route{
  1407. Endpoint: getK8sEventsEndpoint,
  1408. Handler: getK8sEventsHandler,
  1409. Router: r,
  1410. })
  1411. // POST /api/projects/{project_id}/clusters/{cluster_id}/incidents/notify_new -> cluster.NewNotifyNewIncidentHandler
  1412. notifyNewIncidentEndpoint := factory.NewAPIEndpoint(
  1413. &types.APIRequestMetadata{
  1414. Verb: types.APIVerbCreate,
  1415. Method: types.HTTPVerbPost,
  1416. Path: &types.Path{
  1417. Parent: basePath,
  1418. RelativePath: relPath + "/incidents/notify_new",
  1419. },
  1420. Scopes: []types.PermissionScope{
  1421. types.UserScope,
  1422. types.ProjectScope,
  1423. types.ClusterScope,
  1424. },
  1425. },
  1426. )
  1427. notifyNewIncidentHandler := cluster.NewNotifyNewIncidentHandler(
  1428. config,
  1429. factory.GetDecoderValidator(),
  1430. factory.GetResultWriter(),
  1431. )
  1432. routes = append(routes, &router.Route{
  1433. Endpoint: notifyNewIncidentEndpoint,
  1434. Handler: notifyNewIncidentHandler,
  1435. Router: r,
  1436. })
  1437. // POST /api/projects/{project_id}/clusters/{cluster_id}/incidents/notify_resolved -> cluster.NewNotifyResolvedIncidentHandler
  1438. notifyResolvedIncidentEndpoint := factory.NewAPIEndpoint(
  1439. &types.APIRequestMetadata{
  1440. Verb: types.APIVerbCreate,
  1441. Method: types.HTTPVerbPost,
  1442. Path: &types.Path{
  1443. Parent: basePath,
  1444. RelativePath: relPath + "/incidents/notify_resolved",
  1445. },
  1446. Scopes: []types.PermissionScope{
  1447. types.UserScope,
  1448. types.ProjectScope,
  1449. types.ClusterScope,
  1450. },
  1451. },
  1452. )
  1453. notifyResolvedIncidentHandler := cluster.NewNotifyResolvedIncidentHandler(
  1454. config,
  1455. factory.GetDecoderValidator(),
  1456. factory.GetResultWriter(),
  1457. )
  1458. routes = append(routes, &router.Route{
  1459. Endpoint: notifyResolvedIncidentEndpoint,
  1460. Handler: notifyResolvedIncidentHandler,
  1461. Router: r,
  1462. })
  1463. // POST /api/projects/{project_id}/clusters/{cluster_id}/environment-groups
  1464. updateEnvironmentGroupEndpoint := factory.NewAPIEndpoint(
  1465. &types.APIRequestMetadata{
  1466. Verb: types.APIVerbCreate,
  1467. Method: types.HTTPVerbPost,
  1468. Path: &types.Path{
  1469. Parent: basePath,
  1470. RelativePath: relPath + "/environment-groups",
  1471. },
  1472. Scopes: []types.PermissionScope{
  1473. types.UserScope,
  1474. types.ProjectScope,
  1475. types.ClusterScope,
  1476. },
  1477. },
  1478. )
  1479. updateEnvironmentGroupHandler := environment_groups.NewUpdateEnvironmentGroupHandler(
  1480. config,
  1481. factory.GetDecoderValidator(),
  1482. factory.GetResultWriter(),
  1483. )
  1484. routes = append(routes, &router.Route{
  1485. Endpoint: updateEnvironmentGroupEndpoint,
  1486. Handler: updateEnvironmentGroupHandler,
  1487. Router: r,
  1488. })
  1489. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/environment-groups}
  1490. deleteEnvironmentGroupEndpoint := factory.NewAPIEndpoint(
  1491. &types.APIRequestMetadata{
  1492. Verb: types.APIVerbDelete,
  1493. Method: types.HTTPVerbDelete,
  1494. Path: &types.Path{
  1495. Parent: basePath,
  1496. RelativePath: relPath + "/environment-groups",
  1497. },
  1498. Scopes: []types.PermissionScope{
  1499. types.UserScope,
  1500. types.ProjectScope,
  1501. types.ClusterScope,
  1502. },
  1503. },
  1504. )
  1505. deleteEnvironmentGroupHandler := environment_groups.NewDeleteEnvironmentGroupHandler(
  1506. config,
  1507. factory.GetDecoderValidator(),
  1508. factory.GetResultWriter(),
  1509. )
  1510. routes = append(routes, &router.Route{
  1511. Endpoint: deleteEnvironmentGroupEndpoint,
  1512. Handler: deleteEnvironmentGroupHandler,
  1513. Router: r,
  1514. })
  1515. // GET /api/projects/{project_id}/clusters/{cluster_id}/environment-groups
  1516. listEnvironmentGroupEndpoint := factory.NewAPIEndpoint(
  1517. &types.APIRequestMetadata{
  1518. Verb: types.APIVerbList,
  1519. Method: types.HTTPVerbGet,
  1520. Path: &types.Path{
  1521. Parent: basePath,
  1522. RelativePath: relPath + "/environment-groups",
  1523. },
  1524. Scopes: []types.PermissionScope{
  1525. types.UserScope,
  1526. types.ProjectScope,
  1527. types.ClusterScope,
  1528. },
  1529. },
  1530. )
  1531. listEnvironmentGroupHandler := environment_groups.NewListEnvironmentGroupsHandler(
  1532. config,
  1533. factory.GetDecoderValidator(),
  1534. factory.GetResultWriter(),
  1535. )
  1536. routes = append(routes, &router.Route{
  1537. Endpoint: listEnvironmentGroupEndpoint,
  1538. Handler: listEnvironmentGroupHandler,
  1539. Router: r,
  1540. })
  1541. // GET /api/projects/{project_id}/clusters/{cluster_id}/environment-groups/update-linked-apps
  1542. updateLinkedAppsEndpoint := factory.NewAPIEndpoint(
  1543. &types.APIRequestMetadata{
  1544. Verb: types.APIVerbUpdate,
  1545. Method: types.HTTPVerbPost,
  1546. Path: &types.Path{
  1547. Parent: basePath,
  1548. RelativePath: relPath + "/environment-groups/update-linked-apps",
  1549. },
  1550. Scopes: []types.PermissionScope{
  1551. types.UserScope,
  1552. types.ProjectScope,
  1553. types.ClusterScope,
  1554. },
  1555. },
  1556. )
  1557. updateLinkedAppsHandler := environment_groups.NewUpdateLinkedAppsHandler(
  1558. config,
  1559. factory.GetDecoderValidator(),
  1560. factory.GetResultWriter(),
  1561. )
  1562. routes = append(routes, &router.Route{
  1563. Endpoint: updateLinkedAppsEndpoint,
  1564. Handler: updateLinkedAppsHandler,
  1565. Router: r,
  1566. })
  1567. // POST /api/projects/{project_id}/clusters/{cluster_id}/environment-groups/enable-external-providers
  1568. enableExternalProvidersEndpoint := factory.NewAPIEndpoint(
  1569. &types.APIRequestMetadata{
  1570. Verb: types.APIVerbUpdate,
  1571. Method: types.HTTPVerbPost,
  1572. Path: &types.Path{
  1573. Parent: basePath,
  1574. RelativePath: fmt.Sprintf("%s/environment-groups/enable-external-providers", relPath),
  1575. },
  1576. Scopes: []types.PermissionScope{
  1577. types.UserScope,
  1578. types.ProjectScope,
  1579. types.ClusterScope,
  1580. },
  1581. },
  1582. )
  1583. enableExternalProvidersHandler := environment_groups.NewEnableExternalProvidersHandler(
  1584. config,
  1585. factory.GetDecoderValidator(),
  1586. factory.GetResultWriter(),
  1587. )
  1588. routes = append(routes, &router.Route{
  1589. Endpoint: enableExternalProvidersEndpoint,
  1590. Handler: enableExternalProvidersHandler,
  1591. Router: r,
  1592. })
  1593. // GET /api/projects/{project_id}/clusters/{cluster_id}/environment-groups/are-external-providers-enabled
  1594. areExternalProvidersEnabledEndpoint := factory.NewAPIEndpoint(
  1595. &types.APIRequestMetadata{
  1596. Verb: types.APIVerbGet,
  1597. Method: types.HTTPVerbGet,
  1598. Path: &types.Path{
  1599. Parent: basePath,
  1600. RelativePath: fmt.Sprintf("%s/environment-groups/are-external-providers-enabled", relPath),
  1601. },
  1602. Scopes: []types.PermissionScope{
  1603. types.UserScope,
  1604. types.ProjectScope,
  1605. types.ClusterScope,
  1606. },
  1607. },
  1608. )
  1609. areExternalProvidersEnabledHandler := environment_groups.NewAreExternalProvidersEnabledHandler(
  1610. config,
  1611. factory.GetDecoderValidator(),
  1612. factory.GetResultWriter(),
  1613. )
  1614. routes = append(routes, &router.Route{
  1615. Endpoint: areExternalProvidersEnabledEndpoint,
  1616. Handler: areExternalProvidersEnabledHandler,
  1617. Router: r,
  1618. })
  1619. return routes, newPath
  1620. }