release.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. package router
  2. import (
  3. "github.com/go-chi/chi/v5"
  4. "github.com/porter-dev/porter/api/server/handlers/release"
  5. "github.com/porter-dev/porter/api/server/shared"
  6. "github.com/porter-dev/porter/api/server/shared/config"
  7. "github.com/porter-dev/porter/api/server/shared/router"
  8. "github.com/porter-dev/porter/api/types"
  9. )
  10. func NewReleaseScopedRegisterer(children ...*router.Registerer) *router.Registerer {
  11. return &router.Registerer{
  12. GetRoutes: GetReleaseScopedRoutes,
  13. Children: children,
  14. }
  15. }
  16. func GetReleaseScopedRoutes(
  17. r chi.Router,
  18. config *config.Config,
  19. basePath *types.Path,
  20. factory shared.APIEndpointFactory,
  21. children ...*router.Registerer,
  22. ) []*router.Route {
  23. routes, projPath := getReleaseRoutes(r, config, basePath, factory)
  24. if len(children) > 0 {
  25. r.Route(projPath.RelativePath, func(r chi.Router) {
  26. for _, child := range children {
  27. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  28. routes = append(routes, childRoutes...)
  29. }
  30. })
  31. }
  32. return routes
  33. }
  34. func getReleaseRoutes(
  35. r chi.Router,
  36. config *config.Config,
  37. basePath *types.Path,
  38. factory shared.APIEndpointFactory,
  39. ) ([]*router.Route, *types.Path) {
  40. relPath := "/releases/{name}/{version}"
  41. newPath := &types.Path{
  42. Parent: basePath,
  43. RelativePath: relPath,
  44. }
  45. routes := make([]*router.Route, 0)
  46. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version} -> release.NewReleaseGetHandler
  47. getEndpoint := factory.NewAPIEndpoint(
  48. &types.APIRequestMetadata{
  49. Verb: types.APIVerbGet,
  50. Method: types.HTTPVerbGet,
  51. Path: &types.Path{
  52. Parent: basePath,
  53. RelativePath: relPath,
  54. },
  55. Scopes: []types.PermissionScope{
  56. types.UserScope,
  57. types.ProjectScope,
  58. types.ClusterScope,
  59. types.NamespaceScope,
  60. types.ReleaseScope,
  61. },
  62. },
  63. )
  64. getHandler := release.NewReleaseGetHandler(
  65. config,
  66. factory.GetResultWriter(),
  67. )
  68. routes = append(routes, &router.Route{
  69. Endpoint: getEndpoint,
  70. Handler: getHandler,
  71. Router: r,
  72. })
  73. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/form_stream -> release.NewStreamFormHandler
  74. streamFormEndpoint := factory.NewAPIEndpoint(
  75. &types.APIRequestMetadata{
  76. Verb: types.APIVerbGet,
  77. Method: types.HTTPVerbGet,
  78. Path: &types.Path{
  79. Parent: basePath,
  80. RelativePath: relPath + "/form_stream",
  81. },
  82. Scopes: []types.PermissionScope{
  83. types.UserScope,
  84. types.ProjectScope,
  85. types.ClusterScope,
  86. types.NamespaceScope,
  87. types.ReleaseScope,
  88. },
  89. IsWebsocket: true,
  90. },
  91. )
  92. streamFormHandler := release.NewStreamFormHandler(
  93. config,
  94. factory.GetDecoderValidator(),
  95. factory.GetResultWriter(),
  96. )
  97. routes = append(routes, &router.Route{
  98. Endpoint: streamFormEndpoint,
  99. Handler: streamFormHandler,
  100. Router: r,
  101. })
  102. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/controllers -> release.NewGetControllersHandler
  103. getControllersEndpoint := factory.NewAPIEndpoint(
  104. &types.APIRequestMetadata{
  105. Verb: types.APIVerbGet,
  106. Method: types.HTTPVerbGet,
  107. Path: &types.Path{
  108. Parent: basePath,
  109. RelativePath: relPath + "/controllers",
  110. },
  111. Scopes: []types.PermissionScope{
  112. types.UserScope,
  113. types.ProjectScope,
  114. types.ClusterScope,
  115. types.NamespaceScope,
  116. types.ReleaseScope,
  117. },
  118. },
  119. )
  120. getControllersHandler := release.NewGetControllersHandler(
  121. config,
  122. factory.GetResultWriter(),
  123. )
  124. routes = append(routes, &router.Route{
  125. Endpoint: getControllersEndpoint,
  126. Handler: getControllersHandler,
  127. Router: r,
  128. })
  129. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/components -> release.NewGetComponentsHandler
  130. getComponentsEndpoint := factory.NewAPIEndpoint(
  131. &types.APIRequestMetadata{
  132. Verb: types.APIVerbGet,
  133. Method: types.HTTPVerbGet,
  134. Path: &types.Path{
  135. Parent: basePath,
  136. RelativePath: relPath + "/components",
  137. },
  138. Scopes: []types.PermissionScope{
  139. types.UserScope,
  140. types.ProjectScope,
  141. types.ClusterScope,
  142. types.NamespaceScope,
  143. types.ReleaseScope,
  144. },
  145. },
  146. )
  147. getComponentsHandler := release.NewGetComponentsHandler(
  148. config,
  149. factory.GetResultWriter(),
  150. )
  151. routes = append(routes, &router.Route{
  152. Endpoint: getComponentsEndpoint,
  153. Handler: getComponentsHandler,
  154. Router: r,
  155. })
  156. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/history -> release.NewGetHistoryHandler
  157. getHistoryEndpoint := factory.NewAPIEndpoint(
  158. &types.APIRequestMetadata{
  159. Verb: types.APIVerbGet,
  160. Method: types.HTTPVerbGet,
  161. Path: &types.Path{
  162. Parent: basePath,
  163. RelativePath: "/releases/{name}/history",
  164. },
  165. Scopes: []types.PermissionScope{
  166. types.UserScope,
  167. types.ProjectScope,
  168. types.ClusterScope,
  169. types.NamespaceScope,
  170. },
  171. },
  172. )
  173. getHistoryHandler := release.NewGetReleaseHistoryHandler(
  174. config,
  175. factory.GetDecoderValidator(),
  176. factory.GetResultWriter(),
  177. )
  178. routes = append(routes, &router.Route{
  179. Endpoint: getHistoryEndpoint,
  180. Handler: getHistoryHandler,
  181. Router: r,
  182. })
  183. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/pods/all -> release.NewGetAllPodsHandler
  184. getAllPodsEndpoint := factory.NewAPIEndpoint(
  185. &types.APIRequestMetadata{
  186. Verb: types.APIVerbGet,
  187. Method: types.HTTPVerbGet,
  188. Path: &types.Path{
  189. Parent: basePath,
  190. RelativePath: relPath + "/pods/all",
  191. },
  192. Scopes: []types.PermissionScope{
  193. types.UserScope,
  194. types.ProjectScope,
  195. types.ClusterScope,
  196. types.NamespaceScope,
  197. types.ReleaseScope,
  198. },
  199. },
  200. )
  201. getAllPodsHandler := release.NewGetAllPodsHandler(
  202. config,
  203. factory.GetResultWriter(),
  204. )
  205. routes = append(routes, &router.Route{
  206. Endpoint: getAllPodsEndpoint,
  207. Handler: getAllPodsHandler,
  208. Router: r,
  209. })
  210. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/notifications -> release.NewUpdateNotificationHandler
  211. updateNotifsEndpoint := factory.NewAPIEndpoint(
  212. &types.APIRequestMetadata{
  213. Verb: types.APIVerbUpdate,
  214. Method: types.HTTPVerbPost,
  215. Path: &types.Path{
  216. Parent: basePath,
  217. RelativePath: "/releases/{name}/notifications",
  218. },
  219. Scopes: []types.PermissionScope{
  220. types.UserScope,
  221. types.ProjectScope,
  222. types.ClusterScope,
  223. types.NamespaceScope,
  224. },
  225. },
  226. )
  227. updateNotifsHandler := release.NewUpdateNotificationHandler(
  228. config,
  229. factory.GetDecoderValidator(),
  230. factory.GetResultWriter(),
  231. )
  232. routes = append(routes, &router.Route{
  233. Endpoint: updateNotifsEndpoint,
  234. Handler: updateNotifsHandler,
  235. Router: r,
  236. })
  237. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/notifications -> release.NewGetNotificationHandler
  238. getNotifsEndpoint := factory.NewAPIEndpoint(
  239. &types.APIRequestMetadata{
  240. Verb: types.APIVerbGet,
  241. Method: types.HTTPVerbGet,
  242. Path: &types.Path{
  243. Parent: basePath,
  244. RelativePath: "/releases/{name}/notifications",
  245. },
  246. Scopes: []types.PermissionScope{
  247. types.UserScope,
  248. types.ProjectScope,
  249. types.ClusterScope,
  250. types.NamespaceScope,
  251. },
  252. },
  253. )
  254. getNotifsHandler := release.NewGetNotificationHandler(
  255. config,
  256. factory.GetResultWriter(),
  257. )
  258. routes = append(routes, &router.Route{
  259. Endpoint: getNotifsEndpoint,
  260. Handler: getNotifsHandler,
  261. Router: r,
  262. })
  263. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/buildconfig -> release.NewUpdateBuildConfigHandler
  264. updateBuildConfigEndpoint := factory.NewAPIEndpoint(
  265. &types.APIRequestMetadata{
  266. Verb: types.APIVerbUpdate,
  267. Method: types.HTTPVerbPost,
  268. Path: &types.Path{
  269. Parent: basePath,
  270. RelativePath: "/releases/{name}/buildconfig",
  271. },
  272. Scopes: []types.PermissionScope{
  273. types.UserScope,
  274. types.ProjectScope,
  275. types.ClusterScope,
  276. types.NamespaceScope,
  277. },
  278. },
  279. )
  280. updateBuildConfigHandler := release.NewUpdateBuildConfigHandler(
  281. config,
  282. factory.GetDecoderValidator(),
  283. factory.GetResultWriter(),
  284. )
  285. routes = append(routes, &router.Route{
  286. Endpoint: updateBuildConfigEndpoint,
  287. Handler: updateBuildConfigHandler,
  288. Router: r,
  289. })
  290. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/webhook -> release.NewGetWebhookHandler
  291. getWebhookEndpoint := factory.NewAPIEndpoint(
  292. &types.APIRequestMetadata{
  293. Verb: types.APIVerbGet,
  294. Method: types.HTTPVerbGet,
  295. Path: &types.Path{
  296. Parent: basePath,
  297. RelativePath: "/releases/{name}/webhook",
  298. },
  299. Scopes: []types.PermissionScope{
  300. types.UserScope,
  301. types.ProjectScope,
  302. types.ClusterScope,
  303. types.NamespaceScope,
  304. },
  305. },
  306. )
  307. getWebhookHandler := release.NewGetWebhookHandler(
  308. config,
  309. factory.GetResultWriter(),
  310. )
  311. routes = append(routes, &router.Route{
  312. Endpoint: getWebhookEndpoint,
  313. Handler: getWebhookHandler,
  314. Router: r,
  315. })
  316. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/webhook -> release.NewCreateWebhookHandler
  317. createWebhookEndpoint := factory.NewAPIEndpoint(
  318. &types.APIRequestMetadata{
  319. Verb: types.APIVerbCreate,
  320. Method: types.HTTPVerbPost,
  321. Path: &types.Path{
  322. Parent: basePath,
  323. RelativePath: relPath + "/webhook",
  324. },
  325. Scopes: []types.PermissionScope{
  326. types.UserScope,
  327. types.ProjectScope,
  328. types.ClusterScope,
  329. types.NamespaceScope,
  330. types.ReleaseScope,
  331. },
  332. },
  333. )
  334. createWebhookHandler := release.NewCreateWebhookHandler(
  335. config,
  336. factory.GetResultWriter(),
  337. )
  338. routes = append(routes, &router.Route{
  339. Endpoint: createWebhookEndpoint,
  340. Handler: createWebhookHandler,
  341. Router: r,
  342. })
  343. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/steps -> release.NewGetReleaseStepsHandler
  344. getStepsEndpoint := factory.NewAPIEndpoint(
  345. &types.APIRequestMetadata{
  346. Verb: types.APIVerbGet,
  347. Method: types.HTTPVerbGet,
  348. Path: &types.Path{
  349. Parent: basePath,
  350. RelativePath: "/releases/{name}/steps",
  351. },
  352. Scopes: []types.PermissionScope{
  353. types.UserScope,
  354. types.ProjectScope,
  355. types.ClusterScope,
  356. types.NamespaceScope,
  357. },
  358. },
  359. )
  360. getStepsHandler := release.NewGetReleaseStepsHandler(
  361. config,
  362. factory.GetDecoderValidator(),
  363. factory.GetResultWriter(),
  364. )
  365. routes = append(routes, &router.Route{
  366. Endpoint: getStepsEndpoint,
  367. Handler: getStepsHandler,
  368. Router: r,
  369. })
  370. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/steps -> release.NewUpdateReleaseStepsHandler
  371. updateStepsEndpoint := factory.NewAPIEndpoint(
  372. &types.APIRequestMetadata{
  373. Verb: types.APIVerbCreate,
  374. Method: types.HTTPVerbPost,
  375. Path: &types.Path{
  376. Parent: basePath,
  377. RelativePath: "/releases/{name}/steps",
  378. },
  379. Scopes: []types.PermissionScope{
  380. types.UserScope,
  381. types.ProjectScope,
  382. types.ClusterScope,
  383. types.NamespaceScope,
  384. },
  385. },
  386. )
  387. updateStepsHandler := release.NewUpdateReleaseStepsHandler(
  388. config,
  389. factory.GetDecoderValidator(),
  390. factory.GetResultWriter(),
  391. )
  392. routes = append(routes, &router.Route{
  393. Endpoint: updateStepsEndpoint,
  394. Handler: updateStepsHandler,
  395. Router: r,
  396. })
  397. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases -> release.NewCreateReleaseHandler
  398. createReleaseEndpoint := factory.NewAPIEndpoint(
  399. &types.APIRequestMetadata{
  400. Verb: types.APIVerbCreate,
  401. Method: types.HTTPVerbPost,
  402. Path: &types.Path{
  403. Parent: basePath,
  404. RelativePath: "/releases",
  405. },
  406. Scopes: []types.PermissionScope{
  407. types.UserScope,
  408. types.ProjectScope,
  409. types.ClusterScope,
  410. types.NamespaceScope,
  411. },
  412. },
  413. )
  414. createReleaseHandler := release.NewCreateReleaseHandler(
  415. config,
  416. factory.GetDecoderValidator(),
  417. factory.GetResultWriter(),
  418. )
  419. routes = append(routes, &router.Route{
  420. Endpoint: createReleaseEndpoint,
  421. Handler: createReleaseHandler,
  422. Router: r,
  423. })
  424. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/addons -> release.NewCreateAddonHandler
  425. createAddonEndpoint := factory.NewAPIEndpoint(
  426. &types.APIRequestMetadata{
  427. Verb: types.APIVerbCreate,
  428. Method: types.HTTPVerbPost,
  429. Path: &types.Path{
  430. Parent: basePath,
  431. RelativePath: "/addons",
  432. },
  433. Scopes: []types.PermissionScope{
  434. types.UserScope,
  435. types.ProjectScope,
  436. types.ClusterScope,
  437. types.NamespaceScope,
  438. },
  439. },
  440. )
  441. createAddonHandler := release.NewCreateAddonHandler(
  442. config,
  443. factory.GetDecoderValidator(),
  444. factory.GetResultWriter(),
  445. )
  446. routes = append(routes, &router.Route{
  447. Endpoint: createAddonEndpoint,
  448. Handler: createAddonHandler,
  449. Router: r,
  450. })
  451. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/gha_template -> release.NewGetGHATemplateHandler
  452. getGHATemplateEndpoint := factory.NewAPIEndpoint(
  453. &types.APIRequestMetadata{
  454. Verb: types.APIVerbGet,
  455. Method: types.HTTPVerbPost,
  456. Path: &types.Path{
  457. Parent: basePath,
  458. RelativePath: "/releases/gha_template",
  459. },
  460. Scopes: []types.PermissionScope{
  461. types.UserScope,
  462. types.ProjectScope,
  463. types.ClusterScope,
  464. types.NamespaceScope,
  465. },
  466. },
  467. )
  468. getGHATemplateHandler := release.NewGetGHATemplateHandler(
  469. config,
  470. factory.GetDecoderValidator(),
  471. factory.GetResultWriter(),
  472. )
  473. routes = append(routes, &router.Route{
  474. Endpoint: getGHATemplateEndpoint,
  475. Handler: getGHATemplateHandler,
  476. Router: r,
  477. })
  478. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/rollback ->
  479. // release.NewRollbackReleaseHandler
  480. rollbackEndpoint := factory.NewAPIEndpoint(
  481. &types.APIRequestMetadata{
  482. Verb: types.APIVerbUpdate,
  483. Method: types.HTTPVerbPost,
  484. Path: &types.Path{
  485. Parent: basePath,
  486. RelativePath: relPath + "/rollback",
  487. },
  488. Scopes: []types.PermissionScope{
  489. types.UserScope,
  490. types.ProjectScope,
  491. types.ClusterScope,
  492. types.NamespaceScope,
  493. types.ReleaseScope,
  494. },
  495. },
  496. )
  497. rollbackHandler := release.NewRollbackReleaseHandler(
  498. config,
  499. factory.GetDecoderValidator(),
  500. factory.GetResultWriter(),
  501. )
  502. routes = append(routes, &router.Route{
  503. Endpoint: rollbackEndpoint,
  504. Handler: rollbackHandler,
  505. Router: r,
  506. })
  507. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/upgrade ->
  508. // release.NewUpgradeReleaseHandler
  509. upgradeEndpoint := factory.NewAPIEndpoint(
  510. &types.APIRequestMetadata{
  511. Verb: types.APIVerbUpdate,
  512. Method: types.HTTPVerbPost,
  513. Path: &types.Path{
  514. Parent: basePath,
  515. RelativePath: relPath + "/upgrade",
  516. },
  517. Scopes: []types.PermissionScope{
  518. types.UserScope,
  519. types.ProjectScope,
  520. types.ClusterScope,
  521. types.NamespaceScope,
  522. types.ReleaseScope,
  523. },
  524. },
  525. )
  526. upgradeHandler := release.NewUpgradeReleaseHandler(
  527. config,
  528. factory.GetDecoderValidator(),
  529. factory.GetResultWriter(),
  530. )
  531. routes = append(routes, &router.Route{
  532. Endpoint: upgradeEndpoint,
  533. Handler: upgradeHandler,
  534. Router: r,
  535. })
  536. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version} ->
  537. // release.NewDeleteReleaseHandler
  538. deleteEndpoint := factory.NewAPIEndpoint(
  539. &types.APIRequestMetadata{
  540. Verb: types.APIVerbDelete,
  541. Method: types.HTTPVerbDelete,
  542. Path: &types.Path{
  543. Parent: basePath,
  544. RelativePath: relPath,
  545. },
  546. Scopes: []types.PermissionScope{
  547. types.UserScope,
  548. types.ProjectScope,
  549. types.ClusterScope,
  550. types.NamespaceScope,
  551. types.ReleaseScope,
  552. },
  553. },
  554. )
  555. deleteHandler := release.NewDeleteReleaseHandler(
  556. config,
  557. factory.GetDecoderValidator(),
  558. factory.GetResultWriter(),
  559. )
  560. routes = append(routes, &router.Route{
  561. Endpoint: deleteEndpoint,
  562. Handler: deleteHandler,
  563. Router: r,
  564. })
  565. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/image/batch ->
  566. // release.NewUpdateImageBatchHandler
  567. updateImageBatchEndpoint := factory.NewAPIEndpoint(
  568. &types.APIRequestMetadata{
  569. Verb: types.APIVerbUpdate,
  570. Method: types.HTTPVerbPost,
  571. Path: &types.Path{
  572. Parent: basePath,
  573. RelativePath: "/releases/image/batch",
  574. },
  575. Scopes: []types.PermissionScope{
  576. types.UserScope,
  577. types.ProjectScope,
  578. types.ClusterScope,
  579. types.NamespaceScope,
  580. },
  581. },
  582. )
  583. updateImageBatchHandler := release.NewUpdateImageBatchHandler(
  584. config,
  585. factory.GetDecoderValidator(),
  586. factory.GetResultWriter(),
  587. )
  588. routes = append(routes, &router.Route{
  589. Endpoint: updateImageBatchEndpoint,
  590. Handler: updateImageBatchHandler,
  591. Router: r,
  592. })
  593. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/jobs ->
  594. // release.NewGetJobsHandler
  595. getJobsEndpoint := factory.NewAPIEndpoint(
  596. &types.APIRequestMetadata{
  597. Verb: types.APIVerbGet,
  598. Method: types.HTTPVerbGet,
  599. Path: &types.Path{
  600. Parent: basePath,
  601. RelativePath: relPath + "/jobs",
  602. },
  603. Scopes: []types.PermissionScope{
  604. types.UserScope,
  605. types.ProjectScope,
  606. types.ClusterScope,
  607. types.NamespaceScope,
  608. types.ReleaseScope,
  609. },
  610. },
  611. )
  612. getJobsHandler := release.NewGetJobsHandler(
  613. config,
  614. factory.GetDecoderValidator(),
  615. factory.GetResultWriter(),
  616. )
  617. routes = append(routes, &router.Route{
  618. Endpoint: getJobsEndpoint,
  619. Handler: getJobsHandler,
  620. Router: r,
  621. })
  622. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/latest_job_run ->
  623. // release.NewGetLatestJobRunHandler
  624. getLatestJobRunEndpoint := factory.NewAPIEndpoint(
  625. &types.APIRequestMetadata{
  626. Verb: types.APIVerbGet,
  627. Method: types.HTTPVerbGet,
  628. Path: &types.Path{
  629. Parent: basePath,
  630. RelativePath: relPath + "/latest_job_run",
  631. },
  632. Scopes: []types.PermissionScope{
  633. types.UserScope,
  634. types.ProjectScope,
  635. types.ClusterScope,
  636. types.NamespaceScope,
  637. types.ReleaseScope,
  638. },
  639. },
  640. )
  641. getLatestJobRunHandler := release.NewGetLatestJobRunHandler(
  642. config,
  643. factory.GetResultWriter(),
  644. )
  645. routes = append(routes, &router.Route{
  646. Endpoint: getLatestJobRunEndpoint,
  647. Handler: getLatestJobRunHandler,
  648. Router: r,
  649. })
  650. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/jobs/status ->
  651. // release.NewGetJobsHandler
  652. getJobsStatusEndpoint := factory.NewAPIEndpoint(
  653. &types.APIRequestMetadata{
  654. Verb: types.APIVerbGet,
  655. Method: types.HTTPVerbGet,
  656. Path: &types.Path{
  657. Parent: basePath,
  658. RelativePath: relPath + "/jobs/status",
  659. },
  660. Scopes: []types.PermissionScope{
  661. types.UserScope,
  662. types.ProjectScope,
  663. types.ClusterScope,
  664. types.NamespaceScope,
  665. types.ReleaseScope,
  666. },
  667. },
  668. )
  669. getJobsStatusHandler := release.NewGetJobsStatusHandler(
  670. config,
  671. factory.GetResultWriter(),
  672. )
  673. routes = append(routes, &router.Route{
  674. Endpoint: getJobsStatusEndpoint,
  675. Handler: getJobsStatusHandler,
  676. Router: r,
  677. })
  678. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/subdomain -> release.NewCreateSubdomainHandler
  679. createSubdomainEndpoint := factory.NewAPIEndpoint(
  680. &types.APIRequestMetadata{
  681. Verb: types.APIVerbCreate,
  682. Method: types.HTTPVerbPost,
  683. Path: &types.Path{
  684. Parent: basePath,
  685. RelativePath: "/releases/{name}/subdomain",
  686. },
  687. Scopes: []types.PermissionScope{
  688. types.UserScope,
  689. types.ProjectScope,
  690. types.ClusterScope,
  691. types.NamespaceScope,
  692. },
  693. },
  694. )
  695. createSubdomainHandler := release.NewCreateSubdomainHandler(
  696. config,
  697. factory.GetResultWriter(),
  698. )
  699. routes = append(routes, &router.Route{
  700. Endpoint: createSubdomainEndpoint,
  701. Handler: createSubdomainHandler,
  702. Router: r,
  703. })
  704. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/update_tags -> release.NewUpdateReleaseTagsHandler
  705. updateReleaseTagsEndpoint := factory.NewAPIEndpoint(
  706. &types.APIRequestMetadata{
  707. Verb: types.APIVerbUpdate,
  708. Method: types.HTTPVerbPatch,
  709. Path: &types.Path{
  710. Parent: basePath,
  711. RelativePath: relPath + "/update_tags",
  712. },
  713. Scopes: []types.PermissionScope{
  714. types.UserScope,
  715. types.ProjectScope,
  716. types.ClusterScope,
  717. types.NamespaceScope,
  718. types.ReleaseScope,
  719. },
  720. },
  721. )
  722. updateReleaseTagsHandler := release.NewUpdateReleaseTagsHandler(
  723. config,
  724. factory.GetDecoderValidator(),
  725. factory.GetResultWriter(),
  726. )
  727. routes = append(routes, &router.Route{
  728. Endpoint: updateReleaseTagsEndpoint,
  729. Handler: updateReleaseTagsHandler,
  730. Router: r,
  731. })
  732. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/update_canonical_name -> release.NewUpdateCanonicalNameHandler
  733. updateCanonicalNameEndpoint := factory.NewAPIEndpoint(
  734. &types.APIRequestMetadata{
  735. Verb: types.APIVerbUpdate,
  736. Method: types.HTTPVerbPatch,
  737. Path: &types.Path{
  738. Parent: basePath,
  739. RelativePath: relPath + "/update_canonical_name",
  740. },
  741. Scopes: []types.PermissionScope{
  742. types.UserScope,
  743. types.ProjectScope,
  744. types.ClusterScope,
  745. types.NamespaceScope,
  746. types.ReleaseScope,
  747. },
  748. },
  749. )
  750. updateCanonicalNameHandler := release.NewUpdateCanonicalNameHandler(
  751. config,
  752. factory.GetDecoderValidator(),
  753. factory.GetResultWriter(),
  754. )
  755. routes = append(routes, &router.Route{
  756. Endpoint: updateCanonicalNameEndpoint,
  757. Handler: updateCanonicalNameHandler,
  758. Router: r,
  759. })
  760. // PATCH /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/git_action_config -> release.NewUpdateGitActionConfigHandler
  761. updateGitActionConfigEndpoint := factory.NewAPIEndpoint(
  762. &types.APIRequestMetadata{
  763. Verb: types.APIVerbUpdate,
  764. Method: types.HTTPVerbPatch,
  765. Path: &types.Path{
  766. Parent: basePath,
  767. RelativePath: "/releases/{name}/{version}/git_action_config",
  768. },
  769. Scopes: []types.PermissionScope{
  770. types.UserScope,
  771. types.ProjectScope,
  772. types.ClusterScope,
  773. types.NamespaceScope,
  774. types.ReleaseScope,
  775. },
  776. },
  777. )
  778. updateGitActionConfigHandler := release.NewUpdateGitActionConfigHandler(
  779. config,
  780. factory.GetDecoderValidator(),
  781. factory.GetResultWriter(),
  782. )
  783. routes = append(routes, &router.Route{
  784. Endpoint: updateGitActionConfigEndpoint,
  785. Handler: updateGitActionConfigHandler,
  786. Router: r,
  787. })
  788. return routes, newPath
  789. }