cluster.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  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}/deployments -> environment.NewListDeploymentsByClusterHandler
  256. listDeploymentsEndpoint := factory.NewAPIEndpoint(
  257. &types.APIRequestMetadata{
  258. Verb: types.APIVerbGet,
  259. Method: types.HTTPVerbGet,
  260. Path: &types.Path{
  261. Parent: basePath,
  262. RelativePath: relPath + "/deployments",
  263. },
  264. Scopes: []types.PermissionScope{
  265. types.UserScope,
  266. types.ProjectScope,
  267. types.ClusterScope,
  268. },
  269. },
  270. )
  271. listDeploymentsHandler := environment.NewListDeploymentsByClusterHandler(
  272. config,
  273. factory.GetDecoderValidator(),
  274. factory.GetResultWriter(),
  275. )
  276. routes = append(routes, &Route{
  277. Endpoint: listDeploymentsEndpoint,
  278. Handler: listDeploymentsHandler,
  279. Router: r,
  280. })
  281. // GET /api/projects/{project_id}/clusters/{cluster_id}/{environment_id}/deployment -> environment.NewGetDeploymentByClusterHandler
  282. getDeploymentEndpoint := factory.NewAPIEndpoint(
  283. &types.APIRequestMetadata{
  284. Verb: types.APIVerbGet,
  285. Method: types.HTTPVerbGet,
  286. Path: &types.Path{
  287. Parent: basePath,
  288. RelativePath: relPath + "/{environment_id}/deployment",
  289. },
  290. Scopes: []types.PermissionScope{
  291. types.UserScope,
  292. types.ProjectScope,
  293. types.ClusterScope,
  294. },
  295. },
  296. )
  297. getDeploymentHandler := environment.NewGetDeploymentByClusterHandler(
  298. config,
  299. factory.GetDecoderValidator(),
  300. factory.GetResultWriter(),
  301. )
  302. routes = append(routes, &Route{
  303. Endpoint: getDeploymentEndpoint,
  304. Handler: getDeploymentHandler,
  305. Router: r,
  306. })
  307. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces -> cluster.NewClusterListNamespacesHandler
  308. listNamespacesEndpoint := factory.NewAPIEndpoint(
  309. &types.APIRequestMetadata{
  310. Verb: types.APIVerbGet,
  311. Method: types.HTTPVerbGet,
  312. Path: &types.Path{
  313. Parent: basePath,
  314. RelativePath: relPath + "/namespaces",
  315. },
  316. Scopes: []types.PermissionScope{
  317. types.UserScope,
  318. types.ProjectScope,
  319. types.ClusterScope,
  320. },
  321. },
  322. )
  323. listNamespacesHandler := cluster.NewListNamespacesHandler(
  324. config,
  325. factory.GetResultWriter(),
  326. )
  327. routes = append(routes, &Route{
  328. Endpoint: listNamespacesEndpoint,
  329. Handler: listNamespacesHandler,
  330. Router: r,
  331. })
  332. // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes -> cluster.NewListNodesHandler
  333. listNodesEndpoint := factory.NewAPIEndpoint(
  334. &types.APIRequestMetadata{
  335. Verb: types.APIVerbGet,
  336. Method: types.HTTPVerbGet,
  337. Path: &types.Path{
  338. Parent: basePath,
  339. RelativePath: relPath + "/nodes",
  340. },
  341. Scopes: []types.PermissionScope{
  342. types.UserScope,
  343. types.ProjectScope,
  344. types.ClusterScope,
  345. },
  346. },
  347. )
  348. listNodesHandler := cluster.NewListNodesHandler(
  349. config,
  350. factory.GetResultWriter(),
  351. )
  352. routes = append(routes, &Route{
  353. Endpoint: listNodesEndpoint,
  354. Handler: listNodesHandler,
  355. Router: r,
  356. })
  357. // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes/{node_name} -> cluster.NewGetNodeHandler
  358. getNodeEndpoint := factory.NewAPIEndpoint(
  359. &types.APIRequestMetadata{
  360. Verb: types.APIVerbGet,
  361. Method: types.HTTPVerbGet,
  362. Path: &types.Path{
  363. Parent: basePath,
  364. RelativePath: fmt.Sprintf("%s/nodes/{%s}", relPath, types.URLParamNodeName),
  365. },
  366. Scopes: []types.PermissionScope{
  367. types.UserScope,
  368. types.ProjectScope,
  369. types.ClusterScope,
  370. },
  371. },
  372. )
  373. getNodeHandler := cluster.NewGetNodeHandler(
  374. config,
  375. factory.GetResultWriter(),
  376. )
  377. routes = append(routes, &Route{
  378. Endpoint: getNodeEndpoint,
  379. Handler: getNodeHandler,
  380. Router: r,
  381. })
  382. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/create -> cluster.NewCreateNamespaceHandler
  383. createNamespaceEndpoint := factory.NewAPIEndpoint(
  384. &types.APIRequestMetadata{
  385. Verb: types.APIVerbCreate,
  386. Method: types.HTTPVerbPost,
  387. Path: &types.Path{
  388. Parent: basePath,
  389. RelativePath: relPath + "/namespaces/create",
  390. },
  391. Scopes: []types.PermissionScope{
  392. types.UserScope,
  393. types.ProjectScope,
  394. types.ClusterScope,
  395. },
  396. },
  397. )
  398. createNamespaceHandler := cluster.NewCreateNamespaceHandler(
  399. config,
  400. factory.GetDecoderValidator(),
  401. factory.GetResultWriter(),
  402. )
  403. routes = append(routes, &Route{
  404. Endpoint: createNamespaceEndpoint,
  405. Handler: createNamespaceHandler,
  406. Router: r,
  407. })
  408. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/delete -> cluster.NewDeleteNamespaceHandler
  409. deleteNamespaceEndpoint := factory.NewAPIEndpoint(
  410. &types.APIRequestMetadata{
  411. Verb: types.APIVerbDelete,
  412. Method: types.HTTPVerbDelete,
  413. Path: &types.Path{
  414. Parent: basePath,
  415. RelativePath: relPath + "/namespaces/delete",
  416. },
  417. Scopes: []types.PermissionScope{
  418. types.UserScope,
  419. types.ProjectScope,
  420. types.ClusterScope,
  421. },
  422. },
  423. )
  424. deleteNamespaceHandler := cluster.NewDeleteNamespaceHandler(
  425. config,
  426. factory.GetDecoderValidator(),
  427. )
  428. routes = append(routes, &Route{
  429. Endpoint: deleteNamespaceEndpoint,
  430. Handler: deleteNamespaceHandler,
  431. Router: r,
  432. })
  433. // GET /api/projects/{project_id}/clusters/{cluster_id}/kubeconfig -> cluster.NewGetTemporaryKubeconfigHandler
  434. getTemporaryKubeconfigEndpoint := factory.NewAPIEndpoint(
  435. &types.APIRequestMetadata{
  436. Verb: types.APIVerbGet,
  437. Method: types.HTTPVerbGet,
  438. Path: &types.Path{
  439. Parent: basePath,
  440. RelativePath: relPath + "/kubeconfig",
  441. },
  442. Scopes: []types.PermissionScope{
  443. types.UserScope,
  444. types.ProjectScope,
  445. types.ClusterScope,
  446. },
  447. },
  448. )
  449. getTemporaryKubeconfigHandler := cluster.NewGetTemporaryKubeconfigHandler(
  450. config,
  451. factory.GetResultWriter(),
  452. )
  453. routes = append(routes, &Route{
  454. Endpoint: getTemporaryKubeconfigEndpoint,
  455. Handler: getTemporaryKubeconfigHandler,
  456. Router: r,
  457. })
  458. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/detect -> cluster.NewDetectPrometheusInstalledHandler
  459. detectPrometheusInstalledEndpoint := factory.NewAPIEndpoint(
  460. &types.APIRequestMetadata{
  461. Verb: types.APIVerbGet,
  462. Method: types.HTTPVerbGet,
  463. Path: &types.Path{
  464. Parent: basePath,
  465. RelativePath: relPath + "/prometheus/detect",
  466. },
  467. Scopes: []types.PermissionScope{
  468. types.UserScope,
  469. types.ProjectScope,
  470. types.ClusterScope,
  471. },
  472. },
  473. )
  474. detectPrometheusInstalledHandler := cluster.NewDetectPrometheusInstalledHandler(config)
  475. routes = append(routes, &Route{
  476. Endpoint: detectPrometheusInstalledEndpoint,
  477. Handler: detectPrometheusInstalledHandler,
  478. Router: r,
  479. })
  480. // GET /api/projects/{project_id}/clusters/{cluster_id}/agent/detect -> cluster.NewDetectAgentInstalledHandler
  481. detectAgentInstalledEndpoint := factory.NewAPIEndpoint(
  482. &types.APIRequestMetadata{
  483. Verb: types.APIVerbGet,
  484. Method: types.HTTPVerbGet,
  485. Path: &types.Path{
  486. Parent: basePath,
  487. RelativePath: relPath + "/agent/detect",
  488. },
  489. Scopes: []types.PermissionScope{
  490. types.UserScope,
  491. types.ProjectScope,
  492. types.ClusterScope,
  493. },
  494. },
  495. )
  496. detectAgentInstalledHandler := cluster.NewDetectAgentInstalledHandler(config)
  497. routes = append(routes, &Route{
  498. Endpoint: detectAgentInstalledEndpoint,
  499. Handler: detectAgentInstalledHandler,
  500. Router: r,
  501. })
  502. // POST /api/projects/{project_id}/clusters/{cluster_id}/agent/install -> cluster.NewInstallAgentHandler
  503. installAgentEndpoint := factory.NewAPIEndpoint(
  504. &types.APIRequestMetadata{
  505. Verb: types.APIVerbCreate,
  506. Method: types.HTTPVerbPost,
  507. Path: &types.Path{
  508. Parent: basePath,
  509. RelativePath: relPath + "/agent/install",
  510. },
  511. Scopes: []types.PermissionScope{
  512. types.UserScope,
  513. types.ProjectScope,
  514. types.ClusterScope,
  515. },
  516. },
  517. )
  518. installAgentHandler := cluster.NewInstallAgentHandler(
  519. config,
  520. factory.GetDecoderValidator(),
  521. factory.GetResultWriter(),
  522. )
  523. routes = append(routes, &Route{
  524. Endpoint: installAgentEndpoint,
  525. Handler: installAgentHandler,
  526. Router: r,
  527. })
  528. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewGetKubeEventHandler
  529. listKubeEventsEndpoint := factory.NewAPIEndpoint(
  530. &types.APIRequestMetadata{
  531. Verb: types.APIVerbGet,
  532. Method: types.HTTPVerbGet,
  533. Path: &types.Path{
  534. Parent: basePath,
  535. RelativePath: relPath + "/kube_events",
  536. },
  537. Scopes: []types.PermissionScope{
  538. types.UserScope,
  539. types.ProjectScope,
  540. types.ClusterScope,
  541. },
  542. },
  543. )
  544. listKubeEventsHandler := kube_events.NewListKubeEventsHandler(
  545. config,
  546. factory.GetDecoderValidator(),
  547. factory.GetResultWriter(),
  548. )
  549. routes = append(routes, &Route{
  550. Endpoint: listKubeEventsEndpoint,
  551. Handler: listKubeEventsHandler,
  552. Router: r,
  553. })
  554. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewGetKubeEventHandler
  555. getKubeEventEndpoint := 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}", relPath, types.URLParamKubeEventID),
  562. },
  563. Scopes: []types.PermissionScope{
  564. types.UserScope,
  565. types.ProjectScope,
  566. types.ClusterScope,
  567. },
  568. },
  569. )
  570. getKubeEventHandler := kube_events.NewGetKubeEventHandler(
  571. config,
  572. factory.GetDecoderValidator(),
  573. factory.GetResultWriter(),
  574. )
  575. routes = append(routes, &Route{
  576. Endpoint: getKubeEventEndpoint,
  577. Handler: getKubeEventHandler,
  578. Router: r,
  579. })
  580. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events/{kube_event_id}/logs -> kube_events.NewGetKubeEventLogsHandler
  581. getKubeEventLogsEndpoint := 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}/logs", relPath, types.URLParamKubeEventID),
  588. },
  589. Scopes: []types.PermissionScope{
  590. types.UserScope,
  591. types.ProjectScope,
  592. types.ClusterScope,
  593. },
  594. },
  595. )
  596. getKubeEventLogsHandler := kube_events.NewGetKubeEventLogsHandler(
  597. config,
  598. factory.GetDecoderValidator(),
  599. factory.GetResultWriter(),
  600. )
  601. routes = append(routes, &Route{
  602. Endpoint: getKubeEventLogsEndpoint,
  603. Handler: getKubeEventLogsHandler,
  604. Router: r,
  605. })
  606. // GET /api/projects/{project_id}/clusters/{cluster_id}/kube_events/{kube_event_id}/log_buckets -> kube_events.NewGetKubeEventLogBucketsHandler
  607. getKubeEventLogBucketsEndpoint := 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}/log_buckets", relPath, types.URLParamKubeEventID),
  614. },
  615. Scopes: []types.PermissionScope{
  616. types.UserScope,
  617. types.ProjectScope,
  618. types.ClusterScope,
  619. },
  620. },
  621. )
  622. getKubeEventLogBucketsHandler := kube_events.NewGetKubeEventLogBucketsHandler(
  623. config,
  624. factory.GetDecoderValidator(),
  625. factory.GetResultWriter(),
  626. )
  627. routes = append(routes, &Route{
  628. Endpoint: getKubeEventLogBucketsEndpoint,
  629. Handler: getKubeEventLogBucketsHandler,
  630. Router: r,
  631. })
  632. // POST /api/projects/{project_id}/clusters/{cluster_id}/kube_events -> kube_events.NewCreateKubeEventHandler
  633. createKubeEventsEndpoint := factory.NewAPIEndpoint(
  634. &types.APIRequestMetadata{
  635. Verb: types.APIVerbCreate,
  636. Method: types.HTTPVerbPost,
  637. Path: &types.Path{
  638. Parent: basePath,
  639. RelativePath: relPath + "/kube_events",
  640. },
  641. Scopes: []types.PermissionScope{
  642. types.UserScope,
  643. types.ProjectScope,
  644. types.ClusterScope,
  645. },
  646. },
  647. )
  648. createKubeEventsHandler := kube_events.NewCreateKubeEventHandler(
  649. config,
  650. factory.GetDecoderValidator(),
  651. factory.GetResultWriter(),
  652. )
  653. routes = append(routes, &Route{
  654. Endpoint: createKubeEventsEndpoint,
  655. Handler: createKubeEventsHandler,
  656. Router: r,
  657. })
  658. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/ingresses -> cluster.NewListNGINXIngressesHandler
  659. listNGINXIngressesEndpoint := factory.NewAPIEndpoint(
  660. &types.APIRequestMetadata{
  661. Verb: types.APIVerbGet,
  662. Method: types.HTTPVerbGet,
  663. Path: &types.Path{
  664. Parent: basePath,
  665. RelativePath: relPath + "/prometheus/ingresses",
  666. },
  667. Scopes: []types.PermissionScope{
  668. types.UserScope,
  669. types.ProjectScope,
  670. types.ClusterScope,
  671. },
  672. },
  673. )
  674. listNGINXIngressesHandler := cluster.NewListNGINXIngressesHandler(
  675. config,
  676. factory.GetResultWriter(),
  677. )
  678. routes = append(routes, &Route{
  679. Endpoint: listNGINXIngressesEndpoint,
  680. Handler: listNGINXIngressesHandler,
  681. Router: r,
  682. })
  683. // GET /api/projects/{project_id}/clusters/{cluster_id}/metrics -> cluster.NewGetPodMetricsHandler
  684. getPodMetricsEndpoint := factory.NewAPIEndpoint(
  685. &types.APIRequestMetadata{
  686. Verb: types.APIVerbGet,
  687. Method: types.HTTPVerbGet,
  688. Path: &types.Path{
  689. Parent: basePath,
  690. RelativePath: relPath + "/metrics",
  691. },
  692. Scopes: []types.PermissionScope{
  693. types.UserScope,
  694. types.ProjectScope,
  695. types.ClusterScope,
  696. },
  697. },
  698. )
  699. getPodMetricsHandler := cluster.NewGetPodMetricsHandler(
  700. config,
  701. factory.GetDecoderValidator(),
  702. factory.GetResultWriter(),
  703. )
  704. routes = append(routes, &Route{
  705. Endpoint: getPodMetricsEndpoint,
  706. Handler: getPodMetricsHandler,
  707. Router: r,
  708. })
  709. // GET /api/projects/{project_id}/clusters/{cluster_id}/helm_release -> cluster.NewStreamHelmReleaseHandler
  710. streamHelmReleaseEndpoint := factory.NewAPIEndpoint(
  711. &types.APIRequestMetadata{
  712. Verb: types.APIVerbGet,
  713. Method: types.HTTPVerbGet,
  714. Path: &types.Path{
  715. Parent: basePath,
  716. RelativePath: relPath + "/helm_release",
  717. },
  718. Scopes: []types.PermissionScope{
  719. types.UserScope,
  720. types.ProjectScope,
  721. types.ClusterScope,
  722. },
  723. IsWebsocket: true,
  724. },
  725. )
  726. streamHelmReleaseHandler := cluster.NewStreamHelmReleaseHandler(
  727. config,
  728. factory.GetDecoderValidator(),
  729. factory.GetResultWriter(),
  730. )
  731. routes = append(routes, &Route{
  732. Endpoint: streamHelmReleaseEndpoint,
  733. Handler: streamHelmReleaseHandler,
  734. Router: r,
  735. })
  736. // GET /api/projects/{project_id}/clusters/{cluster_id}/{kind}/status -> cluster.NewStreamStatusHandler
  737. streamStatusEndpoint := factory.NewAPIEndpoint(
  738. &types.APIRequestMetadata{
  739. Verb: types.APIVerbGet,
  740. Method: types.HTTPVerbGet,
  741. Path: &types.Path{
  742. Parent: basePath,
  743. RelativePath: fmt.Sprintf(
  744. "%s/{%s}/status",
  745. relPath,
  746. types.URLParamKind,
  747. ),
  748. },
  749. Scopes: []types.PermissionScope{
  750. types.UserScope,
  751. types.ProjectScope,
  752. types.ClusterScope,
  753. },
  754. IsWebsocket: true,
  755. },
  756. )
  757. streamStatusHandler := cluster.NewStreamStatusHandler(
  758. config,
  759. factory.GetDecoderValidator(),
  760. factory.GetResultWriter(),
  761. )
  762. routes = append(routes, &Route{
  763. Endpoint: streamStatusEndpoint,
  764. Handler: streamStatusHandler,
  765. Router: r,
  766. })
  767. // GET /api/projects/{project_id}/clusters/{cluster_id}/pods -> cluster.NewGetPodsHandler
  768. getPodsEndpoint := factory.NewAPIEndpoint(
  769. &types.APIRequestMetadata{
  770. Verb: types.APIVerbGet,
  771. Method: types.HTTPVerbGet,
  772. Path: &types.Path{
  773. Parent: basePath,
  774. RelativePath: relPath + "/pods",
  775. },
  776. Scopes: []types.PermissionScope{
  777. types.UserScope,
  778. types.ProjectScope,
  779. types.ClusterScope,
  780. },
  781. },
  782. )
  783. getPodsHandler := cluster.NewGetPodsHandler(
  784. config,
  785. factory.GetDecoderValidator(),
  786. factory.GetResultWriter(),
  787. )
  788. routes = append(routes, &Route{
  789. Endpoint: getPodsEndpoint,
  790. Handler: getPodsHandler,
  791. Router: r,
  792. })
  793. return routes, newPath
  794. }