cluster.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  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)
  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. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewGetKubeEventHandler
  555. listKubeEventsEndpoint := factory.NewAPIEndpoint(
  556. &types.APIRequestMetadata{
  557. Verb: types.APIVerbGet,
  558. Method: types.HTTPVerbGet,
  559. Path: &types.Path{
  560. Parent: basePath,
  561. RelativePath: relPath + "/kube_events",
  562. },
  563. Scopes: []types.PermissionScope{
  564. types.UserScope,
  565. types.ProjectScope,
  566. types.ClusterScope,
  567. },
  568. },
  569. )
  570. listKubeEventsHandler := kube_events.NewListKubeEventsHandler(
  571. config,
  572. factory.GetDecoderValidator(),
  573. factory.GetResultWriter(),
  574. )
  575. routes = append(routes, &Route{
  576. Endpoint: listKubeEventsEndpoint,
  577. Handler: listKubeEventsHandler,
  578. Router: r,
  579. })
  580. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewGetKubeEventHandler
  581. getKubeEventEndpoint := factory.NewAPIEndpoint(
  582. &types.APIRequestMetadata{
  583. Verb: types.APIVerbGet,
  584. Method: types.HTTPVerbGet,
  585. Path: &types.Path{
  586. Parent: basePath,
  587. RelativePath: fmt.Sprintf("%s/kube_events/{%s}", relPath, types.URLParamKubeEventID),
  588. },
  589. Scopes: []types.PermissionScope{
  590. types.UserScope,
  591. types.ProjectScope,
  592. types.ClusterScope,
  593. },
  594. },
  595. )
  596. getKubeEventHandler := kube_events.NewGetKubeEventHandler(
  597. config,
  598. factory.GetDecoderValidator(),
  599. factory.GetResultWriter(),
  600. )
  601. routes = append(routes, &Route{
  602. Endpoint: getKubeEventEndpoint,
  603. Handler: getKubeEventHandler,
  604. Router: r,
  605. })
  606. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events/{kube_event_id}/logs -> kube_events.NewGetKubeEventLogsHandler
  607. getKubeEventLogsEndpoint := 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}/logs", relPath, types.URLParamKubeEventID),
  614. },
  615. Scopes: []types.PermissionScope{
  616. types.UserScope,
  617. types.ProjectScope,
  618. types.ClusterScope,
  619. },
  620. },
  621. )
  622. getKubeEventLogsHandler := kube_events.NewGetKubeEventLogsHandler(
  623. config,
  624. factory.GetDecoderValidator(),
  625. factory.GetResultWriter(),
  626. )
  627. routes = append(routes, &Route{
  628. Endpoint: getKubeEventLogsEndpoint,
  629. Handler: getKubeEventLogsHandler,
  630. Router: r,
  631. })
  632. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events/{kube_event_id}/log_buckets -> kube_events.NewGetKubeEventLogBucketsHandler
  633. getKubeEventLogBucketsEndpoint := 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}/log_buckets", relPath, types.URLParamKubeEventID),
  640. },
  641. Scopes: []types.PermissionScope{
  642. types.UserScope,
  643. types.ProjectScope,
  644. types.ClusterScope,
  645. },
  646. },
  647. )
  648. getKubeEventLogBucketsHandler := kube_events.NewGetKubeEventLogBucketsHandler(
  649. config,
  650. factory.GetDecoderValidator(),
  651. factory.GetResultWriter(),
  652. )
  653. routes = append(routes, &Route{
  654. Endpoint: getKubeEventLogBucketsEndpoint,
  655. Handler: getKubeEventLogBucketsHandler,
  656. Router: r,
  657. })
  658. // POST /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewCreateKubeEventHandler
  659. createKubeEventsEndpoint := factory.NewAPIEndpoint(
  660. &types.APIRequestMetadata{
  661. Verb: types.APIVerbCreate,
  662. Method: types.HTTPVerbPost,
  663. Path: &types.Path{
  664. Parent: basePath,
  665. RelativePath: relPath + "/kube_events",
  666. },
  667. Scopes: []types.PermissionScope{
  668. types.UserScope,
  669. types.ProjectScope,
  670. types.ClusterScope,
  671. },
  672. },
  673. )
  674. createKubeEventsHandler := kube_events.NewCreateKubeEventHandler(
  675. config,
  676. factory.GetDecoderValidator(),
  677. factory.GetResultWriter(),
  678. )
  679. routes = append(routes, &Route{
  680. Endpoint: createKubeEventsEndpoint,
  681. Handler: createKubeEventsHandler,
  682. Router: r,
  683. })
  684. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/ingresses -> cluster.NewListNGINXIngressesHandler
  685. listNGINXIngressesEndpoint := factory.NewAPIEndpoint(
  686. &types.APIRequestMetadata{
  687. Verb: types.APIVerbGet,
  688. Method: types.HTTPVerbGet,
  689. Path: &types.Path{
  690. Parent: basePath,
  691. RelativePath: relPath + "/prometheus/ingresses",
  692. },
  693. Scopes: []types.PermissionScope{
  694. types.UserScope,
  695. types.ProjectScope,
  696. types.ClusterScope,
  697. },
  698. },
  699. )
  700. listNGINXIngressesHandler := cluster.NewListNGINXIngressesHandler(
  701. config,
  702. factory.GetResultWriter(),
  703. )
  704. routes = append(routes, &Route{
  705. Endpoint: listNGINXIngressesEndpoint,
  706. Handler: listNGINXIngressesHandler,
  707. Router: r,
  708. })
  709. // GET /api/projects/{project_id}/clusters/{cluster_id}/metrics -> cluster.NewGetPodMetricsHandler
  710. getPodMetricsEndpoint := factory.NewAPIEndpoint(
  711. &types.APIRequestMetadata{
  712. Verb: types.APIVerbGet,
  713. Method: types.HTTPVerbGet,
  714. Path: &types.Path{
  715. Parent: basePath,
  716. RelativePath: relPath + "/metrics",
  717. },
  718. Scopes: []types.PermissionScope{
  719. types.UserScope,
  720. types.ProjectScope,
  721. types.ClusterScope,
  722. },
  723. },
  724. )
  725. getPodMetricsHandler := cluster.NewGetPodMetricsHandler(
  726. config,
  727. factory.GetDecoderValidator(),
  728. factory.GetResultWriter(),
  729. )
  730. routes = append(routes, &Route{
  731. Endpoint: getPodMetricsEndpoint,
  732. Handler: getPodMetricsHandler,
  733. Router: r,
  734. })
  735. // GET /api/projects/{project_id}/clusters/{cluster_id}/helm_release -> cluster.NewStreamHelmReleaseHandler
  736. streamHelmReleaseEndpoint := factory.NewAPIEndpoint(
  737. &types.APIRequestMetadata{
  738. Verb: types.APIVerbGet,
  739. Method: types.HTTPVerbGet,
  740. Path: &types.Path{
  741. Parent: basePath,
  742. RelativePath: relPath + "/helm_release",
  743. },
  744. Scopes: []types.PermissionScope{
  745. types.UserScope,
  746. types.ProjectScope,
  747. types.ClusterScope,
  748. },
  749. IsWebsocket: true,
  750. },
  751. )
  752. streamHelmReleaseHandler := cluster.NewStreamHelmReleaseHandler(
  753. config,
  754. factory.GetDecoderValidator(),
  755. factory.GetResultWriter(),
  756. )
  757. routes = append(routes, &Route{
  758. Endpoint: streamHelmReleaseEndpoint,
  759. Handler: streamHelmReleaseHandler,
  760. Router: r,
  761. })
  762. // GET /api/projects/{project_id}/clusters/{cluster_id}/{kind}/status -> cluster.NewStreamStatusHandler
  763. streamStatusEndpoint := factory.NewAPIEndpoint(
  764. &types.APIRequestMetadata{
  765. Verb: types.APIVerbGet,
  766. Method: types.HTTPVerbGet,
  767. Path: &types.Path{
  768. Parent: basePath,
  769. RelativePath: fmt.Sprintf(
  770. "%s/{%s}/status",
  771. relPath,
  772. types.URLParamKind,
  773. ),
  774. },
  775. Scopes: []types.PermissionScope{
  776. types.UserScope,
  777. types.ProjectScope,
  778. types.ClusterScope,
  779. },
  780. IsWebsocket: true,
  781. },
  782. )
  783. streamStatusHandler := cluster.NewStreamStatusHandler(
  784. config,
  785. factory.GetDecoderValidator(),
  786. factory.GetResultWriter(),
  787. )
  788. routes = append(routes, &Route{
  789. Endpoint: streamStatusEndpoint,
  790. Handler: streamStatusHandler,
  791. Router: r,
  792. })
  793. // GET /api/projects/{project_id}/clusters/{cluster_id}/pods -> cluster.NewGetPodsHandler
  794. getPodsEndpoint := factory.NewAPIEndpoint(
  795. &types.APIRequestMetadata{
  796. Verb: types.APIVerbGet,
  797. Method: types.HTTPVerbGet,
  798. Path: &types.Path{
  799. Parent: basePath,
  800. RelativePath: relPath + "/pods",
  801. },
  802. Scopes: []types.PermissionScope{
  803. types.UserScope,
  804. types.ProjectScope,
  805. types.ClusterScope,
  806. },
  807. },
  808. )
  809. getPodsHandler := cluster.NewGetPodsHandler(
  810. config,
  811. factory.GetDecoderValidator(),
  812. factory.GetResultWriter(),
  813. )
  814. routes = append(routes, &Route{
  815. Endpoint: getPodsEndpoint,
  816. Handler: getPodsHandler,
  817. Router: r,
  818. })
  819. return routes, newPath
  820. }