release.go 19 KB

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