cluster.go 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  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/types"
  12. )
  13. func NewClusterScopedRegisterer(children ...*Registerer) *Registerer {
  14. return &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 ...*Registerer,
  25. ) []*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. ) ([]*Route, *types.Path) {
  43. relPath := "/clusters/{cluster_id}"
  44. newPath := &types.Path{
  45. Parent: basePath,
  46. RelativePath: relPath,
  47. }
  48. routes := make([]*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, &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, &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, &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, &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, &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, &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, &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, &Route{
  252. Endpoint: listDatabaseEndpoint,
  253. Handler: listDatabaseHandler,
  254. Router: r,
  255. })
  256. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments -> environment.NewListEnvironmentHandler
  257. listEnvEndpoint := factory.NewAPIEndpoint(
  258. &types.APIRequestMetadata{
  259. Verb: types.APIVerbGet,
  260. Method: types.HTTPVerbGet,
  261. Path: &types.Path{
  262. Parent: basePath,
  263. RelativePath: relPath + "/environments",
  264. },
  265. Scopes: []types.PermissionScope{
  266. types.UserScope,
  267. types.ProjectScope,
  268. types.ClusterScope,
  269. },
  270. },
  271. )
  272. listEnvHandler := environment.NewListEnvironmentHandler(
  273. config,
  274. factory.GetResultWriter(),
  275. )
  276. routes = append(routes, &Route{
  277. Endpoint: listEnvEndpoint,
  278. Handler: listEnvHandler,
  279. Router: r,
  280. })
  281. // GET /api/projects/{project_id}/clusters/{cluster_id}/deployments -> environment.NewListDeploymentsByClusterHandler
  282. listDeploymentsEndpoint := factory.NewAPIEndpoint(
  283. &types.APIRequestMetadata{
  284. Verb: types.APIVerbGet,
  285. Method: types.HTTPVerbGet,
  286. Path: &types.Path{
  287. Parent: basePath,
  288. RelativePath: relPath + "/deployments",
  289. },
  290. Scopes: []types.PermissionScope{
  291. types.UserScope,
  292. types.ProjectScope,
  293. types.ClusterScope,
  294. },
  295. },
  296. )
  297. listDeploymentsHandler := environment.NewListDeploymentsByClusterHandler(
  298. config,
  299. factory.GetDecoderValidator(),
  300. factory.GetResultWriter(),
  301. )
  302. routes = append(routes, &Route{
  303. Endpoint: listDeploymentsEndpoint,
  304. Handler: listDeploymentsHandler,
  305. Router: r,
  306. })
  307. // GET /api/projects/{project_id}/clusters/{cluster_id}/{environment_id}/deployment -> environment.NewGetDeploymentByClusterHandler
  308. getDeploymentEndpoint := factory.NewAPIEndpoint(
  309. &types.APIRequestMetadata{
  310. Verb: types.APIVerbGet,
  311. Method: types.HTTPVerbGet,
  312. Path: &types.Path{
  313. Parent: basePath,
  314. RelativePath: relPath + "/{environment_id}/deployment",
  315. },
  316. Scopes: []types.PermissionScope{
  317. types.UserScope,
  318. types.ProjectScope,
  319. types.ClusterScope,
  320. },
  321. },
  322. )
  323. getDeploymentHandler := environment.NewGetDeploymentByClusterHandler(
  324. config,
  325. factory.GetDecoderValidator(),
  326. factory.GetResultWriter(),
  327. )
  328. routes = append(routes, &Route{
  329. Endpoint: getDeploymentEndpoint,
  330. Handler: getDeploymentHandler,
  331. Router: r,
  332. })
  333. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces -> cluster.NewClusterListNamespacesHandler
  334. listNamespacesEndpoint := factory.NewAPIEndpoint(
  335. &types.APIRequestMetadata{
  336. Verb: types.APIVerbGet,
  337. Method: types.HTTPVerbGet,
  338. Path: &types.Path{
  339. Parent: basePath,
  340. RelativePath: relPath + "/namespaces",
  341. },
  342. Scopes: []types.PermissionScope{
  343. types.UserScope,
  344. types.ProjectScope,
  345. types.ClusterScope,
  346. },
  347. },
  348. )
  349. listNamespacesHandler := cluster.NewListNamespacesHandler(
  350. config,
  351. factory.GetResultWriter(),
  352. )
  353. routes = append(routes, &Route{
  354. Endpoint: listNamespacesEndpoint,
  355. Handler: listNamespacesHandler,
  356. Router: r,
  357. })
  358. // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes -> cluster.NewListNodesHandler
  359. listNodesEndpoint := factory.NewAPIEndpoint(
  360. &types.APIRequestMetadata{
  361. Verb: types.APIVerbGet,
  362. Method: types.HTTPVerbGet,
  363. Path: &types.Path{
  364. Parent: basePath,
  365. RelativePath: relPath + "/nodes",
  366. },
  367. Scopes: []types.PermissionScope{
  368. types.UserScope,
  369. types.ProjectScope,
  370. types.ClusterScope,
  371. },
  372. },
  373. )
  374. listNodesHandler := cluster.NewListNodesHandler(
  375. config,
  376. factory.GetResultWriter(),
  377. )
  378. routes = append(routes, &Route{
  379. Endpoint: listNodesEndpoint,
  380. Handler: listNodesHandler,
  381. Router: r,
  382. })
  383. // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes/{node_name} -> cluster.NewGetNodeHandler
  384. getNodeEndpoint := factory.NewAPIEndpoint(
  385. &types.APIRequestMetadata{
  386. Verb: types.APIVerbGet,
  387. Method: types.HTTPVerbGet,
  388. Path: &types.Path{
  389. Parent: basePath,
  390. RelativePath: fmt.Sprintf("%s/nodes/{%s}", relPath, types.URLParamNodeName),
  391. },
  392. Scopes: []types.PermissionScope{
  393. types.UserScope,
  394. types.ProjectScope,
  395. types.ClusterScope,
  396. },
  397. },
  398. )
  399. getNodeHandler := cluster.NewGetNodeHandler(
  400. config,
  401. factory.GetResultWriter(),
  402. )
  403. routes = append(routes, &Route{
  404. Endpoint: getNodeEndpoint,
  405. Handler: getNodeHandler,
  406. Router: r,
  407. })
  408. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/create -> cluster.NewCreateNamespaceHandler
  409. createNamespaceEndpoint := factory.NewAPIEndpoint(
  410. &types.APIRequestMetadata{
  411. Verb: types.APIVerbCreate,
  412. Method: types.HTTPVerbPost,
  413. Path: &types.Path{
  414. Parent: basePath,
  415. RelativePath: relPath + "/namespaces/create",
  416. },
  417. Scopes: []types.PermissionScope{
  418. types.UserScope,
  419. types.ProjectScope,
  420. types.ClusterScope,
  421. },
  422. },
  423. )
  424. createNamespaceHandler := cluster.NewCreateNamespaceHandler(
  425. config,
  426. factory.GetDecoderValidator(),
  427. factory.GetResultWriter(),
  428. )
  429. routes = append(routes, &Route{
  430. Endpoint: createNamespaceEndpoint,
  431. Handler: createNamespaceHandler,
  432. Router: r,
  433. })
  434. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/delete -> cluster.NewDeleteNamespaceHandler
  435. deleteNamespaceEndpoint := factory.NewAPIEndpoint(
  436. &types.APIRequestMetadata{
  437. Verb: types.APIVerbDelete,
  438. Method: types.HTTPVerbDelete,
  439. Path: &types.Path{
  440. Parent: basePath,
  441. RelativePath: relPath + "/namespaces/delete",
  442. },
  443. Scopes: []types.PermissionScope{
  444. types.UserScope,
  445. types.ProjectScope,
  446. types.ClusterScope,
  447. },
  448. },
  449. )
  450. deleteNamespaceHandler := cluster.NewDeleteNamespaceHandler(
  451. config,
  452. factory.GetDecoderValidator(),
  453. )
  454. routes = append(routes, &Route{
  455. Endpoint: deleteNamespaceEndpoint,
  456. Handler: deleteNamespaceHandler,
  457. Router: r,
  458. })
  459. // GET /api/projects/{project_id}/clusters/{cluster_id}/kubeconfig -> cluster.NewGetTemporaryKubeconfigHandler
  460. getTemporaryKubeconfigEndpoint := factory.NewAPIEndpoint(
  461. &types.APIRequestMetadata{
  462. Verb: types.APIVerbGet,
  463. Method: types.HTTPVerbGet,
  464. Path: &types.Path{
  465. Parent: basePath,
  466. RelativePath: relPath + "/kubeconfig",
  467. },
  468. Scopes: []types.PermissionScope{
  469. types.UserScope,
  470. types.ProjectScope,
  471. types.ClusterScope,
  472. },
  473. },
  474. )
  475. getTemporaryKubeconfigHandler := cluster.NewGetTemporaryKubeconfigHandler(
  476. config,
  477. factory.GetResultWriter(),
  478. )
  479. routes = append(routes, &Route{
  480. Endpoint: getTemporaryKubeconfigEndpoint,
  481. Handler: getTemporaryKubeconfigHandler,
  482. Router: r,
  483. })
  484. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/detect -> cluster.NewDetectPrometheusInstalledHandler
  485. detectPrometheusInstalledEndpoint := factory.NewAPIEndpoint(
  486. &types.APIRequestMetadata{
  487. Verb: types.APIVerbGet,
  488. Method: types.HTTPVerbGet,
  489. Path: &types.Path{
  490. Parent: basePath,
  491. RelativePath: relPath + "/prometheus/detect",
  492. },
  493. Scopes: []types.PermissionScope{
  494. types.UserScope,
  495. types.ProjectScope,
  496. types.ClusterScope,
  497. },
  498. },
  499. )
  500. detectPrometheusInstalledHandler := cluster.NewDetectPrometheusInstalledHandler(config)
  501. routes = append(routes, &Route{
  502. Endpoint: detectPrometheusInstalledEndpoint,
  503. Handler: detectPrometheusInstalledHandler,
  504. Router: r,
  505. })
  506. // GET /api/projects/{project_id}/clusters/{cluster_id}/agent/detect -> cluster.NewDetectAgentInstalledHandler
  507. detectAgentInstalledEndpoint := factory.NewAPIEndpoint(
  508. &types.APIRequestMetadata{
  509. Verb: types.APIVerbGet,
  510. Method: types.HTTPVerbGet,
  511. Path: &types.Path{
  512. Parent: basePath,
  513. RelativePath: relPath + "/agent/detect",
  514. },
  515. Scopes: []types.PermissionScope{
  516. types.UserScope,
  517. types.ProjectScope,
  518. types.ClusterScope,
  519. },
  520. },
  521. )
  522. detectAgentInstalledHandler := cluster.NewDetectAgentInstalledHandler(config, factory.GetResultWriter())
  523. routes = append(routes, &Route{
  524. Endpoint: detectAgentInstalledEndpoint,
  525. Handler: detectAgentInstalledHandler,
  526. Router: r,
  527. })
  528. // POST /api/projects/{project_id}/clusters/{cluster_id}/agent/install -> cluster.NewInstallAgentHandler
  529. installAgentEndpoint := factory.NewAPIEndpoint(
  530. &types.APIRequestMetadata{
  531. Verb: types.APIVerbCreate,
  532. Method: types.HTTPVerbPost,
  533. Path: &types.Path{
  534. Parent: basePath,
  535. RelativePath: relPath + "/agent/install",
  536. },
  537. Scopes: []types.PermissionScope{
  538. types.UserScope,
  539. types.ProjectScope,
  540. types.ClusterScope,
  541. },
  542. },
  543. )
  544. installAgentHandler := cluster.NewInstallAgentHandler(
  545. config,
  546. factory.GetDecoderValidator(),
  547. factory.GetResultWriter(),
  548. )
  549. routes = append(routes, &Route{
  550. Endpoint: installAgentEndpoint,
  551. Handler: installAgentHandler,
  552. Router: r,
  553. })
  554. // POST /api/projects/{project_id}/clusters/{cluster_id}/agent/upgrade -> cluster.NewInstallAgentHandler
  555. upgradeAgentEndpoint := factory.NewAPIEndpoint(
  556. &types.APIRequestMetadata{
  557. Verb: types.APIVerbCreate,
  558. Method: types.HTTPVerbPost,
  559. Path: &types.Path{
  560. Parent: basePath,
  561. RelativePath: relPath + "/agent/upgrade",
  562. },
  563. Scopes: []types.PermissionScope{
  564. types.UserScope,
  565. types.ProjectScope,
  566. types.ClusterScope,
  567. },
  568. },
  569. )
  570. upgradeAgentHandler := cluster.NewUpgradeAgentHandler(
  571. config,
  572. factory.GetDecoderValidator(),
  573. factory.GetResultWriter(),
  574. )
  575. routes = append(routes, &Route{
  576. Endpoint: upgradeAgentEndpoint,
  577. Handler: upgradeAgentHandler,
  578. Router: r,
  579. })
  580. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewGetKubeEventHandler
  581. listKubeEventsEndpoint := factory.NewAPIEndpoint(
  582. &types.APIRequestMetadata{
  583. Verb: types.APIVerbGet,
  584. Method: types.HTTPVerbGet,
  585. Path: &types.Path{
  586. Parent: basePath,
  587. RelativePath: relPath + "/kube_events",
  588. },
  589. Scopes: []types.PermissionScope{
  590. types.UserScope,
  591. types.ProjectScope,
  592. types.ClusterScope,
  593. },
  594. },
  595. )
  596. listKubeEventsHandler := kube_events.NewListKubeEventsHandler(
  597. config,
  598. factory.GetDecoderValidator(),
  599. factory.GetResultWriter(),
  600. )
  601. routes = append(routes, &Route{
  602. Endpoint: listKubeEventsEndpoint,
  603. Handler: listKubeEventsHandler,
  604. Router: r,
  605. })
  606. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewGetKubeEventHandler
  607. getKubeEventEndpoint := factory.NewAPIEndpoint(
  608. &types.APIRequestMetadata{
  609. Verb: types.APIVerbGet,
  610. Method: types.HTTPVerbGet,
  611. Path: &types.Path{
  612. Parent: basePath,
  613. RelativePath: fmt.Sprintf("%s/kube_events/{%s}", relPath, types.URLParamKubeEventID),
  614. },
  615. Scopes: []types.PermissionScope{
  616. types.UserScope,
  617. types.ProjectScope,
  618. types.ClusterScope,
  619. },
  620. },
  621. )
  622. getKubeEventHandler := kube_events.NewGetKubeEventHandler(
  623. config,
  624. factory.GetDecoderValidator(),
  625. factory.GetResultWriter(),
  626. )
  627. routes = append(routes, &Route{
  628. Endpoint: getKubeEventEndpoint,
  629. Handler: getKubeEventHandler,
  630. Router: r,
  631. })
  632. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events/{kube_event_id}/logs -> kube_events.NewGetKubeEventLogsHandler
  633. getKubeEventLogsEndpoint := factory.NewAPIEndpoint(
  634. &types.APIRequestMetadata{
  635. Verb: types.APIVerbGet,
  636. Method: types.HTTPVerbGet,
  637. Path: &types.Path{
  638. Parent: basePath,
  639. RelativePath: fmt.Sprintf("%s/kube_events/{%s}/logs", relPath, types.URLParamKubeEventID),
  640. },
  641. Scopes: []types.PermissionScope{
  642. types.UserScope,
  643. types.ProjectScope,
  644. types.ClusterScope,
  645. },
  646. },
  647. )
  648. getKubeEventLogsHandler := kube_events.NewGetKubeEventLogsHandler(
  649. config,
  650. factory.GetDecoderValidator(),
  651. factory.GetResultWriter(),
  652. )
  653. routes = append(routes, &Route{
  654. Endpoint: getKubeEventLogsEndpoint,
  655. Handler: getKubeEventLogsHandler,
  656. Router: r,
  657. })
  658. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events/{kube_event_id}/log_buckets -> kube_events.NewGetKubeEventLogBucketsHandler
  659. getKubeEventLogBucketsEndpoint := factory.NewAPIEndpoint(
  660. &types.APIRequestMetadata{
  661. Verb: types.APIVerbGet,
  662. Method: types.HTTPVerbGet,
  663. Path: &types.Path{
  664. Parent: basePath,
  665. RelativePath: fmt.Sprintf("%s/kube_events/{%s}/log_buckets", relPath, types.URLParamKubeEventID),
  666. },
  667. Scopes: []types.PermissionScope{
  668. types.UserScope,
  669. types.ProjectScope,
  670. types.ClusterScope,
  671. },
  672. },
  673. )
  674. getKubeEventLogBucketsHandler := kube_events.NewGetKubeEventLogBucketsHandler(
  675. config,
  676. factory.GetDecoderValidator(),
  677. factory.GetResultWriter(),
  678. )
  679. routes = append(routes, &Route{
  680. Endpoint: getKubeEventLogBucketsEndpoint,
  681. Handler: getKubeEventLogBucketsHandler,
  682. Router: r,
  683. })
  684. // POST /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewCreateKubeEventHandler
  685. createKubeEventsEndpoint := factory.NewAPIEndpoint(
  686. &types.APIRequestMetadata{
  687. Verb: types.APIVerbCreate,
  688. Method: types.HTTPVerbPost,
  689. Path: &types.Path{
  690. Parent: basePath,
  691. RelativePath: relPath + "/kube_events",
  692. },
  693. Scopes: []types.PermissionScope{
  694. types.UserScope,
  695. types.ProjectScope,
  696. types.ClusterScope,
  697. },
  698. },
  699. )
  700. createKubeEventsHandler := kube_events.NewCreateKubeEventHandler(
  701. config,
  702. factory.GetDecoderValidator(),
  703. factory.GetResultWriter(),
  704. )
  705. routes = append(routes, &Route{
  706. Endpoint: createKubeEventsEndpoint,
  707. Handler: createKubeEventsHandler,
  708. Router: r,
  709. })
  710. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/ingresses -> cluster.NewListNGINXIngressesHandler
  711. listNGINXIngressesEndpoint := factory.NewAPIEndpoint(
  712. &types.APIRequestMetadata{
  713. Verb: types.APIVerbGet,
  714. Method: types.HTTPVerbGet,
  715. Path: &types.Path{
  716. Parent: basePath,
  717. RelativePath: relPath + "/prometheus/ingresses",
  718. },
  719. Scopes: []types.PermissionScope{
  720. types.UserScope,
  721. types.ProjectScope,
  722. types.ClusterScope,
  723. },
  724. },
  725. )
  726. listNGINXIngressesHandler := cluster.NewListNGINXIngressesHandler(
  727. config,
  728. factory.GetResultWriter(),
  729. )
  730. routes = append(routes, &Route{
  731. Endpoint: listNGINXIngressesEndpoint,
  732. Handler: listNGINXIngressesHandler,
  733. Router: r,
  734. })
  735. // GET /api/projects/{project_id}/clusters/{cluster_id}/metrics -> cluster.NewGetPodMetricsHandler
  736. getPodMetricsEndpoint := factory.NewAPIEndpoint(
  737. &types.APIRequestMetadata{
  738. Verb: types.APIVerbGet,
  739. Method: types.HTTPVerbGet,
  740. Path: &types.Path{
  741. Parent: basePath,
  742. RelativePath: relPath + "/metrics",
  743. },
  744. Scopes: []types.PermissionScope{
  745. types.UserScope,
  746. types.ProjectScope,
  747. types.ClusterScope,
  748. },
  749. },
  750. )
  751. getPodMetricsHandler := cluster.NewGetPodMetricsHandler(
  752. config,
  753. factory.GetDecoderValidator(),
  754. factory.GetResultWriter(),
  755. )
  756. routes = append(routes, &Route{
  757. Endpoint: getPodMetricsEndpoint,
  758. Handler: getPodMetricsHandler,
  759. Router: r,
  760. })
  761. // GET /api/projects/{project_id}/clusters/{cluster_id}/helm_release -> cluster.NewStreamHelmReleaseHandler
  762. streamHelmReleaseEndpoint := factory.NewAPIEndpoint(
  763. &types.APIRequestMetadata{
  764. Verb: types.APIVerbGet,
  765. Method: types.HTTPVerbGet,
  766. Path: &types.Path{
  767. Parent: basePath,
  768. RelativePath: relPath + "/helm_release",
  769. },
  770. Scopes: []types.PermissionScope{
  771. types.UserScope,
  772. types.ProjectScope,
  773. types.ClusterScope,
  774. },
  775. IsWebsocket: true,
  776. },
  777. )
  778. streamHelmReleaseHandler := cluster.NewStreamHelmReleaseHandler(
  779. config,
  780. factory.GetDecoderValidator(),
  781. factory.GetResultWriter(),
  782. )
  783. routes = append(routes, &Route{
  784. Endpoint: streamHelmReleaseEndpoint,
  785. Handler: streamHelmReleaseHandler,
  786. Router: r,
  787. })
  788. // GET /api/projects/{project_id}/clusters/{cluster_id}/{kind}/status -> cluster.NewStreamStatusHandler
  789. streamStatusEndpoint := factory.NewAPIEndpoint(
  790. &types.APIRequestMetadata{
  791. Verb: types.APIVerbGet,
  792. Method: types.HTTPVerbGet,
  793. Path: &types.Path{
  794. Parent: basePath,
  795. RelativePath: fmt.Sprintf(
  796. "%s/{%s}/status",
  797. relPath,
  798. types.URLParamKind,
  799. ),
  800. },
  801. Scopes: []types.PermissionScope{
  802. types.UserScope,
  803. types.ProjectScope,
  804. types.ClusterScope,
  805. },
  806. IsWebsocket: true,
  807. },
  808. )
  809. streamStatusHandler := cluster.NewStreamStatusHandler(
  810. config,
  811. factory.GetDecoderValidator(),
  812. factory.GetResultWriter(),
  813. )
  814. routes = append(routes, &Route{
  815. Endpoint: streamStatusEndpoint,
  816. Handler: streamStatusHandler,
  817. Router: r,
  818. })
  819. // GET /api/projects/{project_id}/clusters/{cluster_id}/pods -> cluster.NewGetPodsHandler
  820. getPodsEndpoint := factory.NewAPIEndpoint(
  821. &types.APIRequestMetadata{
  822. Verb: types.APIVerbGet,
  823. Method: types.HTTPVerbGet,
  824. Path: &types.Path{
  825. Parent: basePath,
  826. RelativePath: relPath + "/pods",
  827. },
  828. Scopes: []types.PermissionScope{
  829. types.UserScope,
  830. types.ProjectScope,
  831. types.ClusterScope,
  832. },
  833. },
  834. )
  835. getPodsHandler := cluster.NewGetPodsHandler(
  836. config,
  837. factory.GetDecoderValidator(),
  838. factory.GetResultWriter(),
  839. )
  840. routes = append(routes, &Route{
  841. Endpoint: getPodsEndpoint,
  842. Handler: getPodsHandler,
  843. Router: r,
  844. })
  845. // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents -> cluster.NewGetIncidentsHandler
  846. getIncidentsEndpoint := factory.NewAPIEndpoint(
  847. &types.APIRequestMetadata{
  848. Verb: types.APIVerbGet,
  849. Method: types.HTTPVerbGet,
  850. Path: &types.Path{
  851. Parent: basePath,
  852. RelativePath: relPath + "/incidents",
  853. },
  854. Scopes: []types.PermissionScope{
  855. types.UserScope,
  856. types.ProjectScope,
  857. types.ClusterScope,
  858. },
  859. },
  860. )
  861. getIncidentsHandler := cluster.NewGetIncidentsHandler(
  862. config,
  863. factory.GetDecoderValidator(),
  864. factory.GetResultWriter(),
  865. )
  866. routes = append(routes, &Route{
  867. Endpoint: getIncidentsEndpoint,
  868. Handler: getIncidentsHandler,
  869. Router: r,
  870. })
  871. // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents/logs -> cluster.NewGetIncidentsHandler
  872. getIncidentEventLogsEndpoint := factory.NewAPIEndpoint(
  873. &types.APIRequestMetadata{
  874. Verb: types.APIVerbGet,
  875. Method: types.HTTPVerbGet,
  876. Path: &types.Path{
  877. Parent: basePath,
  878. RelativePath: relPath + "/incidents/logs",
  879. },
  880. Scopes: []types.PermissionScope{
  881. types.UserScope,
  882. types.ProjectScope,
  883. types.ClusterScope,
  884. },
  885. },
  886. )
  887. getIncidentEventLogsHandler := cluster.NewGetIncidentEventLogsHandler(
  888. config,
  889. factory.GetDecoderValidator(),
  890. factory.GetResultWriter(),
  891. )
  892. routes = append(routes, &Route{
  893. Endpoint: getIncidentEventLogsEndpoint,
  894. Handler: getIncidentEventLogsHandler,
  895. Router: r,
  896. })
  897. // POST /api/projects/{project_id}/clusters/{cluster_id}/incidents/notify_new -> cluster.NewNotifyNewIncidentHandler
  898. notifyNewIncidentEndpoint := factory.NewAPIEndpoint(
  899. &types.APIRequestMetadata{
  900. Verb: types.APIVerbCreate,
  901. Method: types.HTTPVerbPost,
  902. Path: &types.Path{
  903. Parent: basePath,
  904. RelativePath: relPath + "/incidents/notify_new",
  905. },
  906. Scopes: []types.PermissionScope{
  907. types.UserScope,
  908. types.ProjectScope,
  909. types.ClusterScope,
  910. },
  911. },
  912. )
  913. notifyNewIncidentHandler := cluster.NewNotifyNewIncidentHandler(
  914. config,
  915. factory.GetDecoderValidator(),
  916. factory.GetResultWriter(),
  917. )
  918. routes = append(routes, &Route{
  919. Endpoint: notifyNewIncidentEndpoint,
  920. Handler: notifyNewIncidentHandler,
  921. Router: r,
  922. })
  923. // POST /api/projects/{project_id}/clusters/{cluster_id}/incidents/notify_resolved -> cluster.NewNotifyResolvedIncidentHandler
  924. notifyResolvedIncidentEndpoint := factory.NewAPIEndpoint(
  925. &types.APIRequestMetadata{
  926. Verb: types.APIVerbCreate,
  927. Method: types.HTTPVerbPost,
  928. Path: &types.Path{
  929. Parent: basePath,
  930. RelativePath: relPath + "/incidents/notify_resolved",
  931. },
  932. Scopes: []types.PermissionScope{
  933. types.UserScope,
  934. types.ProjectScope,
  935. types.ClusterScope,
  936. },
  937. },
  938. )
  939. notifyResolvedIncidentHandler := cluster.NewNotifyResolvedIncidentHandler(
  940. config,
  941. factory.GetDecoderValidator(),
  942. factory.GetResultWriter(),
  943. )
  944. routes = append(routes, &Route{
  945. Endpoint: notifyResolvedIncidentEndpoint,
  946. Handler: notifyResolvedIncidentHandler,
  947. Router: r,
  948. })
  949. return routes, newPath
  950. }