2
0

cluster.go 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  1. package router
  2. import (
  3. "fmt"
  4. "github.com/go-chi/chi/v5"
  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/datastore"
  8. "github.com/porter-dev/porter/api/server/handlers/environment"
  9. "github.com/porter-dev/porter/api/server/handlers/environment_groups"
  10. systemstatus "github.com/porter-dev/porter/api/server/handlers/system_status"
  11. "github.com/porter-dev/porter/api/server/shared"
  12. "github.com/porter-dev/porter/api/server/shared/config"
  13. "github.com/porter-dev/porter/api/server/shared/router"
  14. "github.com/porter-dev/porter/api/types"
  15. )
  16. func NewClusterScopedRegisterer(children ...*router.Registerer) *router.Registerer {
  17. return &router.Registerer{
  18. GetRoutes: GetClusterScopedRoutes,
  19. Children: children,
  20. }
  21. }
  22. func GetClusterScopedRoutes(
  23. r chi.Router,
  24. config *config.Config,
  25. basePath *types.Path,
  26. factory shared.APIEndpointFactory,
  27. children ...*router.Registerer,
  28. ) []*router.Route {
  29. routes, projPath := getClusterRoutes(r, config, basePath, factory)
  30. if len(children) > 0 {
  31. r.Route(projPath.RelativePath, func(r chi.Router) {
  32. for _, child := range children {
  33. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  34. routes = append(routes, childRoutes...)
  35. }
  36. })
  37. }
  38. return routes
  39. }
  40. func getClusterRoutes(
  41. r chi.Router,
  42. config *config.Config,
  43. basePath *types.Path,
  44. factory shared.APIEndpointFactory,
  45. ) ([]*router.Route, *types.Path) {
  46. relPath := "/clusters/{cluster_id}"
  47. newPath := &types.Path{
  48. Parent: basePath,
  49. RelativePath: relPath,
  50. }
  51. routes := make([]*router.Route, 0)
  52. // POST /api/projects/{project_id}/clusters -> project.NewCreateClusterManualHandler
  53. createEndpoint := factory.NewAPIEndpoint(
  54. &types.APIRequestMetadata{
  55. Verb: types.APIVerbCreate,
  56. Method: types.HTTPVerbPost,
  57. Path: &types.Path{
  58. Parent: basePath,
  59. RelativePath: "/clusters",
  60. },
  61. Scopes: []types.PermissionScope{
  62. types.UserScope,
  63. types.ProjectScope,
  64. },
  65. },
  66. )
  67. createHandler := cluster.NewCreateClusterManualHandler(
  68. config,
  69. factory.GetDecoderValidator(),
  70. factory.GetResultWriter(),
  71. )
  72. routes = append(routes, &router.Route{
  73. Endpoint: createEndpoint,
  74. Handler: createHandler,
  75. Router: r,
  76. })
  77. // POST /api/projects/{project_id}/clusters/candidates -> project.NewCreateClusterCandidateHandler
  78. createCandidateEndpoint := factory.NewAPIEndpoint(
  79. &types.APIRequestMetadata{
  80. Verb: types.APIVerbCreate,
  81. Method: types.HTTPVerbPost,
  82. Path: &types.Path{
  83. Parent: basePath,
  84. RelativePath: "/clusters/candidates",
  85. },
  86. Scopes: []types.PermissionScope{
  87. types.UserScope,
  88. types.ProjectScope,
  89. },
  90. CheckUsage: true,
  91. UsageMetric: types.Clusters,
  92. },
  93. )
  94. createCandidateHandler := cluster.NewCreateClusterCandidateHandler(
  95. config,
  96. factory.GetDecoderValidator(),
  97. factory.GetResultWriter(),
  98. )
  99. routes = append(routes, &router.Route{
  100. Endpoint: createCandidateEndpoint,
  101. Handler: createCandidateHandler,
  102. Router: r,
  103. })
  104. // GET /api/projects/{project_id}/clusters/candidates -> project.NewListClusterCandidatesHandler
  105. listCandidatesEndpoint := factory.NewAPIEndpoint(
  106. &types.APIRequestMetadata{
  107. Verb: types.APIVerbList,
  108. Method: types.HTTPVerbGet,
  109. Path: &types.Path{
  110. Parent: basePath,
  111. RelativePath: "/clusters/candidates",
  112. },
  113. Scopes: []types.PermissionScope{
  114. types.UserScope,
  115. types.ProjectScope,
  116. },
  117. },
  118. )
  119. listCandidatesHandler := cluster.NewListClusterCandidatesHandler(
  120. config,
  121. factory.GetResultWriter(),
  122. )
  123. routes = append(routes, &router.Route{
  124. Endpoint: listCandidatesEndpoint,
  125. Handler: listCandidatesHandler,
  126. Router: r,
  127. })
  128. // POST /api/projects/{project_id}/clusters/candidates/{candidate_id}/resolve -> project.NewResolveClusterCandidateHandler
  129. resolveCandidateEndpoint := factory.NewAPIEndpoint(
  130. &types.APIRequestMetadata{
  131. Verb: types.APIVerbCreate,
  132. Method: types.HTTPVerbPost,
  133. Path: &types.Path{
  134. Parent: basePath,
  135. RelativePath: fmt.Sprintf(
  136. "/clusters/candidates/{%s}/resolve",
  137. types.URLParamCandidateID,
  138. ),
  139. },
  140. Scopes: []types.PermissionScope{
  141. types.UserScope,
  142. types.ProjectScope,
  143. },
  144. CheckUsage: true,
  145. UsageMetric: types.Clusters,
  146. },
  147. )
  148. resolveCandidateHandler := cluster.NewResolveClusterCandidateHandler(
  149. config,
  150. factory.GetDecoderValidator(),
  151. factory.GetResultWriter(),
  152. )
  153. routes = append(routes, &router.Route{
  154. Endpoint: resolveCandidateEndpoint,
  155. Handler: resolveCandidateHandler,
  156. Router: r,
  157. })
  158. // POST /api/projects/{project_id}/clusters/{cluster_id} -> project.NewClusterUpdateHandler
  159. updateClusterEndpoint := factory.NewAPIEndpoint(
  160. &types.APIRequestMetadata{
  161. Verb: types.APIVerbUpdate,
  162. Method: types.HTTPVerbPost,
  163. Path: &types.Path{
  164. Parent: basePath,
  165. RelativePath: relPath,
  166. },
  167. Scopes: []types.PermissionScope{
  168. types.UserScope,
  169. types.ProjectScope,
  170. types.ClusterScope,
  171. },
  172. },
  173. )
  174. updateClusterHandler := cluster.NewClusterUpdateHandler(
  175. config,
  176. factory.GetDecoderValidator(),
  177. factory.GetResultWriter(),
  178. )
  179. routes = append(routes, &router.Route{
  180. Endpoint: updateClusterEndpoint,
  181. Handler: updateClusterHandler,
  182. Router: r,
  183. })
  184. // DELETE /api/projects/{project_id}/clusters/{cluster_id} -> project.NewClusterDeleteHandler
  185. deleteClusterEndpoint := factory.NewAPIEndpoint(
  186. &types.APIRequestMetadata{
  187. Verb: types.APIVerbDelete,
  188. Method: types.HTTPVerbDelete,
  189. Path: &types.Path{
  190. Parent: basePath,
  191. RelativePath: relPath,
  192. },
  193. Scopes: []types.PermissionScope{
  194. types.UserScope,
  195. types.ProjectScope,
  196. types.ClusterScope,
  197. },
  198. },
  199. )
  200. deleteClusterHandler := cluster.NewClusterDeleteHandler(
  201. config,
  202. factory.GetResultWriter(),
  203. )
  204. routes = append(routes, &router.Route{
  205. Endpoint: deleteClusterEndpoint,
  206. Handler: deleteClusterHandler,
  207. Router: r,
  208. })
  209. // GET /api/projects/{project_id}/clusters/{cluster_id} -> project.NewClusterGetHandler
  210. getEndpoint := factory.NewAPIEndpoint(
  211. &types.APIRequestMetadata{
  212. Verb: types.APIVerbGet,
  213. Method: types.HTTPVerbGet,
  214. Path: &types.Path{
  215. Parent: basePath,
  216. RelativePath: relPath,
  217. },
  218. Scopes: []types.PermissionScope{
  219. types.UserScope,
  220. types.ProjectScope,
  221. types.ClusterScope,
  222. },
  223. },
  224. )
  225. getHandler := cluster.NewClusterGetHandler(
  226. config,
  227. factory.GetResultWriter(),
  228. )
  229. routes = append(routes, &router.Route{
  230. Endpoint: getEndpoint,
  231. Handler: getHandler,
  232. Router: r,
  233. })
  234. // POST /api/projects/{project_id}/clusters/{cluster_id}/rename -> cluster.NewRenameClusterHandler
  235. renameClusterEndpoint := factory.NewAPIEndpoint(
  236. &types.APIRequestMetadata{
  237. Verb: types.APIVerbCreate,
  238. Method: types.HTTPVerbPost,
  239. Path: &types.Path{
  240. Parent: basePath,
  241. RelativePath: relPath + "/rename",
  242. },
  243. Scopes: []types.PermissionScope{
  244. types.UserScope,
  245. types.ProjectScope,
  246. types.ClusterScope,
  247. },
  248. },
  249. )
  250. renameClusterHandler := cluster.NewRenameClusterHandler(
  251. config,
  252. factory.GetDecoderValidator(),
  253. factory.GetResultWriter(),
  254. )
  255. routes = append(routes, &router.Route{
  256. Endpoint: renameClusterEndpoint,
  257. Handler: renameClusterHandler,
  258. Router: r,
  259. })
  260. // GET /api/projects/{project_id}/clusters/{cluster_id}/databases -> database.NewDatabaseListHandler
  261. listDatabaseEndpoint := factory.NewAPIEndpoint(
  262. &types.APIRequestMetadata{
  263. Verb: types.APIVerbList,
  264. Method: types.HTTPVerbGet,
  265. Path: &types.Path{
  266. Parent: basePath,
  267. RelativePath: relPath + "/databases",
  268. },
  269. Scopes: []types.PermissionScope{
  270. types.UserScope,
  271. types.ProjectScope,
  272. types.ClusterScope,
  273. },
  274. },
  275. )
  276. listDatabaseHandler := database.NewDatabaseListHandler(
  277. config,
  278. factory.GetResultWriter(),
  279. )
  280. routes = append(routes, &router.Route{
  281. Endpoint: listDatabaseEndpoint,
  282. Handler: listDatabaseHandler,
  283. Router: r,
  284. })
  285. // GET /api/projects/{project_id}/clusters/{cluster_id}/compliance/checks -> cluster.NewListComplianceChecksHandler
  286. listComplianceChecksEndpoint := factory.NewAPIEndpoint(
  287. &types.APIRequestMetadata{
  288. Verb: types.APIVerbList,
  289. Method: types.HTTPVerbGet,
  290. Path: &types.Path{
  291. Parent: basePath,
  292. RelativePath: relPath + "/compliance/checks",
  293. },
  294. Scopes: []types.PermissionScope{
  295. types.UserScope,
  296. types.ProjectScope,
  297. types.ClusterScope,
  298. },
  299. },
  300. )
  301. listComplianceChecksHandler := cluster.NewListComplianceChecksHandler(
  302. config,
  303. factory.GetDecoderValidator(),
  304. factory.GetResultWriter(),
  305. )
  306. routes = append(routes, &router.Route{
  307. Endpoint: listComplianceChecksEndpoint,
  308. Handler: listComplianceChecksHandler,
  309. Router: r,
  310. })
  311. if config.ServerConf.GithubIncomingWebhookSecret != "" {
  312. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments -> environment.NewListEnvironmentHandler
  313. listEnvEndpoint := factory.NewAPIEndpoint(
  314. &types.APIRequestMetadata{
  315. Verb: types.APIVerbGet,
  316. Method: types.HTTPVerbGet,
  317. Path: &types.Path{
  318. Parent: basePath,
  319. RelativePath: relPath + "/environments",
  320. },
  321. Scopes: []types.PermissionScope{
  322. types.UserScope,
  323. types.ProjectScope,
  324. types.ClusterScope,
  325. types.PreviewEnvironmentScope,
  326. },
  327. },
  328. )
  329. listEnvHandler := environment.NewListEnvironmentHandler(
  330. config,
  331. factory.GetResultWriter(),
  332. )
  333. routes = append(routes, &router.Route{
  334. Endpoint: listEnvEndpoint,
  335. Handler: listEnvHandler,
  336. Router: r,
  337. })
  338. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id} -> environment.NewGetEnvironmentHandler
  339. getEnvEndpoint := factory.NewAPIEndpoint(
  340. &types.APIRequestMetadata{
  341. Verb: types.APIVerbGet,
  342. Method: types.HTTPVerbGet,
  343. Path: &types.Path{
  344. Parent: basePath,
  345. RelativePath: relPath + "/environments/{environment_id}",
  346. },
  347. Scopes: []types.PermissionScope{
  348. types.UserScope,
  349. types.ProjectScope,
  350. types.ClusterScope,
  351. types.PreviewEnvironmentScope,
  352. },
  353. },
  354. )
  355. getEnvHandler := environment.NewGetEnvironmentHandler(
  356. config,
  357. factory.GetResultWriter(),
  358. )
  359. routes = append(routes, &router.Route{
  360. Endpoint: getEnvEndpoint,
  361. Handler: getEnvHandler,
  362. Router: r,
  363. })
  364. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/toggle_new_comment -> environment.NewToggleNewCommentHandler
  365. toggleNewCommentEndpoint := factory.NewAPIEndpoint(
  366. &types.APIRequestMetadata{
  367. Verb: types.APIVerbUpdate,
  368. Method: types.HTTPVerbPatch,
  369. Path: &types.Path{
  370. Parent: basePath,
  371. RelativePath: relPath + "/environments/{environment_id}/toggle_new_comment",
  372. },
  373. Scopes: []types.PermissionScope{
  374. types.UserScope,
  375. types.ProjectScope,
  376. types.ClusterScope,
  377. types.PreviewEnvironmentScope,
  378. },
  379. },
  380. )
  381. toggleNewCommentHandler := environment.NewToggleNewCommentHandler(
  382. config,
  383. factory.GetDecoderValidator(),
  384. factory.GetResultWriter(),
  385. )
  386. routes = append(routes, &router.Route{
  387. Endpoint: toggleNewCommentEndpoint,
  388. Handler: toggleNewCommentHandler,
  389. Router: r,
  390. })
  391. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/validate_porter_yaml -> environment.NewValidatePorterYAMLHandler
  392. validtatePorterYAMLEndpoint := factory.NewAPIEndpoint(
  393. &types.APIRequestMetadata{
  394. Verb: types.APIVerbGet,
  395. Method: types.HTTPVerbGet,
  396. Path: &types.Path{
  397. Parent: basePath,
  398. RelativePath: relPath + "/environments/{environment_id}/validate_porter_yaml",
  399. },
  400. Scopes: []types.PermissionScope{
  401. types.UserScope,
  402. types.ProjectScope,
  403. types.ClusterScope,
  404. types.PreviewEnvironmentScope,
  405. },
  406. },
  407. )
  408. validatePorterYAMLHandler := environment.NewValidatePorterYAMLHandler(
  409. config,
  410. factory.GetDecoderValidator(),
  411. factory.GetResultWriter(),
  412. )
  413. routes = append(routes, &router.Route{
  414. Endpoint: validtatePorterYAMLEndpoint,
  415. Handler: validatePorterYAMLHandler,
  416. Router: r,
  417. })
  418. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments -> environment.NewCreateDeploymentByClusterHandler
  419. createDeploymentEndpoint := factory.NewAPIEndpoint(
  420. &types.APIRequestMetadata{
  421. Verb: types.APIVerbCreate,
  422. Method: types.HTTPVerbPost,
  423. Path: &types.Path{
  424. Parent: basePath,
  425. RelativePath: relPath + "/deployments",
  426. },
  427. Scopes: []types.PermissionScope{
  428. types.UserScope,
  429. types.ProjectScope,
  430. types.ClusterScope,
  431. types.PreviewEnvironmentScope,
  432. },
  433. },
  434. )
  435. createDeploymentHandler := environment.NewCreateDeploymentByClusterHandler(
  436. config,
  437. factory.GetDecoderValidator(),
  438. factory.GetResultWriter(),
  439. )
  440. routes = append(routes, &router.Route{
  441. Endpoint: createDeploymentEndpoint,
  442. Handler: createDeploymentHandler,
  443. Router: r,
  444. })
  445. // GET /api/projects/{project_id}/clusters/{cluster_id}/deployments -> environment.NewListDeploymentsByClusterHandler
  446. listDeploymentsEndpoint := factory.NewAPIEndpoint(
  447. &types.APIRequestMetadata{
  448. Verb: types.APIVerbGet,
  449. Method: types.HTTPVerbGet,
  450. Path: &types.Path{
  451. Parent: basePath,
  452. RelativePath: relPath + "/deployments",
  453. },
  454. Scopes: []types.PermissionScope{
  455. types.UserScope,
  456. types.ProjectScope,
  457. types.ClusterScope,
  458. types.PreviewEnvironmentScope,
  459. },
  460. },
  461. )
  462. listDeploymentsHandler := environment.NewListDeploymentsByClusterHandler(
  463. config,
  464. factory.GetDecoderValidator(),
  465. factory.GetResultWriter(),
  466. )
  467. routes = append(routes, &router.Route{
  468. Endpoint: listDeploymentsEndpoint,
  469. Handler: listDeploymentsHandler,
  470. Router: r,
  471. })
  472. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/deployments -> environment.NewUpdateDeploymentByClusterHandler
  473. updateDeploymentEndpoint := factory.NewAPIEndpoint(
  474. &types.APIRequestMetadata{
  475. Verb: types.APIVerbUpdate,
  476. Method: types.HTTPVerbPatch,
  477. Path: &types.Path{
  478. Parent: basePath,
  479. RelativePath: relPath + "/deployments",
  480. },
  481. Scopes: []types.PermissionScope{
  482. types.UserScope,
  483. types.ProjectScope,
  484. types.ClusterScope,
  485. types.PreviewEnvironmentScope,
  486. },
  487. },
  488. )
  489. updateDeploymentHandler := environment.NewUpdateDeploymentByClusterHandler(
  490. config,
  491. factory.GetDecoderValidator(),
  492. factory.GetResultWriter(),
  493. )
  494. routes = append(routes, &router.Route{
  495. Endpoint: updateDeploymentEndpoint,
  496. Handler: updateDeploymentHandler,
  497. Router: r,
  498. })
  499. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/deployments/status -> environment.NewUpdateDeploymentStatusByClusterHandler
  500. updateDeploymentStatusEndpoint := factory.NewAPIEndpoint(
  501. &types.APIRequestMetadata{
  502. Verb: types.APIVerbUpdate,
  503. Method: types.HTTPVerbPatch,
  504. Path: &types.Path{
  505. Parent: basePath,
  506. RelativePath: relPath + "/deployments/status",
  507. },
  508. Scopes: []types.PermissionScope{
  509. types.UserScope,
  510. types.ProjectScope,
  511. types.ClusterScope,
  512. types.PreviewEnvironmentScope,
  513. },
  514. },
  515. )
  516. updateDeploymentStatusHandler := environment.NewUpdateDeploymentStatusByClusterHandler(
  517. config,
  518. factory.GetDecoderValidator(),
  519. factory.GetResultWriter(),
  520. )
  521. routes = append(routes, &router.Route{
  522. Endpoint: updateDeploymentStatusEndpoint,
  523. Handler: updateDeploymentStatusHandler,
  524. Router: r,
  525. })
  526. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/deployment -> environment.NewGetDeploymentByClusterHandler
  527. getDeploymentEndpoint := factory.NewAPIEndpoint(
  528. &types.APIRequestMetadata{
  529. Verb: types.APIVerbGet,
  530. Method: types.HTTPVerbGet,
  531. Path: &types.Path{
  532. Parent: basePath,
  533. RelativePath: relPath + "/environments/{environment_id}/deployment",
  534. },
  535. Scopes: []types.PermissionScope{
  536. types.UserScope,
  537. types.ProjectScope,
  538. types.ClusterScope,
  539. types.PreviewEnvironmentScope,
  540. },
  541. },
  542. )
  543. getDeploymentHandler := environment.NewGetDeploymentByEnvironmentHandler(
  544. config,
  545. factory.GetDecoderValidator(),
  546. factory.GetResultWriter(),
  547. )
  548. routes = append(routes, &router.Route{
  549. Endpoint: getDeploymentEndpoint,
  550. Handler: getDeploymentHandler,
  551. Router: r,
  552. })
  553. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/finalize ->
  554. // environment.NewFinalizeDeploymentByClusterHandler
  555. finalizeDeploymentEndpoint := factory.NewAPIEndpoint(
  556. &types.APIRequestMetadata{
  557. Verb: types.APIVerbCreate,
  558. Method: types.HTTPVerbPost,
  559. Path: &types.Path{
  560. Parent: basePath,
  561. RelativePath: relPath + "/deployments/finalize",
  562. },
  563. Scopes: []types.PermissionScope{
  564. types.UserScope,
  565. types.ProjectScope,
  566. types.ClusterScope,
  567. types.PreviewEnvironmentScope,
  568. },
  569. },
  570. )
  571. finalizeDeploymentHandler := environment.NewFinalizeDeploymentByClusterHandler(
  572. config,
  573. factory.GetDecoderValidator(),
  574. factory.GetResultWriter(),
  575. )
  576. routes = append(routes, &router.Route{
  577. Endpoint: finalizeDeploymentEndpoint,
  578. Handler: finalizeDeploymentHandler,
  579. Router: r,
  580. })
  581. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/finalize_errors ->
  582. // environment.NewFinalizeDeploymentWithErrorsHandler
  583. finalizeDeploymentWithErrorsEndpoint := factory.NewAPIEndpoint(
  584. &types.APIRequestMetadata{
  585. Verb: types.APIVerbCreate,
  586. Method: types.HTTPVerbPost,
  587. Path: &types.Path{
  588. Parent: basePath,
  589. RelativePath: relPath + "/deployments/finalize_errors",
  590. },
  591. Scopes: []types.PermissionScope{
  592. types.UserScope,
  593. types.ProjectScope,
  594. types.ClusterScope,
  595. types.PreviewEnvironmentScope,
  596. },
  597. },
  598. )
  599. finalizeDeploymentWithErrorsHandler := environment.NewFinalizeDeploymentWithErrorsByClusterHandler(
  600. config,
  601. factory.GetDecoderValidator(),
  602. factory.GetResultWriter(),
  603. )
  604. routes = append(routes, &router.Route{
  605. Endpoint: finalizeDeploymentWithErrorsEndpoint,
  606. Handler: finalizeDeploymentWithErrorsHandler,
  607. Router: r,
  608. })
  609. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/deployments/{deployment_id}/reenable -> environment.NewReenableDeploymentHandler
  610. reenableDeploymentEndpoint := factory.NewAPIEndpoint(
  611. &types.APIRequestMetadata{
  612. Verb: types.APIVerbUpdate,
  613. Method: types.HTTPVerbPatch,
  614. Path: &types.Path{
  615. Parent: basePath,
  616. RelativePath: relPath + "/deployments/{deployment_id}/reenable",
  617. },
  618. Scopes: []types.PermissionScope{
  619. types.UserScope,
  620. types.ProjectScope,
  621. types.ClusterScope,
  622. types.PreviewEnvironmentScope,
  623. },
  624. },
  625. )
  626. reenableDeploymentHandler := environment.NewReenableDeploymentHandler(
  627. config,
  628. factory.GetDecoderValidator(),
  629. factory.GetResultWriter(),
  630. )
  631. routes = append(routes, &router.Route{
  632. Endpoint: reenableDeploymentEndpoint,
  633. Handler: reenableDeploymentHandler,
  634. Router: r,
  635. })
  636. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/{deployment_id}/trigger_workflow -> environment.NewTriggerDeploymentWorkflowHandler
  637. triggerDeploymentWorkflowEndpoint := factory.NewAPIEndpoint(
  638. &types.APIRequestMetadata{
  639. Verb: types.APIVerbCreate,
  640. Method: types.HTTPVerbPost,
  641. Path: &types.Path{
  642. Parent: basePath,
  643. RelativePath: relPath + "/deployments/{deployment_id}/trigger_workflow",
  644. },
  645. Scopes: []types.PermissionScope{
  646. types.UserScope,
  647. types.ProjectScope,
  648. types.ClusterScope,
  649. types.PreviewEnvironmentScope,
  650. },
  651. },
  652. )
  653. triggerDeploymentWorkflowHandler := environment.NewTriggerDeploymentWorkflowHandler(
  654. config,
  655. factory.GetDecoderValidator(),
  656. factory.GetResultWriter(),
  657. )
  658. routes = append(routes, &router.Route{
  659. Endpoint: triggerDeploymentWorkflowEndpoint,
  660. Handler: triggerDeploymentWorkflowHandler,
  661. Router: r,
  662. })
  663. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/pull_request -> environment.NewEnablePullRequestHandler
  664. enablePullRequestEndpoint := factory.NewAPIEndpoint(
  665. &types.APIRequestMetadata{
  666. Verb: types.APIVerbCreate,
  667. Method: types.HTTPVerbPost,
  668. Path: &types.Path{
  669. Parent: basePath,
  670. RelativePath: relPath + "/deployments/pull_request",
  671. },
  672. Scopes: []types.PermissionScope{
  673. types.UserScope,
  674. types.ProjectScope,
  675. types.ClusterScope,
  676. types.PreviewEnvironmentScope,
  677. },
  678. },
  679. )
  680. enablePullRequestHandler := environment.NewEnablePullRequestHandler(
  681. config,
  682. factory.GetDecoderValidator(),
  683. factory.GetResultWriter(),
  684. )
  685. routes = append(routes, &router.Route{
  686. Endpoint: enablePullRequestEndpoint,
  687. Handler: enablePullRequestHandler,
  688. Router: r,
  689. })
  690. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/deployments/{deployment_id} ->
  691. // environment.NewDeleteDeploymentHandler
  692. deleteDeploymentEndpoint := factory.NewAPIEndpoint(
  693. &types.APIRequestMetadata{
  694. Verb: types.APIVerbDelete,
  695. Method: types.HTTPVerbDelete,
  696. Path: &types.Path{
  697. Parent: basePath,
  698. RelativePath: relPath + "/deployments/{deployment_id}",
  699. },
  700. Scopes: []types.PermissionScope{
  701. types.UserScope,
  702. types.ProjectScope,
  703. types.ClusterScope,
  704. types.PreviewEnvironmentScope,
  705. },
  706. },
  707. )
  708. deleteDeploymentHandler := environment.NewDeleteDeploymentHandler(
  709. config,
  710. factory.GetDecoderValidator(),
  711. factory.GetResultWriter(),
  712. )
  713. routes = append(routes, &router.Route{
  714. Endpoint: deleteDeploymentEndpoint,
  715. Handler: deleteDeploymentHandler,
  716. Router: r,
  717. })
  718. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/settings ->
  719. // environment.NewUpdateEnvironmentSettingsHandler
  720. updateEnvironmentSettingsEndpoint := factory.NewAPIEndpoint(
  721. &types.APIRequestMetadata{
  722. Verb: types.APIVerbUpdate,
  723. Method: types.HTTPVerbPatch,
  724. Path: &types.Path{
  725. Parent: basePath,
  726. RelativePath: relPath + "/environments/{environment_id}/settings",
  727. },
  728. Scopes: []types.PermissionScope{
  729. types.UserScope,
  730. types.ProjectScope,
  731. types.ClusterScope,
  732. },
  733. },
  734. )
  735. updateEnvironmentSettingsHandler := environment.NewUpdateEnvironmentSettingsHandler(
  736. config,
  737. factory.GetDecoderValidator(),
  738. factory.GetResultWriter(),
  739. )
  740. routes = append(routes, &router.Route{
  741. Endpoint: updateEnvironmentSettingsEndpoint,
  742. Handler: updateEnvironmentSettingsHandler,
  743. Router: r,
  744. })
  745. }
  746. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces -> cluster.NewClusterListNamespacesHandler
  747. listNamespacesEndpoint := factory.NewAPIEndpoint(
  748. &types.APIRequestMetadata{
  749. Verb: types.APIVerbGet,
  750. Method: types.HTTPVerbGet,
  751. Path: &types.Path{
  752. Parent: basePath,
  753. RelativePath: relPath + "/namespaces",
  754. },
  755. Scopes: []types.PermissionScope{
  756. types.UserScope,
  757. types.ProjectScope,
  758. types.ClusterScope,
  759. },
  760. },
  761. )
  762. listNamespacesHandler := cluster.NewListNamespacesHandler(
  763. config,
  764. factory.GetResultWriter(),
  765. )
  766. routes = append(routes, &router.Route{
  767. Endpoint: listNamespacesEndpoint,
  768. Handler: listNamespacesHandler,
  769. Router: r,
  770. })
  771. // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes -> cluster.NewListNodesHandler
  772. listNodesEndpoint := factory.NewAPIEndpoint(
  773. &types.APIRequestMetadata{
  774. Verb: types.APIVerbGet,
  775. Method: types.HTTPVerbGet,
  776. Path: &types.Path{
  777. Parent: basePath,
  778. RelativePath: relPath + "/nodes",
  779. },
  780. Scopes: []types.PermissionScope{
  781. types.UserScope,
  782. types.ProjectScope,
  783. types.ClusterScope,
  784. },
  785. },
  786. )
  787. listNodesHandler := cluster.NewListNodesHandler(
  788. config,
  789. factory.GetResultWriter(),
  790. )
  791. routes = append(routes, &router.Route{
  792. Endpoint: listNodesEndpoint,
  793. Handler: listNodesHandler,
  794. Router: r,
  795. })
  796. // GET /api/projects/{project_id}/clusters/{cluster_id}/node-groups -> cluster.NewNodeGroupsHandler
  797. nodeGroupsEndpoint := factory.NewAPIEndpoint(
  798. &types.APIRequestMetadata{
  799. Verb: types.APIVerbGet,
  800. Method: types.HTTPVerbGet,
  801. Path: &types.Path{
  802. Parent: basePath,
  803. RelativePath: relPath + "/node-groups",
  804. },
  805. Scopes: []types.PermissionScope{
  806. types.UserScope,
  807. types.ProjectScope,
  808. types.ClusterScope,
  809. },
  810. },
  811. )
  812. nodeGroupsHandler := cluster.NewNodeGroupsHandler(
  813. config,
  814. factory.GetResultWriter(),
  815. )
  816. routes = append(routes, &router.Route{
  817. Endpoint: nodeGroupsEndpoint,
  818. Handler: nodeGroupsHandler,
  819. Router: r,
  820. })
  821. // GET /api/projects/{project_id}/clusters/{cluster_id}/delete-node-group -> cluster.NewNodeGroupsHandler
  822. deleteNodeGroupEndpoint := factory.NewAPIEndpoint(
  823. &types.APIRequestMetadata{
  824. Verb: types.APIVerbUpdate,
  825. Method: types.HTTPVerbPost,
  826. Path: &types.Path{
  827. Parent: basePath,
  828. RelativePath: relPath + "/delete-node-group",
  829. },
  830. Scopes: []types.PermissionScope{
  831. types.UserScope,
  832. types.ProjectScope,
  833. types.ClusterScope,
  834. },
  835. },
  836. )
  837. deleteNodeGroupHandler := cluster.NewDeleteNodeGroupHandler(
  838. config,
  839. factory.GetDecoderValidator(),
  840. factory.GetResultWriter(),
  841. )
  842. routes = append(routes, &router.Route{
  843. Endpoint: deleteNodeGroupEndpoint,
  844. Handler: deleteNodeGroupHandler,
  845. Router: r,
  846. })
  847. // GET /api/projects/{project_id}/clusters/{cluster_id}/nodes/{node_name} -> cluster.NewGetNodeHandler
  848. getNodeEndpoint := factory.NewAPIEndpoint(
  849. &types.APIRequestMetadata{
  850. Verb: types.APIVerbGet,
  851. Method: types.HTTPVerbGet,
  852. Path: &types.Path{
  853. Parent: basePath,
  854. RelativePath: fmt.Sprintf("%s/nodes/{%s}", relPath, types.URLParamNodeName),
  855. },
  856. Scopes: []types.PermissionScope{
  857. types.UserScope,
  858. types.ProjectScope,
  859. types.ClusterScope,
  860. },
  861. },
  862. )
  863. getNodeHandler := cluster.NewGetNodeHandler(
  864. config,
  865. factory.GetResultWriter(),
  866. )
  867. routes = append(routes, &router.Route{
  868. Endpoint: getNodeEndpoint,
  869. Handler: getNodeHandler,
  870. Router: r,
  871. })
  872. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/create -> cluster.NewCreateNamespaceHandler
  873. createNamespaceEndpoint := factory.NewAPIEndpoint(
  874. &types.APIRequestMetadata{
  875. Verb: types.APIVerbCreate,
  876. Method: types.HTTPVerbPost,
  877. Path: &types.Path{
  878. Parent: basePath,
  879. RelativePath: relPath + "/namespaces/create",
  880. },
  881. Scopes: []types.PermissionScope{
  882. types.UserScope,
  883. types.ProjectScope,
  884. types.ClusterScope,
  885. },
  886. },
  887. )
  888. createNamespaceHandler := cluster.NewCreateNamespaceHandler(
  889. config,
  890. factory.GetDecoderValidator(),
  891. factory.GetResultWriter(),
  892. )
  893. routes = append(routes, &router.Route{
  894. Endpoint: createNamespaceEndpoint,
  895. Handler: createNamespaceHandler,
  896. Router: r,
  897. })
  898. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace} -> cluster.NewDeleteNamespaceHandler
  899. deleteNamespaceEndpoint := factory.NewAPIEndpoint(
  900. &types.APIRequestMetadata{
  901. Verb: types.APIVerbDelete,
  902. Method: types.HTTPVerbDelete,
  903. Path: &types.Path{
  904. Parent: basePath,
  905. RelativePath: fmt.Sprintf("%s/namespaces/{%s}", relPath, types.URLParamNamespace),
  906. },
  907. Scopes: []types.PermissionScope{
  908. types.UserScope,
  909. types.ProjectScope,
  910. types.ClusterScope,
  911. },
  912. },
  913. )
  914. deleteNamespaceHandler := cluster.NewDeleteNamespaceHandler(
  915. config,
  916. factory.GetDecoderValidator(),
  917. )
  918. routes = append(routes, &router.Route{
  919. Endpoint: deleteNamespaceEndpoint,
  920. Handler: deleteNamespaceHandler,
  921. Router: r,
  922. })
  923. if !config.ServerConf.DisableTemporaryKubeconfig {
  924. // GET /api/projects/{project_id}/clusters/{cluster_id}/kubeconfig -> cluster.NewGetTemporaryKubeconfigHandler
  925. getTemporaryKubeconfigEndpoint := factory.NewAPIEndpoint(
  926. &types.APIRequestMetadata{
  927. Verb: types.APIVerbGet,
  928. Method: types.HTTPVerbGet,
  929. Path: &types.Path{
  930. Parent: basePath,
  931. RelativePath: relPath + "/kubeconfig",
  932. },
  933. Scopes: []types.PermissionScope{
  934. types.UserScope,
  935. types.ProjectScope,
  936. types.ClusterScope,
  937. },
  938. },
  939. )
  940. getTemporaryKubeconfigHandler := cluster.NewGetTemporaryKubeconfigHandler(
  941. config,
  942. factory.GetResultWriter(),
  943. )
  944. routes = append(routes, &router.Route{
  945. Endpoint: getTemporaryKubeconfigEndpoint,
  946. Handler: getTemporaryKubeconfigHandler,
  947. Router: r,
  948. })
  949. }
  950. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/detect -> cluster.NewDetectPrometheusInstalledHandler
  951. detectPrometheusInstalledEndpoint := factory.NewAPIEndpoint(
  952. &types.APIRequestMetadata{
  953. Verb: types.APIVerbGet,
  954. Method: types.HTTPVerbGet,
  955. Path: &types.Path{
  956. Parent: basePath,
  957. RelativePath: relPath + "/prometheus/detect",
  958. },
  959. Scopes: []types.PermissionScope{
  960. types.UserScope,
  961. types.ProjectScope,
  962. types.ClusterScope,
  963. },
  964. },
  965. )
  966. detectPrometheusInstalledHandler := cluster.NewDetectPrometheusInstalledHandler(config)
  967. routes = append(routes, &router.Route{
  968. Endpoint: detectPrometheusInstalledEndpoint,
  969. Handler: detectPrometheusInstalledHandler,
  970. Router: r,
  971. })
  972. // GET /api/projects/{project_id}/clusters/{cluster_id}/agent/detect -> cluster.NewDetectAgentInstalledHandler
  973. detectAgentInstalledEndpoint := factory.NewAPIEndpoint(
  974. &types.APIRequestMetadata{
  975. Verb: types.APIVerbGet,
  976. Method: types.HTTPVerbGet,
  977. Path: &types.Path{
  978. Parent: basePath,
  979. RelativePath: relPath + "/agent/detect",
  980. },
  981. Scopes: []types.PermissionScope{
  982. types.UserScope,
  983. types.ProjectScope,
  984. types.ClusterScope,
  985. },
  986. },
  987. )
  988. detectAgentInstalledHandler := cluster.NewDetectAgentInstalledHandler(config, factory.GetResultWriter())
  989. routes = append(routes, &router.Route{
  990. Endpoint: detectAgentInstalledEndpoint,
  991. Handler: detectAgentInstalledHandler,
  992. Router: r,
  993. })
  994. // POST /api/projects/{project_id}/clusters/{cluster_id}/agent/install -> cluster.NewInstallAgentHandler
  995. installAgentEndpoint := factory.NewAPIEndpoint(
  996. &types.APIRequestMetadata{
  997. Verb: types.APIVerbCreate,
  998. Method: types.HTTPVerbPost,
  999. Path: &types.Path{
  1000. Parent: basePath,
  1001. RelativePath: relPath + "/agent/install",
  1002. },
  1003. Scopes: []types.PermissionScope{
  1004. types.UserScope,
  1005. types.ProjectScope,
  1006. types.ClusterScope,
  1007. },
  1008. },
  1009. )
  1010. installAgentHandler := cluster.NewInstallAgentHandler(
  1011. config,
  1012. factory.GetDecoderValidator(),
  1013. factory.GetResultWriter(),
  1014. )
  1015. routes = append(routes, &router.Route{
  1016. Endpoint: installAgentEndpoint,
  1017. Handler: installAgentHandler,
  1018. Router: r,
  1019. })
  1020. // GET /api/projects/{project_id}/clusters/{cluster_id}/agent/status -> cluster.NewGetAgentStatusHandler
  1021. getAgentStatusEndpoint := factory.NewAPIEndpoint(
  1022. &types.APIRequestMetadata{
  1023. Verb: types.APIVerbGet,
  1024. Method: types.HTTPVerbGet,
  1025. Path: &types.Path{
  1026. Parent: basePath,
  1027. RelativePath: relPath + "/agent/status",
  1028. },
  1029. Scopes: []types.PermissionScope{
  1030. types.UserScope,
  1031. types.ProjectScope,
  1032. types.ClusterScope,
  1033. },
  1034. },
  1035. )
  1036. getAgentStatusHandler := cluster.NewGetAgentStatusHandler(config, factory.GetResultWriter())
  1037. routes = append(routes, &router.Route{
  1038. Endpoint: getAgentStatusEndpoint,
  1039. Handler: getAgentStatusHandler,
  1040. Router: r,
  1041. })
  1042. // POST /api/projects/{project_id}/clusters/{cluster_id}/agent/upgrade -> cluster.NewInstallAgentHandler
  1043. upgradeAgentEndpoint := factory.NewAPIEndpoint(
  1044. &types.APIRequestMetadata{
  1045. Verb: types.APIVerbCreate,
  1046. Method: types.HTTPVerbPost,
  1047. Path: &types.Path{
  1048. Parent: basePath,
  1049. RelativePath: relPath + "/agent/upgrade",
  1050. },
  1051. Scopes: []types.PermissionScope{
  1052. types.UserScope,
  1053. types.ProjectScope,
  1054. types.ClusterScope,
  1055. },
  1056. },
  1057. )
  1058. upgradeAgentHandler := cluster.NewUpgradeAgentHandler(
  1059. config,
  1060. factory.GetDecoderValidator(),
  1061. factory.GetResultWriter(),
  1062. )
  1063. routes = append(routes, &router.Route{
  1064. Endpoint: upgradeAgentEndpoint,
  1065. Handler: upgradeAgentHandler,
  1066. Router: r,
  1067. })
  1068. // GET /api/projects/{project_id}/clusters/{cluster_id}/prometheus/ingresses -> cluster.NewListNGINXIngressesHandler
  1069. listNGINXIngressesEndpoint := factory.NewAPIEndpoint(
  1070. &types.APIRequestMetadata{
  1071. Verb: types.APIVerbGet,
  1072. Method: types.HTTPVerbGet,
  1073. Path: &types.Path{
  1074. Parent: basePath,
  1075. RelativePath: relPath + "/prometheus/ingresses",
  1076. },
  1077. Scopes: []types.PermissionScope{
  1078. types.UserScope,
  1079. types.ProjectScope,
  1080. types.ClusterScope,
  1081. },
  1082. },
  1083. )
  1084. listNGINXIngressesHandler := cluster.NewListNGINXIngressesHandler(
  1085. config,
  1086. factory.GetResultWriter(),
  1087. )
  1088. routes = append(routes, &router.Route{
  1089. Endpoint: listNGINXIngressesEndpoint,
  1090. Handler: listNGINXIngressesHandler,
  1091. Router: r,
  1092. })
  1093. // GET /api/projects/{project_id}/clusters/{cluster_id}/metrics -> cluster.NewGetPodMetricsHandler
  1094. getPodMetricsEndpoint := factory.NewAPIEndpoint(
  1095. &types.APIRequestMetadata{
  1096. Verb: types.APIVerbGet,
  1097. Method: types.HTTPVerbGet,
  1098. Path: &types.Path{
  1099. Parent: basePath,
  1100. RelativePath: relPath + "/metrics",
  1101. },
  1102. Scopes: []types.PermissionScope{
  1103. types.UserScope,
  1104. types.ProjectScope,
  1105. types.ClusterScope,
  1106. },
  1107. },
  1108. )
  1109. getPodMetricsHandler := cluster.NewGetPodMetricsHandler(
  1110. config,
  1111. factory.GetDecoderValidator(),
  1112. factory.GetResultWriter(),
  1113. )
  1114. routes = append(routes, &router.Route{
  1115. Endpoint: getPodMetricsEndpoint,
  1116. Handler: getPodMetricsHandler,
  1117. Router: r,
  1118. })
  1119. // GET /api/projects/{project_id}/clusters/{cluster_id}/helm_release -> cluster.NewStreamHelmReleaseHandler
  1120. streamHelmReleaseEndpoint := factory.NewAPIEndpoint(
  1121. &types.APIRequestMetadata{
  1122. Verb: types.APIVerbGet,
  1123. Method: types.HTTPVerbGet,
  1124. Path: &types.Path{
  1125. Parent: basePath,
  1126. RelativePath: relPath + "/helm_release",
  1127. },
  1128. Scopes: []types.PermissionScope{
  1129. types.UserScope,
  1130. types.ProjectScope,
  1131. types.ClusterScope,
  1132. },
  1133. IsWebsocket: true,
  1134. },
  1135. )
  1136. streamHelmReleaseHandler := cluster.NewStreamHelmReleaseHandler(
  1137. config,
  1138. factory.GetDecoderValidator(),
  1139. factory.GetResultWriter(),
  1140. )
  1141. routes = append(routes, &router.Route{
  1142. Endpoint: streamHelmReleaseEndpoint,
  1143. Handler: streamHelmReleaseHandler,
  1144. Router: r,
  1145. })
  1146. // GET /api/projects/{project_id}/clusters/{cluster_id}/state -> cluster.NewClusterStatusHandler
  1147. clusterStatusEndpoint := factory.NewAPIEndpoint(
  1148. &types.APIRequestMetadata{
  1149. Verb: types.APIVerbGet,
  1150. Method: types.HTTPVerbGet,
  1151. Path: &types.Path{
  1152. Parent: basePath,
  1153. RelativePath: relPath + "/state",
  1154. },
  1155. Scopes: []types.PermissionScope{
  1156. types.UserScope,
  1157. types.ProjectScope,
  1158. types.ClusterScope,
  1159. },
  1160. },
  1161. )
  1162. clusterStatusHandler := cluster.NewClusterStatusHandler(
  1163. config,
  1164. factory.GetDecoderValidator(),
  1165. factory.GetResultWriter(),
  1166. )
  1167. routes = append(routes, &router.Route{
  1168. Endpoint: clusterStatusEndpoint,
  1169. Handler: clusterStatusHandler,
  1170. Router: r,
  1171. })
  1172. // GET /api/projects/{project_id}/clusters/{cluster_id}/{kind}/status -> cluster.NewStreamStatusHandler
  1173. streamStatusEndpoint := factory.NewAPIEndpoint(
  1174. &types.APIRequestMetadata{
  1175. Verb: types.APIVerbGet,
  1176. Method: types.HTTPVerbGet,
  1177. Path: &types.Path{
  1178. Parent: basePath,
  1179. RelativePath: fmt.Sprintf(
  1180. "%s/{%s}/status",
  1181. relPath,
  1182. types.URLParamKind,
  1183. ),
  1184. },
  1185. Scopes: []types.PermissionScope{
  1186. types.UserScope,
  1187. types.ProjectScope,
  1188. types.ClusterScope,
  1189. },
  1190. IsWebsocket: true,
  1191. },
  1192. )
  1193. streamStatusHandler := cluster.NewStreamStatusHandler(
  1194. config,
  1195. factory.GetDecoderValidator(),
  1196. factory.GetResultWriter(),
  1197. )
  1198. routes = append(routes, &router.Route{
  1199. Endpoint: streamStatusEndpoint,
  1200. Handler: streamStatusHandler,
  1201. Router: r,
  1202. })
  1203. // GET /api/projects/{project_id}/clusters/{cluster_id}/pods -> cluster.NewGetPodsHandler
  1204. getPodsEndpoint := factory.NewAPIEndpoint(
  1205. &types.APIRequestMetadata{
  1206. Verb: types.APIVerbGet,
  1207. Method: types.HTTPVerbGet,
  1208. Path: &types.Path{
  1209. Parent: basePath,
  1210. RelativePath: relPath + "/pods",
  1211. },
  1212. Scopes: []types.PermissionScope{
  1213. types.UserScope,
  1214. types.ProjectScope,
  1215. types.ClusterScope,
  1216. },
  1217. },
  1218. )
  1219. getPodsHandler := cluster.NewGetPodsHandler(
  1220. config,
  1221. factory.GetDecoderValidator(),
  1222. factory.GetResultWriter(),
  1223. )
  1224. routes = append(routes, &router.Route{
  1225. Endpoint: getPodsEndpoint,
  1226. Handler: getPodsHandler,
  1227. Router: r,
  1228. })
  1229. // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents -> cluster.NewListIncidentsHandler
  1230. listIncidentsEndpoint := factory.NewAPIEndpoint(
  1231. &types.APIRequestMetadata{
  1232. Verb: types.APIVerbGet,
  1233. Method: types.HTTPVerbGet,
  1234. Path: &types.Path{
  1235. Parent: basePath,
  1236. RelativePath: relPath + "/incidents",
  1237. },
  1238. Scopes: []types.PermissionScope{
  1239. types.UserScope,
  1240. types.ProjectScope,
  1241. types.ClusterScope,
  1242. },
  1243. },
  1244. )
  1245. listIncidentsHandler := cluster.NewListIncidentsHandler(
  1246. config,
  1247. factory.GetDecoderValidator(),
  1248. factory.GetResultWriter(),
  1249. )
  1250. routes = append(routes, &router.Route{
  1251. Endpoint: listIncidentsEndpoint,
  1252. Handler: listIncidentsHandler,
  1253. Router: r,
  1254. })
  1255. // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents/{incident_id} -> cluster.NewGetIncidentHandler
  1256. getIncidentEndpoint := factory.NewAPIEndpoint(
  1257. &types.APIRequestMetadata{
  1258. Verb: types.APIVerbGet,
  1259. Method: types.HTTPVerbGet,
  1260. Path: &types.Path{
  1261. Parent: basePath,
  1262. RelativePath: fmt.Sprintf("%s/incidents/{%s}", relPath, types.URLParamIncidentID),
  1263. },
  1264. Scopes: []types.PermissionScope{
  1265. types.UserScope,
  1266. types.ProjectScope,
  1267. types.ClusterScope,
  1268. },
  1269. },
  1270. )
  1271. getIncidentHandler := cluster.NewGetIncidentHandler(
  1272. config,
  1273. factory.GetDecoderValidator(),
  1274. factory.GetResultWriter(),
  1275. )
  1276. routes = append(routes, &router.Route{
  1277. Endpoint: getIncidentEndpoint,
  1278. Handler: getIncidentHandler,
  1279. Router: r,
  1280. })
  1281. // GET /api/projects/{project_id}/clusters/{cluster_id}/incidents/events -> cluster.NewListIncidentEventsHandler
  1282. listIncidentEventsEndpoint := factory.NewAPIEndpoint(
  1283. &types.APIRequestMetadata{
  1284. Verb: types.APIVerbGet,
  1285. Method: types.HTTPVerbGet,
  1286. Path: &types.Path{
  1287. Parent: basePath,
  1288. RelativePath: fmt.Sprintf("%s/incidents/events", relPath),
  1289. },
  1290. Scopes: []types.PermissionScope{
  1291. types.UserScope,
  1292. types.ProjectScope,
  1293. types.ClusterScope,
  1294. },
  1295. },
  1296. )
  1297. listIncidentEventsHandler := cluster.NewListIncidentEventsHandler(
  1298. config,
  1299. factory.GetDecoderValidator(),
  1300. factory.GetResultWriter(),
  1301. )
  1302. routes = append(routes, &router.Route{
  1303. Endpoint: listIncidentEventsEndpoint,
  1304. Handler: listIncidentEventsHandler,
  1305. Router: r,
  1306. })
  1307. // GET /api/projects/{project_id}/clusters/{cluster_id}/logs -> cluster.NewGetLogsHandler
  1308. getLogsEndpoint := factory.NewAPIEndpoint(
  1309. &types.APIRequestMetadata{
  1310. Verb: types.APIVerbGet,
  1311. Method: types.HTTPVerbGet,
  1312. Path: &types.Path{
  1313. Parent: basePath,
  1314. RelativePath: fmt.Sprintf("%s/logs", relPath),
  1315. },
  1316. Scopes: []types.PermissionScope{
  1317. types.UserScope,
  1318. types.ProjectScope,
  1319. types.ClusterScope,
  1320. },
  1321. },
  1322. )
  1323. getLogsHandler := cluster.NewGetLogsHandler(
  1324. config,
  1325. factory.GetDecoderValidator(),
  1326. factory.GetResultWriter(),
  1327. )
  1328. routes = append(routes, &router.Route{
  1329. Endpoint: getLogsEndpoint,
  1330. Handler: getLogsHandler,
  1331. Router: r,
  1332. })
  1333. // GET /api/projects/{project_id}/clusters/{cluster_id}/logs/pod_values -> cluster.NewGetLogPodValuesHandler
  1334. getLogPodValuesEndpoint := factory.NewAPIEndpoint(
  1335. &types.APIRequestMetadata{
  1336. Verb: types.APIVerbGet,
  1337. Method: types.HTTPVerbGet,
  1338. Path: &types.Path{
  1339. Parent: basePath,
  1340. RelativePath: fmt.Sprintf("%s/logs/pod_values", relPath),
  1341. },
  1342. Scopes: []types.PermissionScope{
  1343. types.UserScope,
  1344. types.ProjectScope,
  1345. types.ClusterScope,
  1346. },
  1347. },
  1348. )
  1349. getLogPodValuesHandler := cluster.NewGetLogPodValuesHandler(
  1350. config,
  1351. factory.GetDecoderValidator(),
  1352. factory.GetResultWriter(),
  1353. )
  1354. routes = append(routes, &router.Route{
  1355. Endpoint: getLogPodValuesEndpoint,
  1356. Handler: getLogPodValuesHandler,
  1357. Router: r,
  1358. })
  1359. // GET /api/projects/{project_id}/clusters/{cluster_id}/logs/revision_values -> cluster.NewGetLogPodValuesHandler
  1360. getLogRevisionValuesEndpoint := factory.NewAPIEndpoint(
  1361. &types.APIRequestMetadata{
  1362. Verb: types.APIVerbGet,
  1363. Method: types.HTTPVerbGet,
  1364. Path: &types.Path{
  1365. Parent: basePath,
  1366. RelativePath: fmt.Sprintf("%s/logs/revision_values", relPath),
  1367. },
  1368. Scopes: []types.PermissionScope{
  1369. types.UserScope,
  1370. types.ProjectScope,
  1371. types.ClusterScope,
  1372. },
  1373. },
  1374. )
  1375. getLogRevisionValuesHandler := cluster.NewGetLogRevisionValuesHandler(
  1376. config,
  1377. factory.GetDecoderValidator(),
  1378. factory.GetResultWriter(),
  1379. )
  1380. routes = append(routes, &router.Route{
  1381. Endpoint: getLogRevisionValuesEndpoint,
  1382. Handler: getLogRevisionValuesHandler,
  1383. Router: r,
  1384. })
  1385. // GET /api/projects/{project_id}/clusters/{cluster_id}/events -> cluster.NewGetEventsHandler
  1386. getPorterEventsEndpoint := factory.NewAPIEndpoint(
  1387. &types.APIRequestMetadata{
  1388. Verb: types.APIVerbGet,
  1389. Method: types.HTTPVerbGet,
  1390. Path: &types.Path{
  1391. Parent: basePath,
  1392. RelativePath: fmt.Sprintf("%s/events", relPath),
  1393. },
  1394. Scopes: []types.PermissionScope{
  1395. types.UserScope,
  1396. types.ProjectScope,
  1397. types.ClusterScope,
  1398. },
  1399. },
  1400. )
  1401. getPorterEventsHandler := cluster.NewGetPorterEventsHandler(
  1402. config,
  1403. factory.GetDecoderValidator(),
  1404. factory.GetResultWriter(),
  1405. )
  1406. routes = append(routes, &router.Route{
  1407. Endpoint: getPorterEventsEndpoint,
  1408. Handler: getPorterEventsHandler,
  1409. Router: r,
  1410. })
  1411. // GET /api/projects/{project_id}/clusters/{cluster_id}/events/job -> cluster.NewGetPorterJobEventsHandler
  1412. getPorterJobEventsEndpoint := factory.NewAPIEndpoint(
  1413. &types.APIRequestMetadata{
  1414. Verb: types.APIVerbGet,
  1415. Method: types.HTTPVerbGet,
  1416. Path: &types.Path{
  1417. Parent: basePath,
  1418. RelativePath: fmt.Sprintf("%s/events/job", relPath),
  1419. },
  1420. Scopes: []types.PermissionScope{
  1421. types.UserScope,
  1422. types.ProjectScope,
  1423. types.ClusterScope,
  1424. },
  1425. },
  1426. )
  1427. getPorterJobEventsHandler := cluster.NewGetPorterJobEventsHandler(
  1428. config,
  1429. factory.GetDecoderValidator(),
  1430. factory.GetResultWriter(),
  1431. )
  1432. routes = append(routes, &router.Route{
  1433. Endpoint: getPorterJobEventsEndpoint,
  1434. Handler: getPorterJobEventsHandler,
  1435. Router: r,
  1436. })
  1437. // GET /api/projects/{project_id}/clusters/{cluster_id}/k8s_events -> cluster.NewGetEventsHandler
  1438. getK8sEventsEndpoint := factory.NewAPIEndpoint(
  1439. &types.APIRequestMetadata{
  1440. Verb: types.APIVerbGet,
  1441. Method: types.HTTPVerbGet,
  1442. Path: &types.Path{
  1443. Parent: basePath,
  1444. RelativePath: fmt.Sprintf("%s/k8s_events", relPath),
  1445. },
  1446. Scopes: []types.PermissionScope{
  1447. types.UserScope,
  1448. types.ProjectScope,
  1449. types.ClusterScope,
  1450. },
  1451. },
  1452. )
  1453. getK8sEventsHandler := cluster.NewGetKubernetesEventsHandler(
  1454. config,
  1455. factory.GetDecoderValidator(),
  1456. factory.GetResultWriter(),
  1457. )
  1458. routes = append(routes, &router.Route{
  1459. Endpoint: getK8sEventsEndpoint,
  1460. Handler: getK8sEventsHandler,
  1461. Router: r,
  1462. })
  1463. // POST /api/projects/{project_id}/clusters/{cluster_id}/incidents/notify_new -> cluster.NewNotifyNewIncidentHandler
  1464. notifyNewIncidentEndpoint := factory.NewAPIEndpoint(
  1465. &types.APIRequestMetadata{
  1466. Verb: types.APIVerbCreate,
  1467. Method: types.HTTPVerbPost,
  1468. Path: &types.Path{
  1469. Parent: basePath,
  1470. RelativePath: relPath + "/incidents/notify_new",
  1471. },
  1472. Scopes: []types.PermissionScope{
  1473. types.UserScope,
  1474. types.ProjectScope,
  1475. types.ClusterScope,
  1476. },
  1477. },
  1478. )
  1479. notifyNewIncidentHandler := cluster.NewNotifyNewIncidentHandler(
  1480. config,
  1481. factory.GetDecoderValidator(),
  1482. factory.GetResultWriter(),
  1483. )
  1484. routes = append(routes, &router.Route{
  1485. Endpoint: notifyNewIncidentEndpoint,
  1486. Handler: notifyNewIncidentHandler,
  1487. Router: r,
  1488. })
  1489. // POST /api/projects/{project_id}/clusters/{cluster_id}/incidents/notify_resolved -> cluster.NewNotifyResolvedIncidentHandler
  1490. notifyResolvedIncidentEndpoint := factory.NewAPIEndpoint(
  1491. &types.APIRequestMetadata{
  1492. Verb: types.APIVerbCreate,
  1493. Method: types.HTTPVerbPost,
  1494. Path: &types.Path{
  1495. Parent: basePath,
  1496. RelativePath: relPath + "/incidents/notify_resolved",
  1497. },
  1498. Scopes: []types.PermissionScope{
  1499. types.UserScope,
  1500. types.ProjectScope,
  1501. types.ClusterScope,
  1502. },
  1503. },
  1504. )
  1505. notifyResolvedIncidentHandler := cluster.NewNotifyResolvedIncidentHandler(
  1506. config,
  1507. factory.GetDecoderValidator(),
  1508. factory.GetResultWriter(),
  1509. )
  1510. routes = append(routes, &router.Route{
  1511. Endpoint: notifyResolvedIncidentEndpoint,
  1512. Handler: notifyResolvedIncidentHandler,
  1513. Router: r,
  1514. })
  1515. // POST /api/projects/{project_id}/clusters/{cluster_id}/environment-groups
  1516. updateEnvironmentGroupEndpoint := factory.NewAPIEndpoint(
  1517. &types.APIRequestMetadata{
  1518. Verb: types.APIVerbCreate,
  1519. Method: types.HTTPVerbPost,
  1520. Path: &types.Path{
  1521. Parent: basePath,
  1522. RelativePath: relPath + "/environment-groups",
  1523. },
  1524. Scopes: []types.PermissionScope{
  1525. types.UserScope,
  1526. types.ProjectScope,
  1527. types.ClusterScope,
  1528. },
  1529. },
  1530. )
  1531. updateEnvironmentGroupHandler := environment_groups.NewUpdateEnvironmentGroupHandler(
  1532. config,
  1533. factory.GetDecoderValidator(),
  1534. factory.GetResultWriter(),
  1535. )
  1536. routes = append(routes, &router.Route{
  1537. Endpoint: updateEnvironmentGroupEndpoint,
  1538. Handler: updateEnvironmentGroupHandler,
  1539. Router: r,
  1540. })
  1541. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/environment-groups}
  1542. deleteEnvironmentGroupEndpoint := factory.NewAPIEndpoint(
  1543. &types.APIRequestMetadata{
  1544. Verb: types.APIVerbDelete,
  1545. Method: types.HTTPVerbDelete,
  1546. Path: &types.Path{
  1547. Parent: basePath,
  1548. RelativePath: relPath + "/environment-groups",
  1549. },
  1550. Scopes: []types.PermissionScope{
  1551. types.UserScope,
  1552. types.ProjectScope,
  1553. types.ClusterScope,
  1554. },
  1555. },
  1556. )
  1557. deleteEnvironmentGroupHandler := environment_groups.NewDeleteEnvironmentGroupHandler(
  1558. config,
  1559. factory.GetDecoderValidator(),
  1560. factory.GetResultWriter(),
  1561. )
  1562. routes = append(routes, &router.Route{
  1563. Endpoint: deleteEnvironmentGroupEndpoint,
  1564. Handler: deleteEnvironmentGroupHandler,
  1565. Router: r,
  1566. })
  1567. // GET /api/projects/{project_id}/clusters/{cluster_id}/environment-groups
  1568. listEnvironmentGroupEndpoint := factory.NewAPIEndpoint(
  1569. &types.APIRequestMetadata{
  1570. Verb: types.APIVerbList,
  1571. Method: types.HTTPVerbGet,
  1572. Path: &types.Path{
  1573. Parent: basePath,
  1574. RelativePath: relPath + "/environment-groups",
  1575. },
  1576. Scopes: []types.PermissionScope{
  1577. types.UserScope,
  1578. types.ProjectScope,
  1579. types.ClusterScope,
  1580. },
  1581. },
  1582. )
  1583. listEnvironmentGroupHandler := environment_groups.NewListEnvironmentGroupsHandler(
  1584. config,
  1585. factory.GetDecoderValidator(),
  1586. factory.GetResultWriter(),
  1587. )
  1588. routes = append(routes, &router.Route{
  1589. Endpoint: listEnvironmentGroupEndpoint,
  1590. Handler: listEnvironmentGroupHandler,
  1591. Router: r,
  1592. })
  1593. // GET /api/projects/{project_id}/clusters/{cluster_id}/environment-groups/{env_group_name}/latest
  1594. getLatestEnvironmentGroupVariablesEndpoint := factory.NewAPIEndpoint(
  1595. &types.APIRequestMetadata{
  1596. Verb: types.APIVerbGet,
  1597. Method: types.HTTPVerbGet,
  1598. Path: &types.Path{
  1599. Parent: basePath,
  1600. RelativePath: fmt.Sprintf("%s/environment-groups/{%s}/latest", relPath, types.URLParamEnvGroupName),
  1601. },
  1602. Scopes: []types.PermissionScope{
  1603. types.UserScope,
  1604. types.ProjectScope,
  1605. types.ClusterScope,
  1606. },
  1607. },
  1608. )
  1609. getLatestEnvironmentGroupVariablesHandler := environment_groups.NewLatestEnvGroupVariablesHandler(
  1610. config,
  1611. factory.GetDecoderValidator(),
  1612. factory.GetResultWriter(),
  1613. )
  1614. routes = append(routes, &router.Route{
  1615. Endpoint: getLatestEnvironmentGroupVariablesEndpoint,
  1616. Handler: getLatestEnvironmentGroupVariablesHandler,
  1617. Router: r,
  1618. })
  1619. // GET /api/projects/{project_id}/clusters/{cluster_id}/environment-groups/update-linked-apps
  1620. updateLinkedAppsEndpoint := factory.NewAPIEndpoint(
  1621. &types.APIRequestMetadata{
  1622. Verb: types.APIVerbUpdate,
  1623. Method: types.HTTPVerbPost,
  1624. Path: &types.Path{
  1625. Parent: basePath,
  1626. RelativePath: relPath + "/environment-groups/update-linked-apps",
  1627. },
  1628. Scopes: []types.PermissionScope{
  1629. types.UserScope,
  1630. types.ProjectScope,
  1631. types.ClusterScope,
  1632. },
  1633. },
  1634. )
  1635. updateLinkedAppsHandler := environment_groups.NewUpdateLinkedAppsHandler(
  1636. config,
  1637. factory.GetDecoderValidator(),
  1638. factory.GetResultWriter(),
  1639. )
  1640. routes = append(routes, &router.Route{
  1641. Endpoint: updateLinkedAppsEndpoint,
  1642. Handler: updateLinkedAppsHandler,
  1643. Router: r,
  1644. })
  1645. // POST /api/projects/{project_id}/clusters/{cluster_id}/environment-groups/enable-external-providers
  1646. enableExternalProvidersEndpoint := factory.NewAPIEndpoint(
  1647. &types.APIRequestMetadata{
  1648. Verb: types.APIVerbUpdate,
  1649. Method: types.HTTPVerbPost,
  1650. Path: &types.Path{
  1651. Parent: basePath,
  1652. RelativePath: fmt.Sprintf("%s/environment-groups/enable-external-providers", relPath),
  1653. },
  1654. Scopes: []types.PermissionScope{
  1655. types.UserScope,
  1656. types.ProjectScope,
  1657. types.ClusterScope,
  1658. },
  1659. },
  1660. )
  1661. enableExternalProvidersHandler := environment_groups.NewEnableExternalProvidersHandler(
  1662. config,
  1663. factory.GetDecoderValidator(),
  1664. factory.GetResultWriter(),
  1665. )
  1666. routes = append(routes, &router.Route{
  1667. Endpoint: enableExternalProvidersEndpoint,
  1668. Handler: enableExternalProvidersHandler,
  1669. Router: r,
  1670. })
  1671. // GET /api/projects/{project_id}/clusters/{cluster_id}/environment-groups/are-external-providers-enabled
  1672. areExternalProvidersEnabledEndpoint := factory.NewAPIEndpoint(
  1673. &types.APIRequestMetadata{
  1674. Verb: types.APIVerbGet,
  1675. Method: types.HTTPVerbGet,
  1676. Path: &types.Path{
  1677. Parent: basePath,
  1678. RelativePath: fmt.Sprintf("%s/environment-groups/are-external-providers-enabled", relPath),
  1679. },
  1680. Scopes: []types.PermissionScope{
  1681. types.UserScope,
  1682. types.ProjectScope,
  1683. types.ClusterScope,
  1684. },
  1685. },
  1686. )
  1687. areExternalProvidersEnabledHandler := environment_groups.NewAreExternalProvidersEnabledHandler(
  1688. config,
  1689. factory.GetDecoderValidator(),
  1690. factory.GetResultWriter(),
  1691. )
  1692. routes = append(routes, &router.Route{
  1693. Endpoint: areExternalProvidersEnabledEndpoint,
  1694. Handler: areExternalProvidersEnabledHandler,
  1695. Router: r,
  1696. })
  1697. // POST /api/projects/{project_id}/clusters/{cluster_id}/datastores -> cluster.NewUpdateDatastoreHandler
  1698. updateDatastoreEndpoint := factory.NewAPIEndpoint(
  1699. &types.APIRequestMetadata{
  1700. Verb: types.APIVerbUpdate,
  1701. Method: types.HTTPVerbPost,
  1702. Path: &types.Path{
  1703. Parent: basePath,
  1704. RelativePath: fmt.Sprintf("%s/datastores", relPath),
  1705. },
  1706. Scopes: []types.PermissionScope{
  1707. types.UserScope,
  1708. types.ProjectScope,
  1709. types.ClusterScope,
  1710. },
  1711. },
  1712. )
  1713. updateDatastoreHandler := datastore.NewUpdateDatastoreHandler(
  1714. config,
  1715. factory.GetDecoderValidator(),
  1716. factory.GetResultWriter(),
  1717. )
  1718. routes = append(routes, &router.Route{
  1719. Endpoint: updateDatastoreEndpoint,
  1720. Handler: updateDatastoreHandler,
  1721. Router: r,
  1722. })
  1723. // POST /api/projects/{project_id}/clusters/{cluster_id}/system-status-history -> systemstatus.NewSystemStatusHistoryHandler
  1724. systemStatusHistoryEndpoint := factory.NewAPIEndpoint(
  1725. &types.APIRequestMetadata{
  1726. Verb: types.APIVerbGet,
  1727. Method: types.HTTPVerbGet,
  1728. Path: &types.Path{
  1729. Parent: basePath,
  1730. RelativePath: fmt.Sprintf("%s/system-status-history", relPath),
  1731. },
  1732. Scopes: []types.PermissionScope{
  1733. types.UserScope,
  1734. types.ProjectScope,
  1735. types.ClusterScope,
  1736. },
  1737. },
  1738. )
  1739. systemStatusHistoryHandler := systemstatus.NewHistoryHandler(
  1740. config,
  1741. factory.GetResultWriter(),
  1742. )
  1743. routes = append(routes, &router.Route{
  1744. Endpoint: systemStatusHistoryEndpoint,
  1745. Handler: systemStatusHistoryHandler,
  1746. Router: r,
  1747. })
  1748. return routes, newPath
  1749. }