cluster.go 50 KB

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