cluster.go 27 KB

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