project.go 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  1. package router
  2. import (
  3. "fmt"
  4. "github.com/go-chi/chi"
  5. "github.com/porter-dev/porter/api/server/handlers/api_token"
  6. "github.com/porter-dev/porter/api/server/handlers/billing"
  7. "github.com/porter-dev/porter/api/server/handlers/cluster"
  8. "github.com/porter-dev/porter/api/server/handlers/gitinstallation"
  9. "github.com/porter-dev/porter/api/server/handlers/helmrepo"
  10. "github.com/porter-dev/porter/api/server/handlers/infra"
  11. "github.com/porter-dev/porter/api/server/handlers/policy"
  12. "github.com/porter-dev/porter/api/server/handlers/project"
  13. "github.com/porter-dev/porter/api/server/handlers/registry"
  14. "github.com/porter-dev/porter/api/server/shared"
  15. "github.com/porter-dev/porter/api/server/shared/config"
  16. "github.com/porter-dev/porter/api/server/shared/router"
  17. "github.com/porter-dev/porter/api/types"
  18. )
  19. func NewProjectScopedRegisterer(children ...*router.Registerer) *router.Registerer {
  20. return &router.Registerer{
  21. GetRoutes: GetProjectScopedRoutes,
  22. Children: children,
  23. }
  24. }
  25. func GetProjectScopedRoutes(
  26. r chi.Router,
  27. config *config.Config,
  28. basePath *types.Path,
  29. factory shared.APIEndpointFactory,
  30. children ...*router.Registerer,
  31. ) []*router.Route {
  32. routes, projPath := getProjectRoutes(r, config, basePath, factory)
  33. if len(children) > 0 {
  34. r.Route(projPath.RelativePath, func(r chi.Router) {
  35. for _, child := range children {
  36. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  37. routes = append(routes, childRoutes...)
  38. }
  39. })
  40. }
  41. return routes
  42. }
  43. func getProjectRoutes(
  44. r chi.Router,
  45. config *config.Config,
  46. basePath *types.Path,
  47. factory shared.APIEndpointFactory,
  48. ) ([]*router.Route, *types.Path) {
  49. relPath := "/projects/{project_id}"
  50. newPath := &types.Path{
  51. Parent: basePath,
  52. RelativePath: relPath,
  53. }
  54. routes := make([]*router.Route, 0)
  55. // GET /api/projects/{project_id} -> project.NewProjectGetHandler
  56. getEndpoint := factory.NewAPIEndpoint(
  57. &types.APIRequestMetadata{
  58. Verb: types.APIVerbGet,
  59. Method: types.HTTPVerbGet,
  60. Path: &types.Path{
  61. Parent: basePath,
  62. RelativePath: relPath,
  63. },
  64. Scopes: []types.PermissionScope{
  65. types.UserScope,
  66. types.ProjectScope,
  67. },
  68. },
  69. )
  70. getHandler := project.NewProjectGetHandler(
  71. config,
  72. factory.GetResultWriter(),
  73. )
  74. routes = append(routes, &router.Route{
  75. Endpoint: getEndpoint,
  76. Handler: getHandler,
  77. Router: r,
  78. })
  79. // DELETE /api/projects/{project_id} -> project.NewProjectDeleteHandler
  80. deleteEndpoint := factory.NewAPIEndpoint(
  81. &types.APIRequestMetadata{
  82. Verb: types.APIVerbDelete,
  83. Method: types.HTTPVerbDelete,
  84. Path: &types.Path{
  85. Parent: basePath,
  86. RelativePath: relPath,
  87. },
  88. Scopes: []types.PermissionScope{
  89. types.UserScope,
  90. types.ProjectScope,
  91. },
  92. },
  93. )
  94. deleteHandler := project.NewProjectDeleteHandler(
  95. config,
  96. factory.GetResultWriter(),
  97. )
  98. routes = append(routes, &router.Route{
  99. Endpoint: deleteEndpoint,
  100. Handler: deleteHandler,
  101. Router: r,
  102. })
  103. // GET /api/projects/{project_id}/policy -> project.NewProjectGetPolicyHandler
  104. getPolicyEndpoint := factory.NewAPIEndpoint(
  105. &types.APIRequestMetadata{
  106. Verb: types.APIVerbGet,
  107. Method: types.HTTPVerbGet,
  108. Path: &types.Path{
  109. Parent: basePath,
  110. RelativePath: relPath + "/policy",
  111. },
  112. Scopes: []types.PermissionScope{
  113. types.UserScope,
  114. types.ProjectScope,
  115. },
  116. },
  117. )
  118. getPolicyHandler := project.NewProjectGetPolicyHandler(
  119. config,
  120. factory.GetResultWriter(),
  121. )
  122. routes = append(routes, &router.Route{
  123. Endpoint: getPolicyEndpoint,
  124. Handler: getPolicyHandler,
  125. Router: r,
  126. })
  127. // GET /api/projects/{project_id}/onboarding -> project.NewProjectGetOnboardingHandler
  128. getOnboardingEndpoint := factory.NewAPIEndpoint(
  129. &types.APIRequestMetadata{
  130. Verb: types.APIVerbGet,
  131. Method: types.HTTPVerbGet,
  132. Path: &types.Path{
  133. Parent: basePath,
  134. RelativePath: relPath + "/onboarding",
  135. },
  136. Scopes: []types.PermissionScope{
  137. types.UserScope,
  138. types.ProjectScope,
  139. },
  140. },
  141. )
  142. getOnboardingHandler := project.NewOnboardingGetHandler(
  143. config,
  144. factory.GetDecoderValidator(),
  145. factory.GetResultWriter(),
  146. )
  147. routes = append(routes, &router.Route{
  148. Endpoint: getOnboardingEndpoint,
  149. Handler: getOnboardingHandler,
  150. Router: r,
  151. })
  152. // POST /api/projects/{project_id}/onboarding -> project.NewProjectGetOnboardingHandler
  153. updateOnboardingEndpoint := factory.NewAPIEndpoint(
  154. &types.APIRequestMetadata{
  155. Verb: types.APIVerbUpdate,
  156. Method: types.HTTPVerbPost,
  157. Path: &types.Path{
  158. Parent: basePath,
  159. RelativePath: relPath + "/onboarding",
  160. },
  161. Scopes: []types.PermissionScope{
  162. types.UserScope,
  163. types.ProjectScope,
  164. },
  165. },
  166. )
  167. updateOnboardingHandler := project.NewOnboardingUpdateHandler(
  168. config,
  169. factory.GetDecoderValidator(),
  170. factory.GetResultWriter(),
  171. )
  172. routes = append(routes, &router.Route{
  173. Endpoint: updateOnboardingEndpoint,
  174. Handler: updateOnboardingHandler,
  175. Router: r,
  176. })
  177. // GET /api/projects/{project_id}/usage -> project.NewProjectGetUsageHandler
  178. getUsageEndpoint := factory.NewAPIEndpoint(
  179. &types.APIRequestMetadata{
  180. Verb: types.APIVerbGet,
  181. Method: types.HTTPVerbGet,
  182. Path: &types.Path{
  183. Parent: basePath,
  184. RelativePath: relPath + "/usage",
  185. },
  186. Scopes: []types.PermissionScope{
  187. types.UserScope,
  188. types.ProjectScope,
  189. },
  190. },
  191. )
  192. getUsageHandler := project.NewProjectGetUsageHandler(
  193. config,
  194. factory.GetResultWriter(),
  195. )
  196. routes = append(routes, &router.Route{
  197. Endpoint: getUsageEndpoint,
  198. Handler: getUsageHandler,
  199. Router: r,
  200. })
  201. // GET /api/project/{project_id}/billing/redirect -> billing.NewRedirectBillingHandler
  202. redirectBillingEndpoint := factory.NewAPIEndpoint(
  203. &types.APIRequestMetadata{
  204. Verb: types.APIVerbGet,
  205. Method: types.HTTPVerbGet,
  206. Path: &types.Path{
  207. Parent: basePath,
  208. RelativePath: relPath + "/billing/redirect",
  209. },
  210. Scopes: []types.PermissionScope{
  211. types.UserScope,
  212. types.ProjectScope,
  213. },
  214. },
  215. )
  216. redirectBillingHandler := billing.NewRedirectBillingHandler(
  217. config,
  218. factory.GetResultWriter(),
  219. )
  220. routes = append(routes, &router.Route{
  221. Endpoint: redirectBillingEndpoint,
  222. Handler: redirectBillingHandler,
  223. Router: r,
  224. })
  225. // GET /api/projects/{project_id}/billing -> project.NewProjectGetBillingHandler
  226. getBillingEndpoint := factory.NewAPIEndpoint(
  227. &types.APIRequestMetadata{
  228. Verb: types.APIVerbGet,
  229. Method: types.HTTPVerbGet,
  230. Path: &types.Path{
  231. Parent: basePath,
  232. RelativePath: relPath + "/billing",
  233. },
  234. Scopes: []types.PermissionScope{
  235. types.UserScope,
  236. types.ProjectScope,
  237. },
  238. },
  239. )
  240. getBillingHandler := project.NewProjectGetBillingHandler(
  241. config,
  242. factory.GetResultWriter(),
  243. )
  244. routes = append(routes, &router.Route{
  245. Endpoint: getBillingEndpoint,
  246. Handler: getBillingHandler,
  247. Router: r,
  248. })
  249. // GET /api/billing_webhook -> billing.NewBillingWebhookHandler
  250. getBillingWebhookEndpoint := factory.NewAPIEndpoint(
  251. &types.APIRequestMetadata{
  252. Verb: types.APIVerbCreate,
  253. Method: types.HTTPVerbPost,
  254. Path: &types.Path{
  255. Parent: basePath,
  256. RelativePath: "/billing_webhook",
  257. },
  258. Scopes: []types.PermissionScope{},
  259. },
  260. )
  261. getBillingWebhookHandler := billing.NewBillingWebhookHandler(
  262. config,
  263. factory.GetDecoderValidator(),
  264. )
  265. routes = append(routes, &router.Route{
  266. Endpoint: getBillingWebhookEndpoint,
  267. Handler: getBillingWebhookHandler,
  268. Router: r,
  269. })
  270. // GET /api/projects/{project_id}/clusters -> cluster.NewClusterListHandler
  271. listClusterEndpoint := factory.NewAPIEndpoint(
  272. &types.APIRequestMetadata{
  273. Verb: types.APIVerbList,
  274. Method: types.HTTPVerbGet,
  275. Path: &types.Path{
  276. Parent: basePath,
  277. RelativePath: relPath + "/clusters",
  278. },
  279. Scopes: []types.PermissionScope{
  280. types.UserScope,
  281. types.ProjectScope,
  282. },
  283. },
  284. )
  285. listClusterHandler := cluster.NewClusterListHandler(
  286. config,
  287. factory.GetResultWriter(),
  288. )
  289. routes = append(routes, &router.Route{
  290. Endpoint: listClusterEndpoint,
  291. Handler: listClusterHandler,
  292. Router: r,
  293. })
  294. // GET /api/projects/{project_id}/gitrepos -> gitinstallation.NewGitRepoListHandler
  295. listGitReposEndpoint := factory.NewAPIEndpoint(
  296. &types.APIRequestMetadata{
  297. Verb: types.APIVerbList,
  298. Method: types.HTTPVerbGet,
  299. Path: &types.Path{
  300. Parent: basePath,
  301. RelativePath: relPath + "/gitrepos",
  302. },
  303. Scopes: []types.PermissionScope{
  304. types.UserScope,
  305. types.ProjectScope,
  306. },
  307. },
  308. )
  309. listGitReposHandler := gitinstallation.NewGitRepoListHandler(
  310. config,
  311. factory.GetResultWriter(),
  312. )
  313. routes = append(routes, &router.Route{
  314. Endpoint: listGitReposEndpoint,
  315. Handler: listGitReposHandler,
  316. Router: r,
  317. })
  318. // GET /api/projects/{project_id}/collaborators -> project.NewCollaboratorsListHandler
  319. listCollaboratorsEndpoint := factory.NewAPIEndpoint(
  320. &types.APIRequestMetadata{
  321. Verb: types.APIVerbList,
  322. Method: types.HTTPVerbGet,
  323. Path: &types.Path{
  324. Parent: basePath,
  325. RelativePath: relPath + "/collaborators",
  326. },
  327. Scopes: []types.PermissionScope{
  328. types.UserScope,
  329. types.ProjectScope,
  330. },
  331. },
  332. )
  333. listCollaboratorsHandler := project.NewCollaboratorsListHandler(
  334. config,
  335. factory.GetResultWriter(),
  336. )
  337. routes = append(routes, &router.Route{
  338. Endpoint: listCollaboratorsEndpoint,
  339. Handler: listCollaboratorsHandler,
  340. Router: r,
  341. })
  342. // PATCH /api/projects/{project_id}/collaborators/{user_id} -> project.UpdateCollaboratorWithRolesHandler
  343. updateCollaboratorRolesEndpoint := factory.NewAPIEndpoint(
  344. &types.APIRequestMetadata{
  345. Verb: types.APIVerbUpdate,
  346. Method: types.HTTPVerbPatch,
  347. Path: &types.Path{
  348. Parent: basePath,
  349. RelativePath: relPath + "/collaborators/{user_id}",
  350. },
  351. Scopes: []types.PermissionScope{
  352. types.UserScope,
  353. types.ProjectScope,
  354. types.SettingsScope,
  355. },
  356. },
  357. )
  358. updateCollaboratorRolesHandler := project.NewUpdateCollaboratorRolesHandler(
  359. config,
  360. factory.GetDecoderValidator(),
  361. factory.GetResultWriter(),
  362. )
  363. routes = append(routes, &router.Route{
  364. Endpoint: updateCollaboratorRolesEndpoint,
  365. Handler: updateCollaboratorRolesHandler,
  366. Router: r,
  367. })
  368. // GET /api/projects/{project_id}/roles -> project.NewRolesListHandler
  369. listRolesEndpoint := factory.NewAPIEndpoint(
  370. &types.APIRequestMetadata{
  371. Verb: types.APIVerbList,
  372. Method: types.HTTPVerbGet,
  373. Path: &types.Path{
  374. Parent: basePath,
  375. RelativePath: relPath + "/roles",
  376. },
  377. Scopes: []types.PermissionScope{
  378. types.UserScope,
  379. types.ProjectScope,
  380. },
  381. },
  382. )
  383. listRolesHandler := project.NewRolesListHandler(
  384. config,
  385. factory.GetResultWriter(),
  386. )
  387. routes = append(routes, &router.Route{
  388. Endpoint: listRolesEndpoint,
  389. Handler: listRolesHandler,
  390. Router: r,
  391. })
  392. // POST /api/projects/{project_id}/roles -> project.NewRoleUpdateHandler
  393. updateRoleEndpoint := factory.NewAPIEndpoint(
  394. &types.APIRequestMetadata{
  395. Verb: types.APIVerbUpdate,
  396. Method: types.HTTPVerbPost,
  397. Path: &types.Path{
  398. Parent: basePath,
  399. RelativePath: relPath + "/roles",
  400. },
  401. Scopes: []types.PermissionScope{
  402. types.UserScope,
  403. types.ProjectScope,
  404. },
  405. },
  406. )
  407. updateRoleHandler := project.NewRoleUpdateHandler(
  408. config,
  409. factory.GetDecoderValidator(),
  410. factory.GetResultWriter(),
  411. )
  412. routes = append(routes, &router.Route{
  413. Endpoint: updateRoleEndpoint,
  414. Handler: updateRoleHandler,
  415. Router: r,
  416. })
  417. // DELETE /api/projects/{project_id}/roles -> project.NewRoleDeleteHandler
  418. deleteRoleEndpoint := factory.NewAPIEndpoint(
  419. &types.APIRequestMetadata{
  420. Verb: types.APIVerbDelete,
  421. Method: types.HTTPVerbDelete,
  422. Path: &types.Path{
  423. Parent: basePath,
  424. RelativePath: relPath + "/roles",
  425. },
  426. Scopes: []types.PermissionScope{
  427. types.UserScope,
  428. types.ProjectScope,
  429. },
  430. },
  431. )
  432. deleteRoleHandler := project.NewRoleDeleteHandler(
  433. config,
  434. factory.GetDecoderValidator(),
  435. factory.GetResultWriter(),
  436. )
  437. routes = append(routes, &router.Route{
  438. Endpoint: deleteRoleEndpoint,
  439. Handler: deleteRoleHandler,
  440. Router: r,
  441. })
  442. // GET /api/projects/{project_id}/registries -> registry.NewRegistryListHandler
  443. listRegistriesEndpoint := factory.NewAPIEndpoint(
  444. &types.APIRequestMetadata{
  445. Verb: types.APIVerbList,
  446. Method: types.HTTPVerbGet,
  447. Path: &types.Path{
  448. Parent: basePath,
  449. RelativePath: relPath + "/registries",
  450. },
  451. Scopes: []types.PermissionScope{
  452. types.UserScope,
  453. types.ProjectScope,
  454. },
  455. },
  456. )
  457. listRegistriesHandler := registry.NewRegistryListHandler(
  458. config,
  459. factory.GetResultWriter(),
  460. )
  461. routes = append(routes, &router.Route{
  462. Endpoint: listRegistriesEndpoint,
  463. Handler: listRegistriesHandler,
  464. Router: r,
  465. })
  466. // POST /api/projects/{project_id}/registries -> registry.NewRegistryCreateHandler
  467. createRegistryEndpoint := factory.NewAPIEndpoint(
  468. &types.APIRequestMetadata{
  469. Verb: types.APIVerbCreate,
  470. Method: types.HTTPVerbPost,
  471. Path: &types.Path{
  472. Parent: basePath,
  473. RelativePath: relPath + "/registries",
  474. },
  475. Scopes: []types.PermissionScope{
  476. types.UserScope,
  477. types.ProjectScope,
  478. },
  479. },
  480. )
  481. createRegistryHandler := registry.NewRegistryCreateHandler(
  482. config,
  483. factory.GetDecoderValidator(),
  484. factory.GetResultWriter(),
  485. )
  486. routes = append(routes, &router.Route{
  487. Endpoint: createRegistryEndpoint,
  488. Handler: createRegistryHandler,
  489. Router: r,
  490. })
  491. // GET /api/projects/{project_id}/registries/ecr/token -> registry.NewRegistryGetECRTokenHandler
  492. getECRTokenEndpoint := factory.NewAPIEndpoint(
  493. &types.APIRequestMetadata{
  494. Verb: types.APIVerbGet,
  495. Method: types.HTTPVerbGet,
  496. Path: &types.Path{
  497. Parent: basePath,
  498. RelativePath: relPath + "/registries/ecr/token",
  499. },
  500. Scopes: []types.PermissionScope{
  501. types.UserScope,
  502. types.ProjectScope,
  503. },
  504. },
  505. )
  506. getECRTokenHandler := registry.NewRegistryGetECRTokenHandler(
  507. config,
  508. factory.GetDecoderValidator(),
  509. factory.GetResultWriter(),
  510. )
  511. routes = append(routes, &router.Route{
  512. Endpoint: getECRTokenEndpoint,
  513. Handler: getECRTokenHandler,
  514. Router: r,
  515. })
  516. // GET /api/projects/{project_id}/registries/docr/token -> registry.NewRegistryGetDOCRTokenHandler
  517. getDOCRTokenEndpoint := factory.NewAPIEndpoint(
  518. &types.APIRequestMetadata{
  519. Verb: types.APIVerbGet,
  520. Method: types.HTTPVerbGet,
  521. Path: &types.Path{
  522. Parent: basePath,
  523. RelativePath: relPath + "/registries/docr/token",
  524. },
  525. Scopes: []types.PermissionScope{
  526. types.UserScope,
  527. types.ProjectScope,
  528. },
  529. },
  530. )
  531. getDOCRTokenHandler := registry.NewRegistryGetDOCRTokenHandler(
  532. config,
  533. factory.GetDecoderValidator(),
  534. factory.GetResultWriter(),
  535. )
  536. routes = append(routes, &router.Route{
  537. Endpoint: getDOCRTokenEndpoint,
  538. Handler: getDOCRTokenHandler,
  539. Router: r,
  540. })
  541. // GET /api/projects/{project_id}/registries/gcr/token -> registry.NewRegistryGetGCRTokenHandler
  542. getGCRTokenEndpoint := factory.NewAPIEndpoint(
  543. &types.APIRequestMetadata{
  544. Verb: types.APIVerbGet,
  545. Method: types.HTTPVerbGet,
  546. Path: &types.Path{
  547. Parent: basePath,
  548. RelativePath: relPath + "/registries/gcr/token",
  549. },
  550. Scopes: []types.PermissionScope{
  551. types.UserScope,
  552. types.ProjectScope,
  553. },
  554. },
  555. )
  556. getGCRTokenHandler := registry.NewRegistryGetGCRTokenHandler(
  557. config,
  558. factory.GetDecoderValidator(),
  559. factory.GetResultWriter(),
  560. )
  561. routes = append(routes, &router.Route{
  562. Endpoint: getGCRTokenEndpoint,
  563. Handler: getGCRTokenHandler,
  564. Router: r,
  565. })
  566. // GET /api/projects/{project_id}/registries/gar/token -> registry.NewRegistryGetGARTokenHandler
  567. getGARTokenEndpoint := factory.NewAPIEndpoint(
  568. &types.APIRequestMetadata{
  569. Verb: types.APIVerbGet,
  570. Method: types.HTTPVerbGet,
  571. Path: &types.Path{
  572. Parent: basePath,
  573. RelativePath: relPath + "/registries/gar/token",
  574. },
  575. Scopes: []types.PermissionScope{
  576. types.UserScope,
  577. types.ProjectScope,
  578. },
  579. },
  580. )
  581. getGARTokenHandler := registry.NewRegistryGetGARTokenHandler(
  582. config,
  583. factory.GetDecoderValidator(),
  584. factory.GetResultWriter(),
  585. )
  586. routes = append(routes, &router.Route{
  587. Endpoint: getGARTokenEndpoint,
  588. Handler: getGARTokenHandler,
  589. Router: r,
  590. })
  591. // GET /api/projects/{project_id}/registries/acr/token -> registry.NewRegistryGetACRTokenHandler
  592. getACRTokenEndpoint := factory.NewAPIEndpoint(
  593. &types.APIRequestMetadata{
  594. Verb: types.APIVerbGet,
  595. Method: types.HTTPVerbGet,
  596. Path: &types.Path{
  597. Parent: basePath,
  598. RelativePath: relPath + "/registries/acr/token",
  599. },
  600. Scopes: []types.PermissionScope{
  601. types.UserScope,
  602. types.ProjectScope,
  603. },
  604. },
  605. )
  606. getACRTokenHandler := registry.NewRegistryGetACRTokenHandler(
  607. config,
  608. factory.GetDecoderValidator(),
  609. factory.GetResultWriter(),
  610. )
  611. routes = append(routes, &router.Route{
  612. Endpoint: getACRTokenEndpoint,
  613. Handler: getACRTokenHandler,
  614. Router: r,
  615. })
  616. // GET /api/projects/{project_id}/registries/dockerhub/token -> registry.NewRegistryGetDockerhubTokenHandler
  617. getDockerhubTokenEndpoint := factory.NewAPIEndpoint(
  618. &types.APIRequestMetadata{
  619. Verb: types.APIVerbGet,
  620. Method: types.HTTPVerbGet,
  621. Path: &types.Path{
  622. Parent: basePath,
  623. RelativePath: relPath + "/registries/dockerhub/token",
  624. },
  625. Scopes: []types.PermissionScope{
  626. types.UserScope,
  627. types.ProjectScope,
  628. },
  629. },
  630. )
  631. getDockerhubTokenHandler := registry.NewRegistryGetDockerhubTokenHandler(
  632. config,
  633. factory.GetDecoderValidator(),
  634. factory.GetResultWriter(),
  635. )
  636. routes = append(routes, &router.Route{
  637. Endpoint: getDockerhubTokenEndpoint,
  638. Handler: getDockerhubTokenHandler,
  639. Router: r,
  640. })
  641. // POST /api/projects/{project_id}/infras -> infra.NewInfraCreateHandler
  642. createInfraEndpoint := factory.NewAPIEndpoint(
  643. &types.APIRequestMetadata{
  644. Verb: types.APIVerbCreate,
  645. Method: types.HTTPVerbPost,
  646. Path: &types.Path{
  647. Parent: basePath,
  648. RelativePath: relPath + "/infras",
  649. },
  650. Scopes: []types.PermissionScope{
  651. types.UserScope,
  652. types.ProjectScope,
  653. },
  654. },
  655. )
  656. createInfraHandler := infra.NewInfraCreateHandler(
  657. config,
  658. factory.GetDecoderValidator(),
  659. factory.GetResultWriter(),
  660. )
  661. routes = append(routes, &router.Route{
  662. Endpoint: createInfraEndpoint,
  663. Handler: createInfraHandler,
  664. Router: r,
  665. })
  666. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  667. getTemplatesEndpoint := factory.NewAPIEndpoint(
  668. &types.APIRequestMetadata{
  669. Verb: types.APIVerbGet,
  670. Method: types.HTTPVerbGet,
  671. Path: &types.Path{
  672. Parent: basePath,
  673. RelativePath: relPath + "/infras/templates",
  674. },
  675. Scopes: []types.PermissionScope{
  676. types.UserScope,
  677. types.ProjectScope,
  678. },
  679. },
  680. )
  681. getTemplatesHandler := infra.NewInfraListTemplateHandler(
  682. config,
  683. factory.GetResultWriter(),
  684. )
  685. routes = append(routes, &router.Route{
  686. Endpoint: getTemplatesEndpoint,
  687. Handler: getTemplatesHandler,
  688. Router: r,
  689. })
  690. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  691. getTemplateEndpoint := factory.NewAPIEndpoint(
  692. &types.APIRequestMetadata{
  693. Verb: types.APIVerbGet,
  694. Method: types.HTTPVerbGet,
  695. Path: &types.Path{
  696. Parent: basePath,
  697. RelativePath: fmt.Sprintf("%s/infras/templates/{%s}/{%s}", relPath, types.URLParamTemplateName, types.URLParamTemplateVersion),
  698. },
  699. Scopes: []types.PermissionScope{
  700. types.UserScope,
  701. types.ProjectScope,
  702. },
  703. },
  704. )
  705. getTemplateHandler := infra.NewInfraGetTemplateHandler(
  706. config,
  707. factory.GetResultWriter(),
  708. )
  709. routes = append(routes, &router.Route{
  710. Endpoint: getTemplateEndpoint,
  711. Handler: getTemplateHandler,
  712. Router: r,
  713. })
  714. // // POST /api/projects/{project_id}/provision/ecr -> provision.NewProvisionECRHandler
  715. // provisionECREndpoint := factory.NewAPIEndpoint(
  716. // &types.APIRequestMetadata{
  717. // Verb: types.APIVerbCreate,
  718. // Method: types.HTTPVerbPost,
  719. // Path: &types.Path{
  720. // Parent: basePath,
  721. // RelativePath: relPath + "/provision/ecr",
  722. // },
  723. // Scopes: []types.PermissionScope{
  724. // types.UserScope,
  725. // types.ProjectScope,
  726. // },
  727. // },
  728. // )
  729. // provisionECRHandler := provision.NewProvisionECRHandler(
  730. // config,
  731. // factory.GetDecoderValidator(),
  732. // factory.GetResultWriter(),
  733. // )
  734. // routes = append(routes, &router.Route{
  735. // Endpoint: provisionECREndpoint,
  736. // Handler: provisionECRHandler,
  737. // Router: r,
  738. // })
  739. // // POST /api/projects/{project_id}/provision/eks -> provision.NewProvisionEKSHandler
  740. // provisionEKSEndpoint := factory.NewAPIEndpoint(
  741. // &types.APIRequestMetadata{
  742. // Verb: types.APIVerbCreate,
  743. // Method: types.HTTPVerbPost,
  744. // Path: &types.Path{
  745. // Parent: basePath,
  746. // RelativePath: relPath + "/provision/eks",
  747. // },
  748. // Scopes: []types.PermissionScope{
  749. // types.UserScope,
  750. // types.ProjectScope,
  751. // },
  752. // CheckUsage: true,
  753. // UsageMetric: types.Clusters,
  754. // },
  755. // )
  756. // provisionEKSHandler := provision.NewProvisionEKSHandler(
  757. // config,
  758. // factory.GetDecoderValidator(),
  759. // factory.GetResultWriter(),
  760. // )
  761. // routes = append(routes, &router.Route{
  762. // Endpoint: provisionEKSEndpoint,
  763. // Handler: provisionEKSHandler,
  764. // Router: r,
  765. // })
  766. // // POST /api/projects/{project_id}/provision/docr -> provision.NewProvisionDOCRHandler
  767. // provisionDOCREndpoint := factory.NewAPIEndpoint(
  768. // &types.APIRequestMetadata{
  769. // Verb: types.APIVerbCreate,
  770. // Method: types.HTTPVerbPost,
  771. // Path: &types.Path{
  772. // Parent: basePath,
  773. // RelativePath: relPath + "/provision/docr",
  774. // },
  775. // Scopes: []types.PermissionScope{
  776. // types.UserScope,
  777. // types.ProjectScope,
  778. // },
  779. // },
  780. // )
  781. // provisionDOCRHandler := provision.NewProvisionDOCRHandler(
  782. // config,
  783. // factory.GetDecoderValidator(),
  784. // factory.GetResultWriter(),
  785. // )
  786. // routes = append(routes, &router.Route{
  787. // Endpoint: provisionDOCREndpoint,
  788. // Handler: provisionDOCRHandler,
  789. // Router: r,
  790. // })
  791. // // POST /api/projects/{project_id}/provision/doks -> provision.NewProvisionDOKSHandler
  792. // provisionDOKSEndpoint := factory.NewAPIEndpoint(
  793. // &types.APIRequestMetadata{
  794. // Verb: types.APIVerbCreate,
  795. // Method: types.HTTPVerbPost,
  796. // Path: &types.Path{
  797. // Parent: basePath,
  798. // RelativePath: relPath + "/provision/doks",
  799. // },
  800. // Scopes: []types.PermissionScope{
  801. // types.UserScope,
  802. // types.ProjectScope,
  803. // },
  804. // CheckUsage: true,
  805. // UsageMetric: types.Clusters,
  806. // },
  807. // )
  808. // provisionDOKSHandler := provision.NewProvisionDOKSHandler(
  809. // config,
  810. // factory.GetDecoderValidator(),
  811. // factory.GetResultWriter(),
  812. // )
  813. // routes = append(routes, &router.Route{
  814. // Endpoint: provisionDOKSEndpoint,
  815. // Handler: provisionDOKSHandler,
  816. // Router: r,
  817. // })
  818. // // POST /api/projects/{project_id}/provision/gcr -> provision.NewProvisionGCRHandler
  819. // provisionGCREndpoint := factory.NewAPIEndpoint(
  820. // &types.APIRequestMetadata{
  821. // Verb: types.APIVerbCreate,
  822. // Method: types.HTTPVerbPost,
  823. // Path: &types.Path{
  824. // Parent: basePath,
  825. // RelativePath: relPath + "/provision/gcr",
  826. // },
  827. // Scopes: []types.PermissionScope{
  828. // types.UserScope,
  829. // types.ProjectScope,
  830. // },
  831. // },
  832. // )
  833. // provisionGCRHandler := provision.NewProvisionGCRHandler(
  834. // config,
  835. // factory.GetDecoderValidator(),
  836. // factory.GetResultWriter(),
  837. // )
  838. // routes = append(routes, &router.Route{
  839. // Endpoint: provisionGCREndpoint,
  840. // Handler: provisionGCRHandler,
  841. // Router: r,
  842. // })
  843. // // POST /api/projects/{project_id}/provision/gke -> provision.NewProvisionGKEHandler
  844. // provisionGKEEndpoint := factory.NewAPIEndpoint(
  845. // &types.APIRequestMetadata{
  846. // Verb: types.APIVerbCreate,
  847. // Method: types.HTTPVerbPost,
  848. // Path: &types.Path{
  849. // Parent: basePath,
  850. // RelativePath: relPath + "/provision/gke",
  851. // },
  852. // Scopes: []types.PermissionScope{
  853. // types.UserScope,
  854. // types.ProjectScope,
  855. // },
  856. // CheckUsage: true,
  857. // UsageMetric: types.Clusters,
  858. // },
  859. // )
  860. // provisionGKEHandler := provision.NewProvisionGKEHandler(
  861. // config,
  862. // factory.GetDecoderValidator(),
  863. // factory.GetResultWriter(),
  864. // )
  865. // routes = append(routes, &router.Route{
  866. // Endpoint: provisionGKEEndpoint,
  867. // Handler: provisionGKEHandler,
  868. // Router: r,
  869. // })
  870. // POST /api/projects/{project_id}/policy -> policy.NewPolicyCreateHandler
  871. policyCreateEndpoint := factory.NewAPIEndpoint(
  872. &types.APIRequestMetadata{
  873. Verb: types.APIVerbCreate,
  874. Method: types.HTTPVerbPost,
  875. Path: &types.Path{
  876. Parent: basePath,
  877. RelativePath: relPath + "/policy",
  878. },
  879. Scopes: []types.PermissionScope{
  880. types.UserScope,
  881. types.ProjectScope,
  882. types.SettingsScope,
  883. },
  884. },
  885. )
  886. policyCreateHandler := policy.NewPolicyCreateHandler(
  887. config,
  888. factory.GetDecoderValidator(),
  889. factory.GetResultWriter(),
  890. )
  891. routes = append(routes, &router.Route{
  892. Endpoint: policyCreateEndpoint,
  893. Handler: policyCreateHandler,
  894. Router: r,
  895. })
  896. // GET /api/projects/{project_id}/policies -> policy.NewPolicyListHandler
  897. policyListEndpoint := factory.NewAPIEndpoint(
  898. &types.APIRequestMetadata{
  899. Verb: types.APIVerbList,
  900. Method: types.HTTPVerbGet,
  901. Path: &types.Path{
  902. Parent: basePath,
  903. RelativePath: relPath + "/policies",
  904. },
  905. Scopes: []types.PermissionScope{
  906. types.UserScope,
  907. types.ProjectScope,
  908. types.SettingsScope,
  909. },
  910. },
  911. )
  912. policyListHandler := policy.NewPolicyListHandler(
  913. config,
  914. factory.GetDecoderValidator(),
  915. factory.GetResultWriter(),
  916. )
  917. routes = append(routes, &router.Route{
  918. Endpoint: policyListEndpoint,
  919. Handler: policyListHandler,
  920. Router: r,
  921. })
  922. // GET /api/projects/{project_id}/policy/{policy_id} -> policy.NewPolicyGetHandler
  923. policyGetEndpoint := factory.NewAPIEndpoint(
  924. &types.APIRequestMetadata{
  925. Verb: types.APIVerbGet,
  926. Method: types.HTTPVerbGet,
  927. Path: &types.Path{
  928. Parent: basePath,
  929. RelativePath: fmt.Sprintf("%s/policy/{%s}", relPath, types.URLParamPolicyID),
  930. },
  931. Scopes: []types.PermissionScope{
  932. types.UserScope,
  933. types.ProjectScope,
  934. types.SettingsScope,
  935. },
  936. },
  937. )
  938. policyGetHandler := policy.NewPolicyGetHandler(
  939. config,
  940. factory.GetDecoderValidator(),
  941. factory.GetResultWriter(),
  942. )
  943. routes = append(routes, &router.Route{
  944. Endpoint: policyGetEndpoint,
  945. Handler: policyGetHandler,
  946. Router: r,
  947. })
  948. // POST /api/projects/{project_id}/api_token -> api_token.NewAPITokenCreateHandler
  949. apiTokenCreateEndpoint := factory.NewAPIEndpoint(
  950. &types.APIRequestMetadata{
  951. Verb: types.APIVerbCreate,
  952. Method: types.HTTPVerbPost,
  953. Path: &types.Path{
  954. Parent: basePath,
  955. RelativePath: relPath + "/api_token",
  956. },
  957. Scopes: []types.PermissionScope{
  958. types.UserScope,
  959. types.ProjectScope,
  960. types.SettingsScope,
  961. },
  962. },
  963. )
  964. apiTokenCreateHandler := api_token.NewAPITokenCreateHandler(
  965. config,
  966. factory.GetDecoderValidator(),
  967. factory.GetResultWriter(),
  968. )
  969. routes = append(routes, &router.Route{
  970. Endpoint: apiTokenCreateEndpoint,
  971. Handler: apiTokenCreateHandler,
  972. Router: r,
  973. })
  974. // GET /api/projects/{project_id}/api_token -> api_token.NewAPITokenListHandler
  975. apiTokenListEndpoint := factory.NewAPIEndpoint(
  976. &types.APIRequestMetadata{
  977. Verb: types.APIVerbList,
  978. Method: types.HTTPVerbGet,
  979. Path: &types.Path{
  980. Parent: basePath,
  981. RelativePath: fmt.Sprintf("%s/api_token", relPath),
  982. },
  983. Scopes: []types.PermissionScope{
  984. types.UserScope,
  985. types.ProjectScope,
  986. types.SettingsScope,
  987. },
  988. },
  989. )
  990. apiTokenListHandler := api_token.NewAPITokenListHandler(
  991. config,
  992. factory.GetDecoderValidator(),
  993. factory.GetResultWriter(),
  994. )
  995. routes = append(routes, &router.Route{
  996. Endpoint: apiTokenListEndpoint,
  997. Handler: apiTokenListHandler,
  998. Router: r,
  999. })
  1000. // GET /api/projects/{project_id}/api_token/{api_token_id} -> api_token.NewAPITokenGetHandler
  1001. apiTokenGetEndpoint := factory.NewAPIEndpoint(
  1002. &types.APIRequestMetadata{
  1003. Verb: types.APIVerbGet,
  1004. Method: types.HTTPVerbGet,
  1005. Path: &types.Path{
  1006. Parent: basePath,
  1007. RelativePath: fmt.Sprintf("%s/api_token/{%s}", relPath, types.URLParamTokenID),
  1008. },
  1009. Scopes: []types.PermissionScope{
  1010. types.UserScope,
  1011. types.ProjectScope,
  1012. types.SettingsScope,
  1013. },
  1014. },
  1015. )
  1016. apiTokenGetHandler := api_token.NewAPITokenGetHandler(
  1017. config,
  1018. factory.GetDecoderValidator(),
  1019. factory.GetResultWriter(),
  1020. )
  1021. routes = append(routes, &router.Route{
  1022. Endpoint: apiTokenGetEndpoint,
  1023. Handler: apiTokenGetHandler,
  1024. Router: r,
  1025. })
  1026. // POST /api/projects/{project_id}/api_token/{api_token_id}/revoke -> api_token.NewAPITokenRevokeHandler
  1027. apiTokenRevokeEndpoint := factory.NewAPIEndpoint(
  1028. &types.APIRequestMetadata{
  1029. Verb: types.APIVerbUpdate,
  1030. Method: types.HTTPVerbPost,
  1031. Path: &types.Path{
  1032. Parent: basePath,
  1033. RelativePath: fmt.Sprintf("%s/api_token/{%s}/revoke", relPath, types.URLParamTokenID),
  1034. },
  1035. Scopes: []types.PermissionScope{
  1036. types.UserScope,
  1037. types.ProjectScope,
  1038. types.SettingsScope,
  1039. },
  1040. },
  1041. )
  1042. apiTokenRevokeHandler := api_token.NewAPITokenRevokeHandler(
  1043. config,
  1044. factory.GetDecoderValidator(),
  1045. factory.GetResultWriter(),
  1046. )
  1047. routes = append(routes, &router.Route{
  1048. Endpoint: apiTokenRevokeEndpoint,
  1049. Handler: apiTokenRevokeHandler,
  1050. Router: r,
  1051. })
  1052. // POST /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoCreateHandler
  1053. hrCreateEndpoint := factory.NewAPIEndpoint(
  1054. &types.APIRequestMetadata{
  1055. Verb: types.APIVerbCreate,
  1056. Method: types.HTTPVerbPost,
  1057. Path: &types.Path{
  1058. Parent: basePath,
  1059. RelativePath: relPath + "/helmrepos",
  1060. },
  1061. Scopes: []types.PermissionScope{
  1062. types.UserScope,
  1063. types.ProjectScope,
  1064. },
  1065. },
  1066. )
  1067. hrCreateHandler := helmrepo.NewHelmRepoCreateHandler(
  1068. config,
  1069. factory.GetDecoderValidator(),
  1070. factory.GetResultWriter(),
  1071. )
  1072. routes = append(routes, &router.Route{
  1073. Endpoint: hrCreateEndpoint,
  1074. Handler: hrCreateHandler,
  1075. Router: r,
  1076. })
  1077. // GET /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoListHandler
  1078. hrListEndpoint := factory.NewAPIEndpoint(
  1079. &types.APIRequestMetadata{
  1080. Verb: types.APIVerbList,
  1081. Method: types.HTTPVerbGet,
  1082. Path: &types.Path{
  1083. Parent: basePath,
  1084. RelativePath: relPath + "/helmrepos",
  1085. },
  1086. Scopes: []types.PermissionScope{
  1087. types.UserScope,
  1088. types.ProjectScope,
  1089. },
  1090. },
  1091. )
  1092. hrListHandler := helmrepo.NewHelmRepoListHandler(
  1093. config,
  1094. factory.GetResultWriter(),
  1095. )
  1096. routes = append(routes, &router.Route{
  1097. Endpoint: hrListEndpoint,
  1098. Handler: hrListHandler,
  1099. Router: r,
  1100. })
  1101. // GET /api/projects/{project_id}/tags -> project.NewGetTagsHandler
  1102. getTagsEndpoint := factory.NewAPIEndpoint(
  1103. &types.APIRequestMetadata{
  1104. Verb: types.APIVerbGet,
  1105. Method: types.HTTPVerbGet,
  1106. Path: &types.Path{
  1107. Parent: basePath,
  1108. RelativePath: relPath + "/tags",
  1109. },
  1110. Scopes: []types.PermissionScope{
  1111. types.UserScope,
  1112. types.ProjectScope,
  1113. },
  1114. },
  1115. )
  1116. getTagsHandler := project.NewGetTagsHandler(
  1117. config,
  1118. factory.GetResultWriter(),
  1119. )
  1120. routes = append(routes, &router.Route{
  1121. Endpoint: getTagsEndpoint,
  1122. Handler: getTagsHandler,
  1123. Router: r,
  1124. })
  1125. // POST /api/projects/{project_id}/tags -> project.NewCreateTagHandler
  1126. createTagEndpoint := factory.NewAPIEndpoint(
  1127. &types.APIRequestMetadata{
  1128. Verb: types.APIVerbCreate,
  1129. Method: types.HTTPVerbPost,
  1130. Path: &types.Path{
  1131. Parent: basePath,
  1132. RelativePath: relPath + "/tags",
  1133. },
  1134. Scopes: []types.PermissionScope{
  1135. types.UserScope,
  1136. types.ProjectScope,
  1137. },
  1138. },
  1139. )
  1140. createTagHandler := project.NewCreateTagHandler(
  1141. config,
  1142. factory.GetDecoderValidator(),
  1143. factory.GetResultWriter(),
  1144. )
  1145. routes = append(routes, &router.Route{
  1146. Endpoint: createTagEndpoint,
  1147. Handler: createTagHandler,
  1148. Router: r,
  1149. })
  1150. return routes, newPath
  1151. }