cluster.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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/environment"
  7. "github.com/porter-dev/porter/api/server/handlers/kube_events"
  8. "github.com/porter-dev/porter/api/server/shared"
  9. "github.com/porter-dev/porter/api/server/shared/config"
  10. "github.com/porter-dev/porter/api/types"
  11. )
  12. func NewClusterScopedRegisterer(children ...*Registerer) *Registerer {
  13. return &Registerer{
  14. GetRoutes: GetClusterScopedRoutes,
  15. Children: children,
  16. }
  17. }
  18. func GetClusterScopedRoutes(
  19. r chi.Router,
  20. config *config.Config,
  21. basePath *types.Path,
  22. factory shared.APIEndpointFactory,
  23. children ...*Registerer,
  24. ) []*Route {
  25. routes, projPath := getClusterRoutes(r, config, basePath, factory)
  26. if len(children) > 0 {
  27. r.Route(projPath.RelativePath, func(r chi.Router) {
  28. for _, child := range children {
  29. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  30. routes = append(routes, childRoutes...)
  31. }
  32. })
  33. }
  34. return routes
  35. }
  36. func getClusterRoutes(
  37. r chi.Router,
  38. config *config.Config,
  39. basePath *types.Path,
  40. factory shared.APIEndpointFactory,
  41. ) ([]*Route, *types.Path) {
  42. relPath := "/clusters/{cluster_id}"
  43. newPath := &types.Path{
  44. Parent: basePath,
  45. RelativePath: relPath,
  46. }
  47. routes := make([]*Route, 0)
  48. // POST /api/projects/{project_id}/clusters -> project.NewCreateClusterManualHandler
  49. createEndpoint := factory.NewAPIEndpoint(
  50. &types.APIRequestMetadata{
  51. Verb: types.APIVerbCreate,
  52. Method: types.HTTPVerbPost,
  53. Path: &types.Path{
  54. Parent: basePath,
  55. RelativePath: "/clusters",
  56. },
  57. Scopes: []types.PermissionScope{
  58. types.UserScope,
  59. types.ProjectScope,
  60. },
  61. },
  62. )
  63. createHandler := cluster.NewCreateClusterManualHandler(
  64. config,
  65. factory.GetDecoderValidator(),
  66. factory.GetResultWriter(),
  67. )
  68. routes = append(routes, &Route{
  69. Endpoint: createEndpoint,
  70. Handler: createHandler,
  71. Router: r,
  72. })
  73. // POST /api/projects/{project_id}/clusters/candidates -> project.NewCreateClusterCandidateHandler
  74. createCandidateEndpoint := factory.NewAPIEndpoint(
  75. &types.APIRequestMetadata{
  76. Verb: types.APIVerbCreate,
  77. Method: types.HTTPVerbPost,
  78. Path: &types.Path{
  79. Parent: basePath,
  80. RelativePath: "/clusters/candidates",
  81. },
  82. Scopes: []types.PermissionScope{
  83. types.UserScope,
  84. types.ProjectScope,
  85. },
  86. CheckUsage: true,
  87. UsageMetric: types.Clusters,
  88. },
  89. )
  90. createCandidateHandler := cluster.NewCreateClusterCandidateHandler(
  91. config,
  92. factory.GetDecoderValidator(),
  93. factory.GetResultWriter(),
  94. )
  95. routes = append(routes, &Route{
  96. Endpoint: createCandidateEndpoint,
  97. Handler: createCandidateHandler,
  98. Router: r,
  99. })
  100. // GET /api/projects/{project_id}/clusters/candidates -> project.NewListClusterCandidatesHandler
  101. listCandidatesEndpoint := factory.NewAPIEndpoint(
  102. &types.APIRequestMetadata{
  103. Verb: types.APIVerbList,
  104. Method: types.HTTPVerbGet,
  105. Path: &types.Path{
  106. Parent: basePath,
  107. RelativePath: "/clusters/candidates",
  108. },
  109. Scopes: []types.PermissionScope{
  110. types.UserScope,
  111. types.ProjectScope,
  112. },
  113. },
  114. )
  115. listCandidatesHandler := cluster.NewListClusterCandidatesHandler(
  116. config,
  117. factory.GetResultWriter(),
  118. )
  119. routes = append(routes, &Route{
  120. Endpoint: listCandidatesEndpoint,
  121. Handler: listCandidatesHandler,
  122. Router: r,
  123. })
  124. // POST /api/projects/{project_id}/clusters/candidates/{candidate_id}/resolve -> project.NewResolveClusterCandidateHandler
  125. resolveCandidateEndpoint := factory.NewAPIEndpoint(
  126. &types.APIRequestMetadata{
  127. Verb: types.APIVerbCreate,
  128. Method: types.HTTPVerbPost,
  129. Path: &types.Path{
  130. Parent: basePath,
  131. RelativePath: fmt.Sprintf(
  132. "/clusters/candidates/{%s}/resolve",
  133. types.URLParamCandidateID,
  134. ),
  135. },
  136. Scopes: []types.PermissionScope{
  137. types.UserScope,
  138. types.ProjectScope,
  139. },
  140. CheckUsage: true,
  141. UsageMetric: types.Clusters,
  142. },
  143. )
  144. resolveCandidateHandler := cluster.NewResolveClusterCandidateHandler(
  145. config,
  146. factory.GetDecoderValidator(),
  147. factory.GetResultWriter(),
  148. )
  149. routes = append(routes, &Route{
  150. Endpoint: resolveCandidateEndpoint,
  151. Handler: resolveCandidateHandler,
  152. Router: r,
  153. })
  154. // POST /api/projects/{project_id}/clusters/{cluster_id} -> project.NewClusterUpdateHandler
  155. updateClusterEndpoint := factory.NewAPIEndpoint(
  156. &types.APIRequestMetadata{
  157. Verb: types.APIVerbUpdate,
  158. Method: types.HTTPVerbPost,
  159. Path: &types.Path{
  160. Parent: basePath,
  161. RelativePath: relPath,
  162. },
  163. Scopes: []types.PermissionScope{
  164. types.UserScope,
  165. types.ProjectScope,
  166. types.ClusterScope,
  167. },
  168. },
  169. )
  170. updateClusterHandler := cluster.NewClusterUpdateHandler(
  171. config,
  172. factory.GetDecoderValidator(),
  173. factory.GetResultWriter(),
  174. )
  175. routes = append(routes, &Route{
  176. Endpoint: updateClusterEndpoint,
  177. Handler: updateClusterHandler,
  178. Router: r,
  179. })
  180. // DELETE /api/projects/{project_id}/clusters/{cluster_id} -> project.NewClusterDeleteHandler
  181. deleteClusterEndpoint := factory.NewAPIEndpoint(
  182. &types.APIRequestMetadata{
  183. Verb: types.APIVerbDelete,
  184. Method: types.HTTPVerbDelete,
  185. Path: &types.Path{
  186. Parent: basePath,
  187. RelativePath: relPath,
  188. },
  189. Scopes: []types.PermissionScope{
  190. types.UserScope,
  191. types.ProjectScope,
  192. types.ClusterScope,
  193. },
  194. },
  195. )
  196. deleteClusterHandler := cluster.NewClusterDeleteHandler(
  197. config,
  198. factory.GetResultWriter(),
  199. )
  200. routes = append(routes, &Route{
  201. Endpoint: deleteClusterEndpoint,
  202. Handler: deleteClusterHandler,
  203. Router: r,
  204. })
  205. // GET /api/projects/{project_id}/clusters/{cluster_id} -> project.NewClusterGetHandler
  206. getEndpoint := factory.NewAPIEndpoint(
  207. &types.APIRequestMetadata{
  208. Verb: types.APIVerbGet,
  209. Method: types.HTTPVerbGet,
  210. Path: &types.Path{
  211. Parent: basePath,
  212. RelativePath: relPath,
  213. },
  214. Scopes: []types.PermissionScope{
  215. types.UserScope,
  216. types.ProjectScope,
  217. types.ClusterScope,
  218. },
  219. },
  220. )
  221. getHandler := cluster.NewClusterGetHandler(
  222. config,
  223. factory.GetResultWriter(),
  224. )
  225. routes = append(routes, &Route{
  226. Endpoint: getEndpoint,
  227. Handler: getHandler,
  228. Router: r,
  229. })
  230. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments -> environment.NewListEnvironmentHandler
  231. listEnvEndpoint := factory.NewAPIEndpoint(
  232. &types.APIRequestMetadata{
  233. Verb: types.APIVerbGet,
  234. Method: types.HTTPVerbGet,
  235. Path: &types.Path{
  236. Parent: basePath,
  237. RelativePath: relPath + "/environments",
  238. },
  239. Scopes: []types.PermissionScope{
  240. types.UserScope,
  241. types.ProjectScope,
  242. types.ClusterScope,
  243. },
  244. },
  245. )
  246. listEnvHandler := environment.NewListEnvironmentHandler(
  247. config,
  248. factory.GetResultWriter(),
  249. )
  250. routes = append(routes, &Route{
  251. Endpoint: listEnvEndpoint,
  252. Handler: listEnvHandler,
  253. Router: r,
  254. })
  255. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces -> cluster.NewClusterListNamespacesHandler
  256. listNamespacesEndpoint := factory.NewAPIEndpoint(
  257. &types.APIRequestMetadata{
  258. Verb: types.APIVerbGet,
  259. Method: types.HTTPVerbGet,
  260. Path: &types.Path{
  261. Parent: basePath,
  262. RelativePath: relPath + "/namespaces",
  263. },
  264. Scopes: []types.PermissionScope{
  265. types.UserScope,
  266. types.ProjectScope,
  267. types.ClusterScope,
  268. },
  269. },
  270. )
  271. listNamespacesHandler := cluster.NewListNamespacesHandler(
  272. config,
  273. factory.GetResultWriter(),
  274. )
  275. routes = append(routes, &Route{
  276. Endpoint: listNamespacesEndpoint,
  277. Handler: listNamespacesHandler,
  278. Router: r,
  279. })
  280. // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes -> cluster.NewListNodesHandler
  281. listNodesEndpoint := factory.NewAPIEndpoint(
  282. &types.APIRequestMetadata{
  283. Verb: types.APIVerbGet,
  284. Method: types.HTTPVerbGet,
  285. Path: &types.Path{
  286. Parent: basePath,
  287. RelativePath: relPath + "/nodes",
  288. },
  289. Scopes: []types.PermissionScope{
  290. types.UserScope,
  291. types.ProjectScope,
  292. types.ClusterScope,
  293. },
  294. },
  295. )
  296. listNodesHandler := cluster.NewListNodesHandler(
  297. config,
  298. factory.GetResultWriter(),
  299. )
  300. routes = append(routes, &Route{
  301. Endpoint: listNodesEndpoint,
  302. Handler: listNodesHandler,
  303. Router: r,
  304. })
  305. // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes/{node_name} -> cluster.NewGetNodeHandler
  306. getNodeEndpoint := factory.NewAPIEndpoint(
  307. &types.APIRequestMetadata{
  308. Verb: types.APIVerbGet,
  309. Method: types.HTTPVerbGet,
  310. Path: &types.Path{
  311. Parent: basePath,
  312. RelativePath: fmt.Sprintf("%s/nodes/{%s}", relPath, types.URLParamNodeName),
  313. },
  314. Scopes: []types.PermissionScope{
  315. types.UserScope,
  316. types.ProjectScope,
  317. types.ClusterScope,
  318. },
  319. },
  320. )
  321. getNodeHandler := cluster.NewGetNodeHandler(
  322. config,
  323. factory.GetResultWriter(),
  324. )
  325. routes = append(routes, &Route{
  326. Endpoint: getNodeEndpoint,
  327. Handler: getNodeHandler,
  328. Router: r,
  329. })
  330. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/create -> cluster.NewCreateNamespaceHandler
  331. createNamespaceEndpoint := factory.NewAPIEndpoint(
  332. &types.APIRequestMetadata{
  333. Verb: types.APIVerbCreate,
  334. Method: types.HTTPVerbPost,
  335. Path: &types.Path{
  336. Parent: basePath,
  337. RelativePath: relPath + "/namespaces/create",
  338. },
  339. Scopes: []types.PermissionScope{
  340. types.UserScope,
  341. types.ProjectScope,
  342. types.ClusterScope,
  343. },
  344. },
  345. )
  346. createNamespaceHandler := cluster.NewCreateNamespaceHandler(
  347. config,
  348. factory.GetDecoderValidator(),
  349. factory.GetResultWriter(),
  350. )
  351. routes = append(routes, &Route{
  352. Endpoint: createNamespaceEndpoint,
  353. Handler: createNamespaceHandler,
  354. Router: r,
  355. })
  356. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/delete -> cluster.NewDeleteNamespaceHandler
  357. deleteNamespaceEndpoint := factory.NewAPIEndpoint(
  358. &types.APIRequestMetadata{
  359. Verb: types.APIVerbDelete,
  360. Method: types.HTTPVerbDelete,
  361. Path: &types.Path{
  362. Parent: basePath,
  363. RelativePath: relPath + "/namespaces/delete",
  364. },
  365. Scopes: []types.PermissionScope{
  366. types.UserScope,
  367. types.ProjectScope,
  368. types.ClusterScope,
  369. },
  370. },
  371. )
  372. deleteNamespaceHandler := cluster.NewDeleteNamespaceHandler(
  373. config,
  374. factory.GetDecoderValidator(),
  375. )
  376. routes = append(routes, &Route{
  377. Endpoint: deleteNamespaceEndpoint,
  378. Handler: deleteNamespaceHandler,
  379. Router: r,
  380. })
  381. // GET /api/projects/{project_id}/clusters/{cluster_id}/kubeconfig -> cluster.NewGetTemporaryKubeconfigHandler
  382. getTemporaryKubeconfigEndpoint := factory.NewAPIEndpoint(
  383. &types.APIRequestMetadata{
  384. Verb: types.APIVerbGet,
  385. Method: types.HTTPVerbGet,
  386. Path: &types.Path{
  387. Parent: basePath,
  388. RelativePath: relPath + "/kubeconfig",
  389. },
  390. Scopes: []types.PermissionScope{
  391. types.UserScope,
  392. types.ProjectScope,
  393. types.ClusterScope,
  394. },
  395. },
  396. )
  397. getTemporaryKubeconfigHandler := cluster.NewGetTemporaryKubeconfigHandler(
  398. config,
  399. factory.GetResultWriter(),
  400. )
  401. routes = append(routes, &Route{
  402. Endpoint: getTemporaryKubeconfigEndpoint,
  403. Handler: getTemporaryKubeconfigHandler,
  404. Router: r,
  405. })
  406. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/detect -> cluster.NewDetectPrometheusInstalledHandler
  407. detectPrometheusInstalledEndpoint := factory.NewAPIEndpoint(
  408. &types.APIRequestMetadata{
  409. Verb: types.APIVerbGet,
  410. Method: types.HTTPVerbGet,
  411. Path: &types.Path{
  412. Parent: basePath,
  413. RelativePath: relPath + "/prometheus/detect",
  414. },
  415. Scopes: []types.PermissionScope{
  416. types.UserScope,
  417. types.ProjectScope,
  418. types.ClusterScope,
  419. },
  420. },
  421. )
  422. detectPrometheusInstalledHandler := cluster.NewDetectPrometheusInstalledHandler(config)
  423. routes = append(routes, &Route{
  424. Endpoint: detectPrometheusInstalledEndpoint,
  425. Handler: detectPrometheusInstalledHandler,
  426. Router: r,
  427. })
  428. // GET /api/projects/{project_id}/clusters/{cluster_id}/agent/detect -> cluster.NewDetectAgentInstalledHandler
  429. detectAgentInstalledEndpoint := factory.NewAPIEndpoint(
  430. &types.APIRequestMetadata{
  431. Verb: types.APIVerbGet,
  432. Method: types.HTTPVerbGet,
  433. Path: &types.Path{
  434. Parent: basePath,
  435. RelativePath: relPath + "/agent/detect",
  436. },
  437. Scopes: []types.PermissionScope{
  438. types.UserScope,
  439. types.ProjectScope,
  440. types.ClusterScope,
  441. },
  442. },
  443. )
  444. detectAgentInstalledHandler := cluster.NewDetectAgentInstalledHandler(config)
  445. routes = append(routes, &Route{
  446. Endpoint: detectAgentInstalledEndpoint,
  447. Handler: detectAgentInstalledHandler,
  448. Router: r,
  449. })
  450. // POST /api/projects/{project_id}/clusters/{cluster_id}/agent/install -> cluster.NewInstallAgentHandler
  451. installAgentEndpoint := factory.NewAPIEndpoint(
  452. &types.APIRequestMetadata{
  453. Verb: types.APIVerbCreate,
  454. Method: types.HTTPVerbPost,
  455. Path: &types.Path{
  456. Parent: basePath,
  457. RelativePath: relPath + "/agent/install",
  458. },
  459. Scopes: []types.PermissionScope{
  460. types.UserScope,
  461. types.ProjectScope,
  462. types.ClusterScope,
  463. },
  464. },
  465. )
  466. installAgentHandler := cluster.NewInstallAgentHandler(
  467. config,
  468. factory.GetDecoderValidator(),
  469. factory.GetResultWriter(),
  470. )
  471. routes = append(routes, &Route{
  472. Endpoint: installAgentEndpoint,
  473. Handler: installAgentHandler,
  474. Router: r,
  475. })
  476. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewGetKubeEventHandler
  477. listKubeEventsEndpoint := factory.NewAPIEndpoint(
  478. &types.APIRequestMetadata{
  479. Verb: types.APIVerbGet,
  480. Method: types.HTTPVerbGet,
  481. Path: &types.Path{
  482. Parent: basePath,
  483. RelativePath: relPath + "/kube_events",
  484. },
  485. Scopes: []types.PermissionScope{
  486. types.UserScope,
  487. types.ProjectScope,
  488. types.ClusterScope,
  489. },
  490. },
  491. )
  492. listKubeEventsHandler := kube_events.NewListKubeEventsHandler(
  493. config,
  494. factory.GetDecoderValidator(),
  495. factory.GetResultWriter(),
  496. )
  497. routes = append(routes, &Route{
  498. Endpoint: listKubeEventsEndpoint,
  499. Handler: listKubeEventsHandler,
  500. Router: r,
  501. })
  502. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewGetKubeEventHandler
  503. getKubeEventEndpoint := factory.NewAPIEndpoint(
  504. &types.APIRequestMetadata{
  505. Verb: types.APIVerbGet,
  506. Method: types.HTTPVerbGet,
  507. Path: &types.Path{
  508. Parent: basePath,
  509. RelativePath: fmt.Sprintf("%s/kube_events/{%s}", relPath, types.URLParamKubeEventID),
  510. },
  511. Scopes: []types.PermissionScope{
  512. types.UserScope,
  513. types.ProjectScope,
  514. types.ClusterScope,
  515. },
  516. },
  517. )
  518. getKubeEventHandler := kube_events.NewGetKubeEventHandler(
  519. config,
  520. factory.GetDecoderValidator(),
  521. factory.GetResultWriter(),
  522. )
  523. routes = append(routes, &Route{
  524. Endpoint: getKubeEventEndpoint,
  525. Handler: getKubeEventHandler,
  526. Router: r,
  527. })
  528. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events/{kube_event_id}/logs -> kube_events.NewGetKubeEventLogsHandler
  529. getKubeEventLogsEndpoint := factory.NewAPIEndpoint(
  530. &types.APIRequestMetadata{
  531. Verb: types.APIVerbGet,
  532. Method: types.HTTPVerbGet,
  533. Path: &types.Path{
  534. Parent: basePath,
  535. RelativePath: fmt.Sprintf("%s/kube_events/{%s}/logs", relPath, types.URLParamKubeEventID),
  536. },
  537. Scopes: []types.PermissionScope{
  538. types.UserScope,
  539. types.ProjectScope,
  540. types.ClusterScope,
  541. },
  542. },
  543. )
  544. getKubeEventLogsHandler := kube_events.NewGetKubeEventLogsHandler(
  545. config,
  546. factory.GetDecoderValidator(),
  547. factory.GetResultWriter(),
  548. )
  549. routes = append(routes, &Route{
  550. Endpoint: getKubeEventLogsEndpoint,
  551. Handler: getKubeEventLogsHandler,
  552. Router: r,
  553. })
  554. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events/{kube_event_id}/log_buckets -> kube_events.NewGetKubeEventLogBucketsHandler
  555. getKubeEventLogBucketsEndpoint := factory.NewAPIEndpoint(
  556. &types.APIRequestMetadata{
  557. Verb: types.APIVerbGet,
  558. Method: types.HTTPVerbGet,
  559. Path: &types.Path{
  560. Parent: basePath,
  561. RelativePath: fmt.Sprintf("%s/kube_events/{%s}/log_buckets", relPath, types.URLParamKubeEventID),
  562. },
  563. Scopes: []types.PermissionScope{
  564. types.UserScope,
  565. types.ProjectScope,
  566. types.ClusterScope,
  567. },
  568. },
  569. )
  570. getKubeEventLogBucketsHandler := kube_events.NewGetKubeEventLogBucketsHandler(
  571. config,
  572. factory.GetDecoderValidator(),
  573. factory.GetResultWriter(),
  574. )
  575. routes = append(routes, &Route{
  576. Endpoint: getKubeEventLogBucketsEndpoint,
  577. Handler: getKubeEventLogBucketsHandler,
  578. Router: r,
  579. })
  580. // POST /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewCreateKubeEventHandler
  581. createKubeEventsEndpoint := factory.NewAPIEndpoint(
  582. &types.APIRequestMetadata{
  583. Verb: types.APIVerbCreate,
  584. Method: types.HTTPVerbPost,
  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. createKubeEventsHandler := kube_events.NewCreateKubeEventHandler(
  597. config,
  598. factory.GetDecoderValidator(),
  599. factory.GetResultWriter(),
  600. )
  601. routes = append(routes, &Route{
  602. Endpoint: createKubeEventsEndpoint,
  603. Handler: createKubeEventsHandler,
  604. Router: r,
  605. })
  606. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/ingresses -> cluster.NewListNGINXIngressesHandler
  607. listNGINXIngressesEndpoint := factory.NewAPIEndpoint(
  608. &types.APIRequestMetadata{
  609. Verb: types.APIVerbGet,
  610. Method: types.HTTPVerbGet,
  611. Path: &types.Path{
  612. Parent: basePath,
  613. RelativePath: relPath + "/prometheus/ingresses",
  614. },
  615. Scopes: []types.PermissionScope{
  616. types.UserScope,
  617. types.ProjectScope,
  618. types.ClusterScope,
  619. },
  620. },
  621. )
  622. listNGINXIngressesHandler := cluster.NewListNGINXIngressesHandler(
  623. config,
  624. factory.GetResultWriter(),
  625. )
  626. routes = append(routes, &Route{
  627. Endpoint: listNGINXIngressesEndpoint,
  628. Handler: listNGINXIngressesHandler,
  629. Router: r,
  630. })
  631. // GET /api/projects/{project_id}/clusters/{cluster_id}/metrics -> cluster.NewGetPodMetricsHandler
  632. getPodMetricsEndpoint := factory.NewAPIEndpoint(
  633. &types.APIRequestMetadata{
  634. Verb: types.APIVerbGet,
  635. Method: types.HTTPVerbGet,
  636. Path: &types.Path{
  637. Parent: basePath,
  638. RelativePath: relPath + "/metrics",
  639. },
  640. Scopes: []types.PermissionScope{
  641. types.UserScope,
  642. types.ProjectScope,
  643. types.ClusterScope,
  644. },
  645. },
  646. )
  647. getPodMetricsHandler := cluster.NewGetPodMetricsHandler(
  648. config,
  649. factory.GetDecoderValidator(),
  650. factory.GetResultWriter(),
  651. )
  652. routes = append(routes, &Route{
  653. Endpoint: getPodMetricsEndpoint,
  654. Handler: getPodMetricsHandler,
  655. Router: r,
  656. })
  657. // GET /api/projects/{project_id}/clusters/{cluster_id}/helm_release -> cluster.NewStreamHelmReleaseHandler
  658. streamHelmReleaseEndpoint := factory.NewAPIEndpoint(
  659. &types.APIRequestMetadata{
  660. Verb: types.APIVerbGet,
  661. Method: types.HTTPVerbGet,
  662. Path: &types.Path{
  663. Parent: basePath,
  664. RelativePath: relPath + "/helm_release",
  665. },
  666. Scopes: []types.PermissionScope{
  667. types.UserScope,
  668. types.ProjectScope,
  669. types.ClusterScope,
  670. },
  671. IsWebsocket: true,
  672. },
  673. )
  674. streamHelmReleaseHandler := cluster.NewStreamHelmReleaseHandler(
  675. config,
  676. factory.GetDecoderValidator(),
  677. factory.GetResultWriter(),
  678. )
  679. routes = append(routes, &Route{
  680. Endpoint: streamHelmReleaseEndpoint,
  681. Handler: streamHelmReleaseHandler,
  682. Router: r,
  683. })
  684. // GET /api/projects/{project_id}/clusters/{cluster_id}/{kind}/status -> cluster.NewStreamStatusHandler
  685. streamStatusEndpoint := factory.NewAPIEndpoint(
  686. &types.APIRequestMetadata{
  687. Verb: types.APIVerbGet,
  688. Method: types.HTTPVerbGet,
  689. Path: &types.Path{
  690. Parent: basePath,
  691. RelativePath: fmt.Sprintf(
  692. "%s/{%s}/status",
  693. relPath,
  694. types.URLParamKind,
  695. ),
  696. },
  697. Scopes: []types.PermissionScope{
  698. types.UserScope,
  699. types.ProjectScope,
  700. types.ClusterScope,
  701. },
  702. IsWebsocket: true,
  703. },
  704. )
  705. streamStatusHandler := cluster.NewStreamStatusHandler(
  706. config,
  707. factory.GetDecoderValidator(),
  708. factory.GetResultWriter(),
  709. )
  710. routes = append(routes, &Route{
  711. Endpoint: streamStatusEndpoint,
  712. Handler: streamStatusHandler,
  713. Router: r,
  714. })
  715. // GET /api/projects/{project_id}/clusters/{cluster_id}/pods -> cluster.NewGetPodsHandler
  716. getPodsEndpoint := factory.NewAPIEndpoint(
  717. &types.APIRequestMetadata{
  718. Verb: types.APIVerbGet,
  719. Method: types.HTTPVerbGet,
  720. Path: &types.Path{
  721. Parent: basePath,
  722. RelativePath: relPath + "/pods",
  723. },
  724. Scopes: []types.PermissionScope{
  725. types.UserScope,
  726. types.ProjectScope,
  727. types.ClusterScope,
  728. },
  729. },
  730. )
  731. getPodsHandler := cluster.NewGetPodsHandler(
  732. config,
  733. factory.GetDecoderValidator(),
  734. factory.GetResultWriter(),
  735. )
  736. routes = append(routes, &Route{
  737. Endpoint: getPodsEndpoint,
  738. Handler: getPodsHandler,
  739. Router: r,
  740. })
  741. return routes, newPath
  742. }