cluster.go 49 KB

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