cluster.go 44 KB

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