cluster.go 42 KB

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