cluster.go 36 KB

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