cluster.go 45 KB

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