cluster.go 35 KB

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