cluster.go 20 KB

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