cluster.go 35 KB

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