cluster.go 36 KB

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