cluster.go 36 KB

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