cluster.go 35 KB

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