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