cluster.go 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  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. // GET /api/projects/{project_id}/clusters/{cluster_id}/databases -> database.NewDatabaseListHandler
  234. listDatabaseEndpoint := factory.NewAPIEndpoint(
  235. &types.APIRequestMetadata{
  236. Verb: types.APIVerbList,
  237. Method: types.HTTPVerbGet,
  238. Path: &types.Path{
  239. Parent: basePath,
  240. RelativePath: relPath + "/databases",
  241. },
  242. Scopes: []types.PermissionScope{
  243. types.UserScope,
  244. types.ProjectScope,
  245. types.ClusterScope,
  246. },
  247. },
  248. )
  249. listDatabaseHandler := database.NewDatabaseListHandler(
  250. config,
  251. factory.GetResultWriter(),
  252. )
  253. routes = append(routes, &router.Route{
  254. Endpoint: listDatabaseEndpoint,
  255. Handler: listDatabaseHandler,
  256. Router: r,
  257. })
  258. // GET /api/projects/{project_id}/clusters/{cluster_id}/datastore/status -> datastore.NewStatusHandler
  259. datastoreStatusEndpoint := factory.NewAPIEndpoint(
  260. &types.APIRequestMetadata{
  261. Verb: types.APIVerbList,
  262. Method: types.HTTPVerbGet,
  263. Path: &types.Path{
  264. Parent: basePath,
  265. RelativePath: relPath + "/datastore/status",
  266. },
  267. Scopes: []types.PermissionScope{
  268. types.UserScope,
  269. types.ProjectScope,
  270. types.ClusterScope,
  271. },
  272. },
  273. )
  274. datastoreStatusHandler := datastore.NewStatusHandler(
  275. config,
  276. factory.GetDecoderValidator(),
  277. factory.GetResultWriter(),
  278. )
  279. routes = append(routes, &router.Route{
  280. Endpoint: datastoreStatusEndpoint,
  281. Handler: datastoreStatusHandler,
  282. Router: r,
  283. })
  284. if config.ServerConf.GithubIncomingWebhookSecret != "" {
  285. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments -> environment.NewListEnvironmentHandler
  286. listEnvEndpoint := factory.NewAPIEndpoint(
  287. &types.APIRequestMetadata{
  288. Verb: types.APIVerbGet,
  289. Method: types.HTTPVerbGet,
  290. Path: &types.Path{
  291. Parent: basePath,
  292. RelativePath: relPath + "/environments",
  293. },
  294. Scopes: []types.PermissionScope{
  295. types.UserScope,
  296. types.ProjectScope,
  297. types.ClusterScope,
  298. types.PreviewEnvironmentScope,
  299. },
  300. },
  301. )
  302. listEnvHandler := environment.NewListEnvironmentHandler(
  303. config,
  304. factory.GetResultWriter(),
  305. )
  306. routes = append(routes, &router.Route{
  307. Endpoint: listEnvEndpoint,
  308. Handler: listEnvHandler,
  309. Router: r,
  310. })
  311. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id} -> environment.NewGetEnvironmentHandler
  312. getEnvEndpoint := factory.NewAPIEndpoint(
  313. &types.APIRequestMetadata{
  314. Verb: types.APIVerbGet,
  315. Method: types.HTTPVerbGet,
  316. Path: &types.Path{
  317. Parent: basePath,
  318. RelativePath: relPath + "/environments/{environment_id}",
  319. },
  320. Scopes: []types.PermissionScope{
  321. types.UserScope,
  322. types.ProjectScope,
  323. types.ClusterScope,
  324. types.PreviewEnvironmentScope,
  325. },
  326. },
  327. )
  328. getEnvHandler := environment.NewGetEnvironmentHandler(
  329. config,
  330. factory.GetResultWriter(),
  331. )
  332. routes = append(routes, &router.Route{
  333. Endpoint: getEnvEndpoint,
  334. Handler: getEnvHandler,
  335. Router: r,
  336. })
  337. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/toggle_new_comment -> environment.NewToggleNewCommentHandler
  338. toggleNewCommentEndpoint := factory.NewAPIEndpoint(
  339. &types.APIRequestMetadata{
  340. Verb: types.APIVerbUpdate,
  341. Method: types.HTTPVerbPatch,
  342. Path: &types.Path{
  343. Parent: basePath,
  344. RelativePath: relPath + "/environments/{environment_id}/toggle_new_comment",
  345. },
  346. Scopes: []types.PermissionScope{
  347. types.UserScope,
  348. types.ProjectScope,
  349. types.ClusterScope,
  350. types.PreviewEnvironmentScope,
  351. },
  352. },
  353. )
  354. toggleNewCommentHandler := environment.NewToggleNewCommentHandler(
  355. config,
  356. factory.GetDecoderValidator(),
  357. factory.GetResultWriter(),
  358. )
  359. routes = append(routes, &router.Route{
  360. Endpoint: toggleNewCommentEndpoint,
  361. Handler: toggleNewCommentHandler,
  362. Router: r,
  363. })
  364. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/validate_porter_yaml -> environment.NewValidatePorterYAMLHandler
  365. validtatePorterYAMLEndpoint := factory.NewAPIEndpoint(
  366. &types.APIRequestMetadata{
  367. Verb: types.APIVerbGet,
  368. Method: types.HTTPVerbGet,
  369. Path: &types.Path{
  370. Parent: basePath,
  371. RelativePath: relPath + "/environments/{environment_id}/validate_porter_yaml",
  372. },
  373. Scopes: []types.PermissionScope{
  374. types.UserScope,
  375. types.ProjectScope,
  376. types.ClusterScope,
  377. types.PreviewEnvironmentScope,
  378. },
  379. },
  380. )
  381. validatePorterYAMLHandler := environment.NewValidatePorterYAMLHandler(
  382. config,
  383. factory.GetDecoderValidator(),
  384. factory.GetResultWriter(),
  385. )
  386. routes = append(routes, &router.Route{
  387. Endpoint: validtatePorterYAMLEndpoint,
  388. Handler: validatePorterYAMLHandler,
  389. Router: r,
  390. })
  391. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments -> environment.NewCreateDeploymentByClusterHandler
  392. createDeploymentEndpoint := factory.NewAPIEndpoint(
  393. &types.APIRequestMetadata{
  394. Verb: types.APIVerbCreate,
  395. Method: types.HTTPVerbPost,
  396. Path: &types.Path{
  397. Parent: basePath,
  398. RelativePath: relPath + "/deployments",
  399. },
  400. Scopes: []types.PermissionScope{
  401. types.UserScope,
  402. types.ProjectScope,
  403. types.ClusterScope,
  404. types.PreviewEnvironmentScope,
  405. },
  406. },
  407. )
  408. createDeploymentHandler := environment.NewCreateDeploymentByClusterHandler(
  409. config,
  410. factory.GetDecoderValidator(),
  411. factory.GetResultWriter(),
  412. )
  413. routes = append(routes, &router.Route{
  414. Endpoint: createDeploymentEndpoint,
  415. Handler: createDeploymentHandler,
  416. Router: r,
  417. })
  418. // GET /api/projects/{project_id}/clusters/{cluster_id}/deployments -> environment.NewListDeploymentsByClusterHandler
  419. listDeploymentsEndpoint := factory.NewAPIEndpoint(
  420. &types.APIRequestMetadata{
  421. Verb: types.APIVerbGet,
  422. Method: types.HTTPVerbGet,
  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. listDeploymentsHandler := environment.NewListDeploymentsByClusterHandler(
  436. config,
  437. factory.GetDecoderValidator(),
  438. factory.GetResultWriter(),
  439. )
  440. routes = append(routes, &router.Route{
  441. Endpoint: listDeploymentsEndpoint,
  442. Handler: listDeploymentsHandler,
  443. Router: r,
  444. })
  445. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/deployments -> environment.NewUpdateDeploymentByClusterHandler
  446. updateDeploymentEndpoint := factory.NewAPIEndpoint(
  447. &types.APIRequestMetadata{
  448. Verb: types.APIVerbUpdate,
  449. Method: types.HTTPVerbPatch,
  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. updateDeploymentHandler := environment.NewUpdateDeploymentByClusterHandler(
  463. config,
  464. factory.GetDecoderValidator(),
  465. factory.GetResultWriter(),
  466. )
  467. routes = append(routes, &router.Route{
  468. Endpoint: updateDeploymentEndpoint,
  469. Handler: updateDeploymentHandler,
  470. Router: r,
  471. })
  472. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/deployments/status -> environment.NewUpdateDeploymentStatusByClusterHandler
  473. updateDeploymentStatusEndpoint := factory.NewAPIEndpoint(
  474. &types.APIRequestMetadata{
  475. Verb: types.APIVerbUpdate,
  476. Method: types.HTTPVerbPatch,
  477. Path: &types.Path{
  478. Parent: basePath,
  479. RelativePath: relPath + "/deployments/status",
  480. },
  481. Scopes: []types.PermissionScope{
  482. types.UserScope,
  483. types.ProjectScope,
  484. types.ClusterScope,
  485. types.PreviewEnvironmentScope,
  486. },
  487. },
  488. )
  489. updateDeploymentStatusHandler := environment.NewUpdateDeploymentStatusByClusterHandler(
  490. config,
  491. factory.GetDecoderValidator(),
  492. factory.GetResultWriter(),
  493. )
  494. routes = append(routes, &router.Route{
  495. Endpoint: updateDeploymentStatusEndpoint,
  496. Handler: updateDeploymentStatusHandler,
  497. Router: r,
  498. })
  499. // GET /api/projects/{project_id}/clusters/{cluster_id}/environments/{environment_id}/deployment -> environment.NewGetDeploymentByClusterHandler
  500. getDeploymentEndpoint := factory.NewAPIEndpoint(
  501. &types.APIRequestMetadata{
  502. Verb: types.APIVerbGet,
  503. Method: types.HTTPVerbGet,
  504. Path: &types.Path{
  505. Parent: basePath,
  506. RelativePath: relPath + "/environments/{environment_id}/deployment",
  507. },
  508. Scopes: []types.PermissionScope{
  509. types.UserScope,
  510. types.ProjectScope,
  511. types.ClusterScope,
  512. types.PreviewEnvironmentScope,
  513. },
  514. },
  515. )
  516. getDeploymentHandler := environment.NewGetDeploymentByEnvironmentHandler(
  517. config,
  518. factory.GetDecoderValidator(),
  519. factory.GetResultWriter(),
  520. )
  521. routes = append(routes, &router.Route{
  522. Endpoint: getDeploymentEndpoint,
  523. Handler: getDeploymentHandler,
  524. Router: r,
  525. })
  526. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/finalize ->
  527. // environment.NewFinalizeDeploymentByClusterHandler
  528. finalizeDeploymentEndpoint := factory.NewAPIEndpoint(
  529. &types.APIRequestMetadata{
  530. Verb: types.APIVerbCreate,
  531. Method: types.HTTPVerbPost,
  532. Path: &types.Path{
  533. Parent: basePath,
  534. RelativePath: relPath + "/deployments/finalize",
  535. },
  536. Scopes: []types.PermissionScope{
  537. types.UserScope,
  538. types.ProjectScope,
  539. types.ClusterScope,
  540. types.PreviewEnvironmentScope,
  541. },
  542. },
  543. )
  544. finalizeDeploymentHandler := environment.NewFinalizeDeploymentByClusterHandler(
  545. config,
  546. factory.GetDecoderValidator(),
  547. factory.GetResultWriter(),
  548. )
  549. routes = append(routes, &router.Route{
  550. Endpoint: finalizeDeploymentEndpoint,
  551. Handler: finalizeDeploymentHandler,
  552. Router: r,
  553. })
  554. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/finalize_errors ->
  555. // environment.NewFinalizeDeploymentWithErrorsHandler
  556. finalizeDeploymentWithErrorsEndpoint := factory.NewAPIEndpoint(
  557. &types.APIRequestMetadata{
  558. Verb: types.APIVerbCreate,
  559. Method: types.HTTPVerbPost,
  560. Path: &types.Path{
  561. Parent: basePath,
  562. RelativePath: relPath + "/deployments/finalize_errors",
  563. },
  564. Scopes: []types.PermissionScope{
  565. types.UserScope,
  566. types.ProjectScope,
  567. types.ClusterScope,
  568. types.PreviewEnvironmentScope,
  569. },
  570. },
  571. )
  572. finalizeDeploymentWithErrorsHandler := environment.NewFinalizeDeploymentWithErrorsByClusterHandler(
  573. config,
  574. factory.GetDecoderValidator(),
  575. factory.GetResultWriter(),
  576. )
  577. routes = append(routes, &router.Route{
  578. Endpoint: finalizeDeploymentWithErrorsEndpoint,
  579. Handler: finalizeDeploymentWithErrorsHandler,
  580. Router: r,
  581. })
  582. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/deployments/{deployment_id}/reenable -> environment.NewReenableDeploymentHandler
  583. reenableDeploymentEndpoint := factory.NewAPIEndpoint(
  584. &types.APIRequestMetadata{
  585. Verb: types.APIVerbUpdate,
  586. Method: types.HTTPVerbPatch,
  587. Path: &types.Path{
  588. Parent: basePath,
  589. RelativePath: relPath + "/deployments/{deployment_id}/reenable",
  590. },
  591. Scopes: []types.PermissionScope{
  592. types.UserScope,
  593. types.ProjectScope,
  594. types.ClusterScope,
  595. types.PreviewEnvironmentScope,
  596. },
  597. },
  598. )
  599. reenableDeploymentHandler := environment.NewReenableDeploymentHandler(
  600. config,
  601. factory.GetDecoderValidator(),
  602. factory.GetResultWriter(),
  603. )
  604. routes = append(routes, &router.Route{
  605. Endpoint: reenableDeploymentEndpoint,
  606. Handler: reenableDeploymentHandler,
  607. Router: r,
  608. })
  609. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/{deployment_id}/trigger_workflow -> environment.NewTriggerDeploymentWorkflowHandler
  610. triggerDeploymentWorkflowEndpoint := factory.NewAPIEndpoint(
  611. &types.APIRequestMetadata{
  612. Verb: types.APIVerbCreate,
  613. Method: types.HTTPVerbPost,
  614. Path: &types.Path{
  615. Parent: basePath,
  616. RelativePath: relPath + "/deployments/{deployment_id}/trigger_workflow",
  617. },
  618. Scopes: []types.PermissionScope{
  619. types.UserScope,
  620. types.ProjectScope,
  621. types.ClusterScope,
  622. types.PreviewEnvironmentScope,
  623. },
  624. },
  625. )
  626. triggerDeploymentWorkflowHandler := environment.NewTriggerDeploymentWorkflowHandler(
  627. config,
  628. factory.GetDecoderValidator(),
  629. factory.GetResultWriter(),
  630. )
  631. routes = append(routes, &router.Route{
  632. Endpoint: triggerDeploymentWorkflowEndpoint,
  633. Handler: triggerDeploymentWorkflowHandler,
  634. Router: r,
  635. })
  636. // POST /api/projects/{project_id}/clusters/{cluster_id}/deployments/pull_request -> environment.NewEnablePullRequestHandler
  637. enablePullRequestEndpoint := factory.NewAPIEndpoint(
  638. &types.APIRequestMetadata{
  639. Verb: types.APIVerbCreate,
  640. Method: types.HTTPVerbPost,
  641. Path: &types.Path{
  642. Parent: basePath,
  643. RelativePath: relPath + "/deployments/pull_request",
  644. },
  645. Scopes: []types.PermissionScope{
  646. types.UserScope,
  647. types.ProjectScope,
  648. types.ClusterScope,
  649. types.PreviewEnvironmentScope,
  650. },
  651. },
  652. )
  653. enablePullRequestHandler := environment.NewEnablePullRequestHandler(
  654. config,
  655. factory.GetDecoderValidator(),
  656. factory.GetResultWriter(),
  657. )
  658. routes = append(routes, &router.Route{
  659. Endpoint: enablePullRequestEndpoint,
  660. Handler: enablePullRequestHandler,
  661. Router: r,
  662. })
  663. // POST /api/projects/{project_id}/clusters/{cluster_id}/rename -> cluster.NewRenameClusterHandler
  664. renameClusterEndpoint := factory.NewAPIEndpoint(
  665. &types.APIRequestMetadata{
  666. Verb: types.APIVerbCreate,
  667. Method: types.HTTPVerbPost,
  668. Path: &types.Path{
  669. Parent: basePath,
  670. RelativePath: relPath + "/rename",
  671. },
  672. Scopes: []types.PermissionScope{
  673. types.UserScope,
  674. types.ProjectScope,
  675. types.ClusterScope,
  676. },
  677. },
  678. )
  679. renameClusterHandler := cluster.NewRenameClusterHandler(
  680. config,
  681. factory.GetDecoderValidator(),
  682. factory.GetResultWriter(),
  683. )
  684. routes = append(routes, &router.Route{
  685. Endpoint: renameClusterEndpoint,
  686. Handler: renameClusterHandler,
  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. return routes, newPath
  1646. }