cluster.go 28 KB

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