cluster.go 37 KB

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