cluster.go 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  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. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/deployments/{deployment_id}/revisions -> environment.NewListDeploymentRevisionsHandler
  418. listDeploymentRevisionsEndpoint := factory.NewAPIEndpoint(
  419. &types.APIRequestMetadata{
  420. Verb: types.APIVerbGet,
  421. Method: types.HTTPVerbGet,
  422. Path: &types.Path{
  423. Parent: basePath,
  424. RelativePath: relPath + "/environments/{environment_id}/deployments/{deployment_id}/revisions",
  425. },
  426. Scopes: []types.PermissionScope{
  427. types.UserScope,
  428. types.ProjectScope,
  429. types.ClusterScope,
  430. types.PreviewEnvironmentScope,
  431. },
  432. },
  433. )
  434. listDeploymentRevisionsHandler := environment.NewListDeploymentRevisionsHandler(
  435. config,
  436. factory.GetDecoderValidator(),
  437. factory.GetResultWriter(),
  438. )
  439. routes = append(routes, &router.Route{
  440. Endpoint: listDeploymentRevisionsEndpoint,
  441. Handler: listDeploymentRevisionsHandler,
  442. Router: r,
  443. })
  444. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/deployments/{deployment_id}/reenable -> environment.NewReenableDeploymentHandler
  445. reenableDeploymentEndpoint := factory.NewAPIEndpoint(
  446. &types.APIRequestMetadata{
  447. Verb: types.APIVerbUpdate,
  448. Method: types.HTTPVerbPatch,
  449. Path: &types.Path{
  450. Parent: basePath,
  451. RelativePath: relPath + "/deployments/{deployment_id}/reenable",
  452. },
  453. Scopes: []types.PermissionScope{
  454. types.UserScope,
  455. types.ProjectScope,
  456. types.ClusterScope,
  457. types.PreviewEnvironmentScope,
  458. },
  459. },
  460. )
  461. reenableDeploymentHandler := environment.NewReenableDeploymentHandler(
  462. config,
  463. factory.GetDecoderValidator(),
  464. factory.GetResultWriter(),
  465. )
  466. routes = append(routes, &router.Route{
  467. Endpoint: reenableDeploymentEndpoint,
  468. Handler: reenableDeploymentHandler,
  469. Router: r,
  470. })
  471. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/{deployment_id}/trigger_workflow -> environment.NewTriggerDeploymentWorkflowHandler
  472. triggerDeploymentWorkflowEndpoint := factory.NewAPIEndpoint(
  473. &types.APIRequestMetadata{
  474. Verb: types.APIVerbCreate,
  475. Method: types.HTTPVerbPost,
  476. Path: &types.Path{
  477. Parent: basePath,
  478. RelativePath: relPath + "/deployments/{deployment_id}/trigger_workflow",
  479. },
  480. Scopes: []types.PermissionScope{
  481. types.UserScope,
  482. types.ProjectScope,
  483. types.ClusterScope,
  484. types.PreviewEnvironmentScope,
  485. },
  486. },
  487. )
  488. triggerDeploymentWorkflowHandler := environment.NewTriggerDeploymentWorkflowHandler(
  489. config,
  490. factory.GetDecoderValidator(),
  491. factory.GetResultWriter(),
  492. )
  493. routes = append(routes, &router.Route{
  494. Endpoint: triggerDeploymentWorkflowEndpoint,
  495. Handler: triggerDeploymentWorkflowHandler,
  496. Router: r,
  497. })
  498. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/pull_request -> environment.NewEnablePullRequestHandler
  499. enablePullRequestEndpoint := factory.NewAPIEndpoint(
  500. &types.APIRequestMetadata{
  501. Verb: types.APIVerbCreate,
  502. Method: types.HTTPVerbPost,
  503. Path: &types.Path{
  504. Parent: basePath,
  505. RelativePath: relPath + "/deployments/pull_request",
  506. },
  507. Scopes: []types.PermissionScope{
  508. types.UserScope,
  509. types.ProjectScope,
  510. types.ClusterScope,
  511. types.PreviewEnvironmentScope,
  512. },
  513. },
  514. )
  515. enablePullRequestHandler := environment.NewEnablePullRequestHandler(
  516. config,
  517. factory.GetDecoderValidator(),
  518. factory.GetResultWriter(),
  519. )
  520. routes = append(routes, &router.Route{
  521. Endpoint: enablePullRequestEndpoint,
  522. Handler: enablePullRequestHandler,
  523. Router: r,
  524. })
  525. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/deployments/{deployment_id} ->
  526. // environment.NewDeleteDeploymentHandler
  527. deleteDeploymentEndpoint := factory.NewAPIEndpoint(
  528. &types.APIRequestMetadata{
  529. Verb: types.APIVerbDelete,
  530. Method: types.HTTPVerbDelete,
  531. Path: &types.Path{
  532. Parent: basePath,
  533. RelativePath: relPath + "/deployments/{deployment_id}",
  534. },
  535. Scopes: []types.PermissionScope{
  536. types.UserScope,
  537. types.ProjectScope,
  538. types.ClusterScope,
  539. types.PreviewEnvironmentScope,
  540. },
  541. },
  542. )
  543. deleteDeploymentHandler := environment.NewDeleteDeploymentHandler(
  544. config,
  545. factory.GetDecoderValidator(),
  546. factory.GetResultWriter(),
  547. )
  548. routes = append(routes, &router.Route{
  549. Endpoint: deleteDeploymentEndpoint,
  550. Handler: deleteDeploymentHandler,
  551. Router: r,
  552. })
  553. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/settings ->
  554. // environment.NewUpdateEnvironmentSettingsHandler
  555. updateEnvironmentSettingsEndpoint := factory.NewAPIEndpoint(
  556. &types.APIRequestMetadata{
  557. Verb: types.APIVerbUpdate,
  558. Method: types.HTTPVerbPatch,
  559. Path: &types.Path{
  560. Parent: basePath,
  561. RelativePath: relPath + "/environments/{environment_id}/settings",
  562. },
  563. Scopes: []types.PermissionScope{
  564. types.UserScope,
  565. types.ProjectScope,
  566. types.ClusterScope,
  567. },
  568. },
  569. )
  570. updateEnvironmentSettingsHandler := environment.NewUpdateEnvironmentSettingsHandler(
  571. config,
  572. factory.GetDecoderValidator(),
  573. factory.GetResultWriter(),
  574. )
  575. routes = append(routes, &router.Route{
  576. Endpoint: updateEnvironmentSettingsEndpoint,
  577. Handler: updateEnvironmentSettingsHandler,
  578. Router: r,
  579. })
  580. }
  581. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces -> cluster.NewClusterListNamespacesHandler
  582. listNamespacesEndpoint := factory.NewAPIEndpoint(
  583. &types.APIRequestMetadata{
  584. Verb: types.APIVerbGet,
  585. Method: types.HTTPVerbGet,
  586. Path: &types.Path{
  587. Parent: basePath,
  588. RelativePath: relPath + "/namespaces",
  589. },
  590. Scopes: []types.PermissionScope{
  591. types.UserScope,
  592. types.ProjectScope,
  593. types.ClusterScope,
  594. },
  595. },
  596. )
  597. listNamespacesHandler := cluster.NewListNamespacesHandler(
  598. config,
  599. factory.GetResultWriter(),
  600. )
  601. routes = append(routes, &router.Route{
  602. Endpoint: listNamespacesEndpoint,
  603. Handler: listNamespacesHandler,
  604. Router: r,
  605. })
  606. // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes -> cluster.NewListNodesHandler
  607. listNodesEndpoint := factory.NewAPIEndpoint(
  608. &types.APIRequestMetadata{
  609. Verb: types.APIVerbGet,
  610. Method: types.HTTPVerbGet,
  611. Path: &types.Path{
  612. Parent: basePath,
  613. RelativePath: relPath + "/nodes",
  614. },
  615. Scopes: []types.PermissionScope{
  616. types.UserScope,
  617. types.ProjectScope,
  618. types.ClusterScope,
  619. },
  620. },
  621. )
  622. listNodesHandler := cluster.NewListNodesHandler(
  623. config,
  624. factory.GetResultWriter(),
  625. )
  626. routes = append(routes, &router.Route{
  627. Endpoint: listNodesEndpoint,
  628. Handler: listNodesHandler,
  629. Router: r,
  630. })
  631. // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes/{node_name} -> cluster.NewGetNodeHandler
  632. getNodeEndpoint := factory.NewAPIEndpoint(
  633. &types.APIRequestMetadata{
  634. Verb: types.APIVerbGet,
  635. Method: types.HTTPVerbGet,
  636. Path: &types.Path{
  637. Parent: basePath,
  638. RelativePath: fmt.Sprintf("%s/nodes/{%s}", relPath, types.URLParamNodeName),
  639. },
  640. Scopes: []types.PermissionScope{
  641. types.UserScope,
  642. types.ProjectScope,
  643. types.ClusterScope,
  644. },
  645. },
  646. )
  647. getNodeHandler := cluster.NewGetNodeHandler(
  648. config,
  649. factory.GetResultWriter(),
  650. )
  651. routes = append(routes, &router.Route{
  652. Endpoint: getNodeEndpoint,
  653. Handler: getNodeHandler,
  654. Router: r,
  655. })
  656. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/create -> cluster.NewCreateNamespaceHandler
  657. createNamespaceEndpoint := factory.NewAPIEndpoint(
  658. &types.APIRequestMetadata{
  659. Verb: types.APIVerbCreate,
  660. Method: types.HTTPVerbPost,
  661. Path: &types.Path{
  662. Parent: basePath,
  663. RelativePath: relPath + "/namespaces/create",
  664. },
  665. Scopes: []types.PermissionScope{
  666. types.UserScope,
  667. types.ProjectScope,
  668. types.ClusterScope,
  669. },
  670. },
  671. )
  672. createNamespaceHandler := cluster.NewCreateNamespaceHandler(
  673. config,
  674. factory.GetDecoderValidator(),
  675. factory.GetResultWriter(),
  676. )
  677. routes = append(routes, &router.Route{
  678. Endpoint: createNamespaceEndpoint,
  679. Handler: createNamespaceHandler,
  680. Router: r,
  681. })
  682. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace} -> cluster.NewDeleteNamespaceHandler
  683. deleteNamespaceEndpoint := factory.NewAPIEndpoint(
  684. &types.APIRequestMetadata{
  685. Verb: types.APIVerbDelete,
  686. Method: types.HTTPVerbDelete,
  687. Path: &types.Path{
  688. Parent: basePath,
  689. RelativePath: fmt.Sprintf("%s/namespaces/{%s}", relPath, types.URLParamNamespace),
  690. },
  691. Scopes: []types.PermissionScope{
  692. types.UserScope,
  693. types.ProjectScope,
  694. types.ClusterScope,
  695. },
  696. },
  697. )
  698. deleteNamespaceHandler := cluster.NewDeleteNamespaceHandler(
  699. config,
  700. factory.GetDecoderValidator(),
  701. )
  702. routes = append(routes, &router.Route{
  703. Endpoint: deleteNamespaceEndpoint,
  704. Handler: deleteNamespaceHandler,
  705. Router: r,
  706. })
  707. // GET /api/projects/{project_id}/clusters/{cluster_id}/kubeconfig -> cluster.NewGetTemporaryKubeconfigHandler
  708. getTemporaryKubeconfigEndpoint := factory.NewAPIEndpoint(
  709. &types.APIRequestMetadata{
  710. Verb: types.APIVerbUpdate, // we do not want users with no-write access to be able to use this
  711. Method: types.HTTPVerbGet,
  712. Path: &types.Path{
  713. Parent: basePath,
  714. RelativePath: relPath + "/kubeconfig",
  715. },
  716. Scopes: []types.PermissionScope{
  717. types.UserScope,
  718. types.ProjectScope,
  719. types.ClusterScope,
  720. },
  721. },
  722. )
  723. getTemporaryKubeconfigHandler := cluster.NewGetTemporaryKubeconfigHandler(
  724. config,
  725. factory.GetResultWriter(),
  726. )
  727. routes = append(routes, &router.Route{
  728. Endpoint: getTemporaryKubeconfigEndpoint,
  729. Handler: getTemporaryKubeconfigHandler,
  730. Router: r,
  731. })
  732. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/detect -> cluster.NewDetectPrometheusInstalledHandler
  733. detectPrometheusInstalledEndpoint := factory.NewAPIEndpoint(
  734. &types.APIRequestMetadata{
  735. Verb: types.APIVerbGet,
  736. Method: types.HTTPVerbGet,
  737. Path: &types.Path{
  738. Parent: basePath,
  739. RelativePath: relPath + "/prometheus/detect",
  740. },
  741. Scopes: []types.PermissionScope{
  742. types.UserScope,
  743. types.ProjectScope,
  744. types.ClusterScope,
  745. },
  746. },
  747. )
  748. detectPrometheusInstalledHandler := cluster.NewDetectPrometheusInstalledHandler(config)
  749. routes = append(routes, &router.Route{
  750. Endpoint: detectPrometheusInstalledEndpoint,
  751. Handler: detectPrometheusInstalledHandler,
  752. Router: r,
  753. })
  754. // GET /api/projects/{project_id}/clusters/{cluster_id}/agent/detect -> cluster.NewDetectAgentInstalledHandler
  755. detectAgentInstalledEndpoint := factory.NewAPIEndpoint(
  756. &types.APIRequestMetadata{
  757. Verb: types.APIVerbGet,
  758. Method: types.HTTPVerbGet,
  759. Path: &types.Path{
  760. Parent: basePath,
  761. RelativePath: relPath + "/agent/detect",
  762. },
  763. Scopes: []types.PermissionScope{
  764. types.UserScope,
  765. types.ProjectScope,
  766. types.ClusterScope,
  767. },
  768. },
  769. )
  770. detectAgentInstalledHandler := cluster.NewDetectAgentInstalledHandler(config, factory.GetResultWriter())
  771. routes = append(routes, &router.Route{
  772. Endpoint: detectAgentInstalledEndpoint,
  773. Handler: detectAgentInstalledHandler,
  774. Router: r,
  775. })
  776. // POST /api/projects/{project_id}/clusters/{cluster_id}/agent/install -> cluster.NewInstallAgentHandler
  777. installAgentEndpoint := factory.NewAPIEndpoint(
  778. &types.APIRequestMetadata{
  779. Verb: types.APIVerbCreate,
  780. Method: types.HTTPVerbPost,
  781. Path: &types.Path{
  782. Parent: basePath,
  783. RelativePath: relPath + "/agent/install",
  784. },
  785. Scopes: []types.PermissionScope{
  786. types.UserScope,
  787. types.ProjectScope,
  788. types.ClusterScope,
  789. },
  790. },
  791. )
  792. installAgentHandler := cluster.NewInstallAgentHandler(
  793. config,
  794. factory.GetDecoderValidator(),
  795. factory.GetResultWriter(),
  796. )
  797. routes = append(routes, &router.Route{
  798. Endpoint: installAgentEndpoint,
  799. Handler: installAgentHandler,
  800. Router: r,
  801. })
  802. // GET /api/projects/{project_id}/clusters/{cluster_id}/agent/status -> cluster.NewGetAgentStatusHandler
  803. getAgentStatusEndpoint := factory.NewAPIEndpoint(
  804. &types.APIRequestMetadata{
  805. Verb: types.APIVerbGet,
  806. Method: types.HTTPVerbGet,
  807. Path: &types.Path{
  808. Parent: basePath,
  809. RelativePath: relPath + "/agent/status",
  810. },
  811. Scopes: []types.PermissionScope{
  812. types.UserScope,
  813. types.ProjectScope,
  814. types.ClusterScope,
  815. },
  816. },
  817. )
  818. getAgentStatusHandler := cluster.NewGetAgentStatusHandler(config, factory.GetResultWriter())
  819. routes = append(routes, &router.Route{
  820. Endpoint: getAgentStatusEndpoint,
  821. Handler: getAgentStatusHandler,
  822. Router: r,
  823. })
  824. // POST /api/projects/{project_id}/clusters/{cluster_id}/agent/upgrade -> cluster.NewInstallAgentHandler
  825. upgradeAgentEndpoint := factory.NewAPIEndpoint(
  826. &types.APIRequestMetadata{
  827. Verb: types.APIVerbCreate,
  828. Method: types.HTTPVerbPost,
  829. Path: &types.Path{
  830. Parent: basePath,
  831. RelativePath: relPath + "/agent/upgrade",
  832. },
  833. Scopes: []types.PermissionScope{
  834. types.UserScope,
  835. types.ProjectScope,
  836. types.ClusterScope,
  837. },
  838. },
  839. )
  840. upgradeAgentHandler := cluster.NewUpgradeAgentHandler(
  841. config,
  842. factory.GetDecoderValidator(),
  843. factory.GetResultWriter(),
  844. )
  845. routes = append(routes, &router.Route{
  846. Endpoint: upgradeAgentEndpoint,
  847. Handler: upgradeAgentHandler,
  848. Router: r,
  849. })
  850. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/ingresses -> cluster.NewListNGINXIngressesHandler
  851. listNGINXIngressesEndpoint := factory.NewAPIEndpoint(
  852. &types.APIRequestMetadata{
  853. Verb: types.APIVerbGet,
  854. Method: types.HTTPVerbGet,
  855. Path: &types.Path{
  856. Parent: basePath,
  857. RelativePath: relPath + "/prometheus/ingresses",
  858. },
  859. Scopes: []types.PermissionScope{
  860. types.UserScope,
  861. types.ProjectScope,
  862. types.ClusterScope,
  863. },
  864. },
  865. )
  866. listNGINXIngressesHandler := cluster.NewListNGINXIngressesHandler(
  867. config,
  868. factory.GetResultWriter(),
  869. )
  870. routes = append(routes, &router.Route{
  871. Endpoint: listNGINXIngressesEndpoint,
  872. Handler: listNGINXIngressesHandler,
  873. Router: r,
  874. })
  875. // GET /api/projects/{project_id}/clusters/{cluster_id}/metrics -> cluster.NewGetPodMetricsHandler
  876. getPodMetricsEndpoint := factory.NewAPIEndpoint(
  877. &types.APIRequestMetadata{
  878. Verb: types.APIVerbGet,
  879. Method: types.HTTPVerbGet,
  880. Path: &types.Path{
  881. Parent: basePath,
  882. RelativePath: relPath + "/metrics",
  883. },
  884. Scopes: []types.PermissionScope{
  885. types.UserScope,
  886. types.ProjectScope,
  887. types.ClusterScope,
  888. },
  889. },
  890. )
  891. getPodMetricsHandler := cluster.NewGetPodMetricsHandler(
  892. config,
  893. factory.GetDecoderValidator(),
  894. factory.GetResultWriter(),
  895. )
  896. routes = append(routes, &router.Route{
  897. Endpoint: getPodMetricsEndpoint,
  898. Handler: getPodMetricsHandler,
  899. Router: r,
  900. })
  901. // GET /api/projects/{project_id}/clusters/{cluster_id}/helm_release -> cluster.NewStreamHelmReleaseHandler
  902. streamHelmReleaseEndpoint := factory.NewAPIEndpoint(
  903. &types.APIRequestMetadata{
  904. Verb: types.APIVerbGet,
  905. Method: types.HTTPVerbGet,
  906. Path: &types.Path{
  907. Parent: basePath,
  908. RelativePath: relPath + "/helm_release",
  909. },
  910. Scopes: []types.PermissionScope{
  911. types.UserScope,
  912. types.ProjectScope,
  913. types.ClusterScope,
  914. },
  915. IsWebsocket: true,
  916. },
  917. )
  918. streamHelmReleaseHandler := cluster.NewStreamHelmReleaseHandler(
  919. config,
  920. factory.GetDecoderValidator(),
  921. factory.GetResultWriter(),
  922. )
  923. routes = append(routes, &router.Route{
  924. Endpoint: streamHelmReleaseEndpoint,
  925. Handler: streamHelmReleaseHandler,
  926. Router: r,
  927. })
  928. // GET /api/projects/{project_id}/clusters/{cluster_id}/{kind}/status -> cluster.NewStreamStatusHandler
  929. streamStatusEndpoint := factory.NewAPIEndpoint(
  930. &types.APIRequestMetadata{
  931. Verb: types.APIVerbGet,
  932. Method: types.HTTPVerbGet,
  933. Path: &types.Path{
  934. Parent: basePath,
  935. RelativePath: fmt.Sprintf(
  936. "%s/{%s}/status",
  937. relPath,
  938. types.URLParamKind,
  939. ),
  940. },
  941. Scopes: []types.PermissionScope{
  942. types.UserScope,
  943. types.ProjectScope,
  944. types.ClusterScope,
  945. },
  946. IsWebsocket: true,
  947. },
  948. )
  949. streamStatusHandler := cluster.NewStreamStatusHandler(
  950. config,
  951. factory.GetDecoderValidator(),
  952. factory.GetResultWriter(),
  953. )
  954. routes = append(routes, &router.Route{
  955. Endpoint: streamStatusEndpoint,
  956. Handler: streamStatusHandler,
  957. Router: r,
  958. })
  959. // GET /api/projects/{project_id}/clusters/{cluster_id}/pods -> cluster.NewGetPodsHandler
  960. getPodsEndpoint := factory.NewAPIEndpoint(
  961. &types.APIRequestMetadata{
  962. Verb: types.APIVerbGet,
  963. Method: types.HTTPVerbGet,
  964. Path: &types.Path{
  965. Parent: basePath,
  966. RelativePath: relPath + "/pods",
  967. },
  968. Scopes: []types.PermissionScope{
  969. types.UserScope,
  970. types.ProjectScope,
  971. types.ClusterScope,
  972. },
  973. },
  974. )
  975. getPodsHandler := cluster.NewGetPodsHandler(
  976. config,
  977. factory.GetDecoderValidator(),
  978. factory.GetResultWriter(),
  979. )
  980. routes = append(routes, &router.Route{
  981. Endpoint: getPodsEndpoint,
  982. Handler: getPodsHandler,
  983. Router: r,
  984. })
  985. // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents -> cluster.NewListIncidentsHandler
  986. listIncidentsEndpoint := factory.NewAPIEndpoint(
  987. &types.APIRequestMetadata{
  988. Verb: types.APIVerbGet,
  989. Method: types.HTTPVerbGet,
  990. Path: &types.Path{
  991. Parent: basePath,
  992. RelativePath: relPath + "/incidents",
  993. },
  994. Scopes: []types.PermissionScope{
  995. types.UserScope,
  996. types.ProjectScope,
  997. types.ClusterScope,
  998. },
  999. },
  1000. )
  1001. listIncidentsHandler := cluster.NewListIncidentsHandler(
  1002. config,
  1003. factory.GetDecoderValidator(),
  1004. factory.GetResultWriter(),
  1005. )
  1006. routes = append(routes, &router.Route{
  1007. Endpoint: listIncidentsEndpoint,
  1008. Handler: listIncidentsHandler,
  1009. Router: r,
  1010. })
  1011. // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents/{incident_id} -> cluster.NewGetIncidentHandler
  1012. getIncidentEndpoint := factory.NewAPIEndpoint(
  1013. &types.APIRequestMetadata{
  1014. Verb: types.APIVerbGet,
  1015. Method: types.HTTPVerbGet,
  1016. Path: &types.Path{
  1017. Parent: basePath,
  1018. RelativePath: fmt.Sprintf("%s/incidents/{%s}", relPath, types.URLParamIncidentID),
  1019. },
  1020. Scopes: []types.PermissionScope{
  1021. types.UserScope,
  1022. types.ProjectScope,
  1023. types.ClusterScope,
  1024. },
  1025. },
  1026. )
  1027. getIncidentHandler := cluster.NewGetIncidentHandler(
  1028. config,
  1029. factory.GetDecoderValidator(),
  1030. factory.GetResultWriter(),
  1031. )
  1032. routes = append(routes, &router.Route{
  1033. Endpoint: getIncidentEndpoint,
  1034. Handler: getIncidentHandler,
  1035. Router: r,
  1036. })
  1037. // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents/events -> cluster.NewListIncidentEventsHandler
  1038. listIncidentEventsEndpoint := factory.NewAPIEndpoint(
  1039. &types.APIRequestMetadata{
  1040. Verb: types.APIVerbGet,
  1041. Method: types.HTTPVerbGet,
  1042. Path: &types.Path{
  1043. Parent: basePath,
  1044. RelativePath: fmt.Sprintf("%s/incidents/events", relPath),
  1045. },
  1046. Scopes: []types.PermissionScope{
  1047. types.UserScope,
  1048. types.ProjectScope,
  1049. types.ClusterScope,
  1050. },
  1051. },
  1052. )
  1053. listIncidentEventsHandler := cluster.NewListIncidentEventsHandler(
  1054. config,
  1055. factory.GetDecoderValidator(),
  1056. factory.GetResultWriter(),
  1057. )
  1058. routes = append(routes, &router.Route{
  1059. Endpoint: listIncidentEventsEndpoint,
  1060. Handler: listIncidentEventsHandler,
  1061. Router: r,
  1062. })
  1063. // GET /api/projects/{project_id}/clusters/{cluster_id}/logs -> cluster.NewGetLogsHandler
  1064. getLogsEndpoint := factory.NewAPIEndpoint(
  1065. &types.APIRequestMetadata{
  1066. Verb: types.APIVerbGet,
  1067. Method: types.HTTPVerbGet,
  1068. Path: &types.Path{
  1069. Parent: basePath,
  1070. RelativePath: fmt.Sprintf("%s/logs", relPath),
  1071. },
  1072. Scopes: []types.PermissionScope{
  1073. types.UserScope,
  1074. types.ProjectScope,
  1075. types.ClusterScope,
  1076. },
  1077. },
  1078. )
  1079. getLogsHandler := cluster.NewGetLogsHandler(
  1080. config,
  1081. factory.GetDecoderValidator(),
  1082. factory.GetResultWriter(),
  1083. )
  1084. routes = append(routes, &router.Route{
  1085. Endpoint: getLogsEndpoint,
  1086. Handler: getLogsHandler,
  1087. Router: r,
  1088. })
  1089. // GET /api/projects/{project_id}/clusters/{cluster_id}/logs/pod_values -> cluster.NewGetLogPodValuesHandler
  1090. getLogPodValuesEndpoint := factory.NewAPIEndpoint(
  1091. &types.APIRequestMetadata{
  1092. Verb: types.APIVerbGet,
  1093. Method: types.HTTPVerbGet,
  1094. Path: &types.Path{
  1095. Parent: basePath,
  1096. RelativePath: fmt.Sprintf("%s/logs/pod_values", relPath),
  1097. },
  1098. Scopes: []types.PermissionScope{
  1099. types.UserScope,
  1100. types.ProjectScope,
  1101. types.ClusterScope,
  1102. },
  1103. },
  1104. )
  1105. getLogPodValuesHandler := cluster.NewGetLogPodValuesHandler(
  1106. config,
  1107. factory.GetDecoderValidator(),
  1108. factory.GetResultWriter(),
  1109. )
  1110. routes = append(routes, &router.Route{
  1111. Endpoint: getLogPodValuesEndpoint,
  1112. Handler: getLogPodValuesHandler,
  1113. Router: r,
  1114. })
  1115. // GET /api/projects/{project_id}/clusters/{cluster_id}/logs/revision_values -> cluster.NewGetLogPodValuesHandler
  1116. getLogRevisionValuesEndpoint := factory.NewAPIEndpoint(
  1117. &types.APIRequestMetadata{
  1118. Verb: types.APIVerbGet,
  1119. Method: types.HTTPVerbGet,
  1120. Path: &types.Path{
  1121. Parent: basePath,
  1122. RelativePath: fmt.Sprintf("%s/logs/revision_values", relPath),
  1123. },
  1124. Scopes: []types.PermissionScope{
  1125. types.UserScope,
  1126. types.ProjectScope,
  1127. types.ClusterScope,
  1128. },
  1129. },
  1130. )
  1131. getLogRevisionValuesHandler := cluster.NewGetLogRevisionValuesHandler(
  1132. config,
  1133. factory.GetDecoderValidator(),
  1134. factory.GetResultWriter(),
  1135. )
  1136. routes = append(routes, &router.Route{
  1137. Endpoint: getLogRevisionValuesEndpoint,
  1138. Handler: getLogRevisionValuesHandler,
  1139. Router: r,
  1140. })
  1141. // GET /api/projects/{project_id}/clusters/{cluster_id}/events -> cluster.NewGetEventsHandler
  1142. getPorterEventsEndpoint := factory.NewAPIEndpoint(
  1143. &types.APIRequestMetadata{
  1144. Verb: types.APIVerbGet,
  1145. Method: types.HTTPVerbGet,
  1146. Path: &types.Path{
  1147. Parent: basePath,
  1148. RelativePath: fmt.Sprintf("%s/events", relPath),
  1149. },
  1150. Scopes: []types.PermissionScope{
  1151. types.UserScope,
  1152. types.ProjectScope,
  1153. types.ClusterScope,
  1154. },
  1155. },
  1156. )
  1157. getPorterEventsHandler := cluster.NewGetPorterEventsHandler(
  1158. config,
  1159. factory.GetDecoderValidator(),
  1160. factory.GetResultWriter(),
  1161. )
  1162. routes = append(routes, &router.Route{
  1163. Endpoint: getPorterEventsEndpoint,
  1164. Handler: getPorterEventsHandler,
  1165. Router: r,
  1166. })
  1167. // GET /api/projects/{project_id}/clusters/{cluster_id}/events/job -> cluster.NewGetPorterJobEventsHandler
  1168. getPorterJobEventsEndpoint := factory.NewAPIEndpoint(
  1169. &types.APIRequestMetadata{
  1170. Verb: types.APIVerbGet,
  1171. Method: types.HTTPVerbGet,
  1172. Path: &types.Path{
  1173. Parent: basePath,
  1174. RelativePath: fmt.Sprintf("%s/events/job", relPath),
  1175. },
  1176. Scopes: []types.PermissionScope{
  1177. types.UserScope,
  1178. types.ProjectScope,
  1179. types.ClusterScope,
  1180. },
  1181. },
  1182. )
  1183. getPorterJobEventsHandler := cluster.NewGetPorterJobEventsHandler(
  1184. config,
  1185. factory.GetDecoderValidator(),
  1186. factory.GetResultWriter(),
  1187. )
  1188. routes = append(routes, &router.Route{
  1189. Endpoint: getPorterJobEventsEndpoint,
  1190. Handler: getPorterJobEventsHandler,
  1191. Router: r,
  1192. })
  1193. // GET /api/projects/{project_id}/clusters/{cluster_id}/k8s_events -> cluster.NewGetEventsHandler
  1194. getK8sEventsEndpoint := factory.NewAPIEndpoint(
  1195. &types.APIRequestMetadata{
  1196. Verb: types.APIVerbGet,
  1197. Method: types.HTTPVerbGet,
  1198. Path: &types.Path{
  1199. Parent: basePath,
  1200. RelativePath: fmt.Sprintf("%s/k8s_events", relPath),
  1201. },
  1202. Scopes: []types.PermissionScope{
  1203. types.UserScope,
  1204. types.ProjectScope,
  1205. types.ClusterScope,
  1206. },
  1207. },
  1208. )
  1209. getK8sEventsHandler := cluster.NewGetKubernetesEventsHandler(
  1210. config,
  1211. factory.GetDecoderValidator(),
  1212. factory.GetResultWriter(),
  1213. )
  1214. routes = append(routes, &router.Route{
  1215. Endpoint: getK8sEventsEndpoint,
  1216. Handler: getK8sEventsHandler,
  1217. Router: r,
  1218. })
  1219. // POST /api/projects/{project_id}/clusters/{cluster_id}/incidents/notify_new -> cluster.NewNotifyNewIncidentHandler
  1220. notifyNewIncidentEndpoint := factory.NewAPIEndpoint(
  1221. &types.APIRequestMetadata{
  1222. Verb: types.APIVerbCreate,
  1223. Method: types.HTTPVerbPost,
  1224. Path: &types.Path{
  1225. Parent: basePath,
  1226. RelativePath: relPath + "/incidents/notify_new",
  1227. },
  1228. Scopes: []types.PermissionScope{
  1229. types.UserScope,
  1230. types.ProjectScope,
  1231. types.ClusterScope,
  1232. },
  1233. },
  1234. )
  1235. notifyNewIncidentHandler := cluster.NewNotifyNewIncidentHandler(
  1236. config,
  1237. factory.GetDecoderValidator(),
  1238. factory.GetResultWriter(),
  1239. )
  1240. routes = append(routes, &router.Route{
  1241. Endpoint: notifyNewIncidentEndpoint,
  1242. Handler: notifyNewIncidentHandler,
  1243. Router: r,
  1244. })
  1245. // POST /api/projects/{project_id}/clusters/{cluster_id}/incidents/notify_resolved -> cluster.NewNotifyResolvedIncidentHandler
  1246. notifyResolvedIncidentEndpoint := factory.NewAPIEndpoint(
  1247. &types.APIRequestMetadata{
  1248. Verb: types.APIVerbCreate,
  1249. Method: types.HTTPVerbPost,
  1250. Path: &types.Path{
  1251. Parent: basePath,
  1252. RelativePath: relPath + "/incidents/notify_resolved",
  1253. },
  1254. Scopes: []types.PermissionScope{
  1255. types.UserScope,
  1256. types.ProjectScope,
  1257. types.ClusterScope,
  1258. },
  1259. },
  1260. )
  1261. notifyResolvedIncidentHandler := cluster.NewNotifyResolvedIncidentHandler(
  1262. config,
  1263. factory.GetDecoderValidator(),
  1264. factory.GetResultWriter(),
  1265. )
  1266. routes = append(routes, &router.Route{
  1267. Endpoint: notifyResolvedIncidentEndpoint,
  1268. Handler: notifyResolvedIncidentHandler,
  1269. Router: r,
  1270. })
  1271. return routes, newPath
  1272. }