2
0

project.go 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  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. // GET /api/projects/{project_id}/roles -> project.NewRolesListHandler
  343. listRolesEndpoint := factory.NewAPIEndpoint(
  344. &types.APIRequestMetadata{
  345. Verb: types.APIVerbList,
  346. Method: types.HTTPVerbGet,
  347. Path: &types.Path{
  348. Parent: basePath,
  349. RelativePath: relPath + "/roles",
  350. },
  351. Scopes: []types.PermissionScope{
  352. types.UserScope,
  353. types.ProjectScope,
  354. },
  355. },
  356. )
  357. listRolesHandler := project.NewRolesListHandler(
  358. config,
  359. factory.GetResultWriter(),
  360. )
  361. routes = append(routes, &router.Route{
  362. Endpoint: listRolesEndpoint,
  363. Handler: listRolesHandler,
  364. Router: r,
  365. })
  366. // POST /api/projects/{project_id}/roles -> project.NewRoleUpdateHandler
  367. updateRoleEndpoint := factory.NewAPIEndpoint(
  368. &types.APIRequestMetadata{
  369. Verb: types.APIVerbUpdate,
  370. Method: types.HTTPVerbPost,
  371. Path: &types.Path{
  372. Parent: basePath,
  373. RelativePath: relPath + "/roles",
  374. },
  375. Scopes: []types.PermissionScope{
  376. types.UserScope,
  377. types.ProjectScope,
  378. },
  379. },
  380. )
  381. updateRoleHandler := project.NewRoleUpdateHandler(
  382. config,
  383. factory.GetDecoderValidator(),
  384. factory.GetResultWriter(),
  385. )
  386. routes = append(routes, &router.Route{
  387. Endpoint: updateRoleEndpoint,
  388. Handler: updateRoleHandler,
  389. Router: r,
  390. })
  391. // DELETE /api/projects/{project_id}/roles -> project.NewRoleDeleteHandler
  392. deleteRoleEndpoint := factory.NewAPIEndpoint(
  393. &types.APIRequestMetadata{
  394. Verb: types.APIVerbDelete,
  395. Method: types.HTTPVerbDelete,
  396. Path: &types.Path{
  397. Parent: basePath,
  398. RelativePath: relPath + "/roles",
  399. },
  400. Scopes: []types.PermissionScope{
  401. types.UserScope,
  402. types.ProjectScope,
  403. },
  404. },
  405. )
  406. deleteRoleHandler := project.NewRoleDeleteHandler(
  407. config,
  408. factory.GetDecoderValidator(),
  409. factory.GetResultWriter(),
  410. )
  411. routes = append(routes, &router.Route{
  412. Endpoint: deleteRoleEndpoint,
  413. Handler: deleteRoleHandler,
  414. Router: r,
  415. })
  416. // GET /api/projects/{project_id}/registries -> registry.NewRegistryListHandler
  417. listRegistriesEndpoint := factory.NewAPIEndpoint(
  418. &types.APIRequestMetadata{
  419. Verb: types.APIVerbList,
  420. Method: types.HTTPVerbGet,
  421. Path: &types.Path{
  422. Parent: basePath,
  423. RelativePath: relPath + "/registries",
  424. },
  425. Scopes: []types.PermissionScope{
  426. types.UserScope,
  427. types.ProjectScope,
  428. },
  429. },
  430. )
  431. listRegistriesHandler := registry.NewRegistryListHandler(
  432. config,
  433. factory.GetResultWriter(),
  434. )
  435. routes = append(routes, &router.Route{
  436. Endpoint: listRegistriesEndpoint,
  437. Handler: listRegistriesHandler,
  438. Router: r,
  439. })
  440. // POST /api/projects/{project_id}/registries -> registry.NewRegistryCreateHandler
  441. createRegistryEndpoint := factory.NewAPIEndpoint(
  442. &types.APIRequestMetadata{
  443. Verb: types.APIVerbCreate,
  444. Method: types.HTTPVerbPost,
  445. Path: &types.Path{
  446. Parent: basePath,
  447. RelativePath: relPath + "/registries",
  448. },
  449. Scopes: []types.PermissionScope{
  450. types.UserScope,
  451. types.ProjectScope,
  452. },
  453. },
  454. )
  455. createRegistryHandler := registry.NewRegistryCreateHandler(
  456. config,
  457. factory.GetDecoderValidator(),
  458. factory.GetResultWriter(),
  459. )
  460. routes = append(routes, &router.Route{
  461. Endpoint: createRegistryEndpoint,
  462. Handler: createRegistryHandler,
  463. Router: r,
  464. })
  465. // GET /api/projects/{project_id}/registries/ecr/token -> registry.NewRegistryGetECRTokenHandler
  466. getECRTokenEndpoint := factory.NewAPIEndpoint(
  467. &types.APIRequestMetadata{
  468. Verb: types.APIVerbGet,
  469. Method: types.HTTPVerbGet,
  470. Path: &types.Path{
  471. Parent: basePath,
  472. RelativePath: relPath + "/registries/ecr/token",
  473. },
  474. Scopes: []types.PermissionScope{
  475. types.UserScope,
  476. types.ProjectScope,
  477. },
  478. },
  479. )
  480. getECRTokenHandler := registry.NewRegistryGetECRTokenHandler(
  481. config,
  482. factory.GetDecoderValidator(),
  483. factory.GetResultWriter(),
  484. )
  485. routes = append(routes, &router.Route{
  486. Endpoint: getECRTokenEndpoint,
  487. Handler: getECRTokenHandler,
  488. Router: r,
  489. })
  490. // GET /api/projects/{project_id}/registries/docr/token -> registry.NewRegistryGetDOCRTokenHandler
  491. getDOCRTokenEndpoint := factory.NewAPIEndpoint(
  492. &types.APIRequestMetadata{
  493. Verb: types.APIVerbGet,
  494. Method: types.HTTPVerbGet,
  495. Path: &types.Path{
  496. Parent: basePath,
  497. RelativePath: relPath + "/registries/docr/token",
  498. },
  499. Scopes: []types.PermissionScope{
  500. types.UserScope,
  501. types.ProjectScope,
  502. },
  503. },
  504. )
  505. getDOCRTokenHandler := registry.NewRegistryGetDOCRTokenHandler(
  506. config,
  507. factory.GetDecoderValidator(),
  508. factory.GetResultWriter(),
  509. )
  510. routes = append(routes, &router.Route{
  511. Endpoint: getDOCRTokenEndpoint,
  512. Handler: getDOCRTokenHandler,
  513. Router: r,
  514. })
  515. // GET /api/projects/{project_id}/registries/gcr/token -> registry.NewRegistryGetGCRTokenHandler
  516. getGCRTokenEndpoint := factory.NewAPIEndpoint(
  517. &types.APIRequestMetadata{
  518. Verb: types.APIVerbGet,
  519. Method: types.HTTPVerbGet,
  520. Path: &types.Path{
  521. Parent: basePath,
  522. RelativePath: relPath + "/registries/gcr/token",
  523. },
  524. Scopes: []types.PermissionScope{
  525. types.UserScope,
  526. types.ProjectScope,
  527. },
  528. },
  529. )
  530. getGCRTokenHandler := registry.NewRegistryGetGCRTokenHandler(
  531. config,
  532. factory.GetDecoderValidator(),
  533. factory.GetResultWriter(),
  534. )
  535. routes = append(routes, &router.Route{
  536. Endpoint: getGCRTokenEndpoint,
  537. Handler: getGCRTokenHandler,
  538. Router: r,
  539. })
  540. // GET /api/projects/{project_id}/registries/acr/token -> registry.NewRegistryGetACRTokenHandler
  541. getACRTokenEndpoint := factory.NewAPIEndpoint(
  542. &types.APIRequestMetadata{
  543. Verb: types.APIVerbGet,
  544. Method: types.HTTPVerbGet,
  545. Path: &types.Path{
  546. Parent: basePath,
  547. RelativePath: relPath + "/registries/acr/token",
  548. },
  549. Scopes: []types.PermissionScope{
  550. types.UserScope,
  551. types.ProjectScope,
  552. },
  553. },
  554. )
  555. getACRTokenHandler := registry.NewRegistryGetACRTokenHandler(
  556. config,
  557. factory.GetDecoderValidator(),
  558. factory.GetResultWriter(),
  559. )
  560. routes = append(routes, &router.Route{
  561. Endpoint: getACRTokenEndpoint,
  562. Handler: getACRTokenHandler,
  563. Router: r,
  564. })
  565. // GET /api/projects/{project_id}/registries/dockerhub/token -> registry.NewRegistryGetDockerhubTokenHandler
  566. getDockerhubTokenEndpoint := factory.NewAPIEndpoint(
  567. &types.APIRequestMetadata{
  568. Verb: types.APIVerbGet,
  569. Method: types.HTTPVerbGet,
  570. Path: &types.Path{
  571. Parent: basePath,
  572. RelativePath: relPath + "/registries/dockerhub/token",
  573. },
  574. Scopes: []types.PermissionScope{
  575. types.UserScope,
  576. types.ProjectScope,
  577. },
  578. },
  579. )
  580. getDockerhubTokenHandler := registry.NewRegistryGetDockerhubTokenHandler(
  581. config,
  582. factory.GetDecoderValidator(),
  583. factory.GetResultWriter(),
  584. )
  585. routes = append(routes, &router.Route{
  586. Endpoint: getDockerhubTokenEndpoint,
  587. Handler: getDockerhubTokenHandler,
  588. Router: r,
  589. })
  590. // POST /api/projects/{project_id}/infras -> infra.NewInfraCreateHandler
  591. createInfraEndpoint := factory.NewAPIEndpoint(
  592. &types.APIRequestMetadata{
  593. Verb: types.APIVerbCreate,
  594. Method: types.HTTPVerbPost,
  595. Path: &types.Path{
  596. Parent: basePath,
  597. RelativePath: relPath + "/infras",
  598. },
  599. Scopes: []types.PermissionScope{
  600. types.UserScope,
  601. types.ProjectScope,
  602. },
  603. },
  604. )
  605. createInfraHandler := infra.NewInfraCreateHandler(
  606. config,
  607. factory.GetDecoderValidator(),
  608. factory.GetResultWriter(),
  609. )
  610. routes = append(routes, &router.Route{
  611. Endpoint: createInfraEndpoint,
  612. Handler: createInfraHandler,
  613. Router: r,
  614. })
  615. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  616. getTemplatesEndpoint := factory.NewAPIEndpoint(
  617. &types.APIRequestMetadata{
  618. Verb: types.APIVerbGet,
  619. Method: types.HTTPVerbGet,
  620. Path: &types.Path{
  621. Parent: basePath,
  622. RelativePath: relPath + "/infras/templates",
  623. },
  624. Scopes: []types.PermissionScope{
  625. types.UserScope,
  626. types.ProjectScope,
  627. },
  628. },
  629. )
  630. getTemplatesHandler := infra.NewInfraListTemplateHandler(
  631. config,
  632. factory.GetResultWriter(),
  633. )
  634. routes = append(routes, &router.Route{
  635. Endpoint: getTemplatesEndpoint,
  636. Handler: getTemplatesHandler,
  637. Router: r,
  638. })
  639. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  640. getTemplateEndpoint := factory.NewAPIEndpoint(
  641. &types.APIRequestMetadata{
  642. Verb: types.APIVerbGet,
  643. Method: types.HTTPVerbGet,
  644. Path: &types.Path{
  645. Parent: basePath,
  646. RelativePath: fmt.Sprintf("%s/infras/templates/{%s}/{%s}", relPath, types.URLParamTemplateName, types.URLParamTemplateVersion),
  647. },
  648. Scopes: []types.PermissionScope{
  649. types.UserScope,
  650. types.ProjectScope,
  651. },
  652. },
  653. )
  654. getTemplateHandler := infra.NewInfraGetTemplateHandler(
  655. config,
  656. factory.GetResultWriter(),
  657. )
  658. routes = append(routes, &router.Route{
  659. Endpoint: getTemplateEndpoint,
  660. Handler: getTemplateHandler,
  661. Router: r,
  662. })
  663. // // POST /api/projects/{project_id}/provision/ecr -> provision.NewProvisionECRHandler
  664. // provisionECREndpoint := factory.NewAPIEndpoint(
  665. // &types.APIRequestMetadata{
  666. // Verb: types.APIVerbCreate,
  667. // Method: types.HTTPVerbPost,
  668. // Path: &types.Path{
  669. // Parent: basePath,
  670. // RelativePath: relPath + "/provision/ecr",
  671. // },
  672. // Scopes: []types.PermissionScope{
  673. // types.UserScope,
  674. // types.ProjectScope,
  675. // },
  676. // },
  677. // )
  678. // provisionECRHandler := provision.NewProvisionECRHandler(
  679. // config,
  680. // factory.GetDecoderValidator(),
  681. // factory.GetResultWriter(),
  682. // )
  683. // routes = append(routes, &router.Route{
  684. // Endpoint: provisionECREndpoint,
  685. // Handler: provisionECRHandler,
  686. // Router: r,
  687. // })
  688. // // POST /api/projects/{project_id}/provision/eks -> provision.NewProvisionEKSHandler
  689. // provisionEKSEndpoint := factory.NewAPIEndpoint(
  690. // &types.APIRequestMetadata{
  691. // Verb: types.APIVerbCreate,
  692. // Method: types.HTTPVerbPost,
  693. // Path: &types.Path{
  694. // Parent: basePath,
  695. // RelativePath: relPath + "/provision/eks",
  696. // },
  697. // Scopes: []types.PermissionScope{
  698. // types.UserScope,
  699. // types.ProjectScope,
  700. // },
  701. // CheckUsage: true,
  702. // UsageMetric: types.Clusters,
  703. // },
  704. // )
  705. // provisionEKSHandler := provision.NewProvisionEKSHandler(
  706. // config,
  707. // factory.GetDecoderValidator(),
  708. // factory.GetResultWriter(),
  709. // )
  710. // routes = append(routes, &router.Route{
  711. // Endpoint: provisionEKSEndpoint,
  712. // Handler: provisionEKSHandler,
  713. // Router: r,
  714. // })
  715. // // POST /api/projects/{project_id}/provision/docr -> provision.NewProvisionDOCRHandler
  716. // provisionDOCREndpoint := factory.NewAPIEndpoint(
  717. // &types.APIRequestMetadata{
  718. // Verb: types.APIVerbCreate,
  719. // Method: types.HTTPVerbPost,
  720. // Path: &types.Path{
  721. // Parent: basePath,
  722. // RelativePath: relPath + "/provision/docr",
  723. // },
  724. // Scopes: []types.PermissionScope{
  725. // types.UserScope,
  726. // types.ProjectScope,
  727. // },
  728. // },
  729. // )
  730. // provisionDOCRHandler := provision.NewProvisionDOCRHandler(
  731. // config,
  732. // factory.GetDecoderValidator(),
  733. // factory.GetResultWriter(),
  734. // )
  735. // routes = append(routes, &router.Route{
  736. // Endpoint: provisionDOCREndpoint,
  737. // Handler: provisionDOCRHandler,
  738. // Router: r,
  739. // })
  740. // // POST /api/projects/{project_id}/provision/doks -> provision.NewProvisionDOKSHandler
  741. // provisionDOKSEndpoint := factory.NewAPIEndpoint(
  742. // &types.APIRequestMetadata{
  743. // Verb: types.APIVerbCreate,
  744. // Method: types.HTTPVerbPost,
  745. // Path: &types.Path{
  746. // Parent: basePath,
  747. // RelativePath: relPath + "/provision/doks",
  748. // },
  749. // Scopes: []types.PermissionScope{
  750. // types.UserScope,
  751. // types.ProjectScope,
  752. // },
  753. // CheckUsage: true,
  754. // UsageMetric: types.Clusters,
  755. // },
  756. // )
  757. // provisionDOKSHandler := provision.NewProvisionDOKSHandler(
  758. // config,
  759. // factory.GetDecoderValidator(),
  760. // factory.GetResultWriter(),
  761. // )
  762. // routes = append(routes, &router.Route{
  763. // Endpoint: provisionDOKSEndpoint,
  764. // Handler: provisionDOKSHandler,
  765. // Router: r,
  766. // })
  767. // // POST /api/projects/{project_id}/provision/gcr -> provision.NewProvisionGCRHandler
  768. // provisionGCREndpoint := factory.NewAPIEndpoint(
  769. // &types.APIRequestMetadata{
  770. // Verb: types.APIVerbCreate,
  771. // Method: types.HTTPVerbPost,
  772. // Path: &types.Path{
  773. // Parent: basePath,
  774. // RelativePath: relPath + "/provision/gcr",
  775. // },
  776. // Scopes: []types.PermissionScope{
  777. // types.UserScope,
  778. // types.ProjectScope,
  779. // },
  780. // },
  781. // )
  782. // provisionGCRHandler := provision.NewProvisionGCRHandler(
  783. // config,
  784. // factory.GetDecoderValidator(),
  785. // factory.GetResultWriter(),
  786. // )
  787. // routes = append(routes, &router.Route{
  788. // Endpoint: provisionGCREndpoint,
  789. // Handler: provisionGCRHandler,
  790. // Router: r,
  791. // })
  792. // // POST /api/projects/{project_id}/provision/gke -> provision.NewProvisionGKEHandler
  793. // provisionGKEEndpoint := factory.NewAPIEndpoint(
  794. // &types.APIRequestMetadata{
  795. // Verb: types.APIVerbCreate,
  796. // Method: types.HTTPVerbPost,
  797. // Path: &types.Path{
  798. // Parent: basePath,
  799. // RelativePath: relPath + "/provision/gke",
  800. // },
  801. // Scopes: []types.PermissionScope{
  802. // types.UserScope,
  803. // types.ProjectScope,
  804. // },
  805. // CheckUsage: true,
  806. // UsageMetric: types.Clusters,
  807. // },
  808. // )
  809. // provisionGKEHandler := provision.NewProvisionGKEHandler(
  810. // config,
  811. // factory.GetDecoderValidator(),
  812. // factory.GetResultWriter(),
  813. // )
  814. // routes = append(routes, &router.Route{
  815. // Endpoint: provisionGKEEndpoint,
  816. // Handler: provisionGKEHandler,
  817. // Router: r,
  818. // })
  819. // POST /api/projects/{project_id}/policy -> policy.NewPolicyCreateHandler
  820. policyCreateEndpoint := factory.NewAPIEndpoint(
  821. &types.APIRequestMetadata{
  822. Verb: types.APIVerbCreate,
  823. Method: types.HTTPVerbPost,
  824. Path: &types.Path{
  825. Parent: basePath,
  826. RelativePath: relPath + "/policy",
  827. },
  828. Scopes: []types.PermissionScope{
  829. types.UserScope,
  830. types.ProjectScope,
  831. types.SettingsScope,
  832. },
  833. },
  834. )
  835. policyCreateHandler := policy.NewPolicyCreateHandler(
  836. config,
  837. factory.GetDecoderValidator(),
  838. factory.GetResultWriter(),
  839. )
  840. routes = append(routes, &router.Route{
  841. Endpoint: policyCreateEndpoint,
  842. Handler: policyCreateHandler,
  843. Router: r,
  844. })
  845. // GET /api/projects/{project_id}/policies -> policy.NewPolicyListHandler
  846. policyListEndpoint := factory.NewAPIEndpoint(
  847. &types.APIRequestMetadata{
  848. Verb: types.APIVerbList,
  849. Method: types.HTTPVerbGet,
  850. Path: &types.Path{
  851. Parent: basePath,
  852. RelativePath: relPath + "/policies",
  853. },
  854. Scopes: []types.PermissionScope{
  855. types.UserScope,
  856. types.ProjectScope,
  857. types.SettingsScope,
  858. },
  859. },
  860. )
  861. policyListHandler := policy.NewPolicyListHandler(
  862. config,
  863. factory.GetDecoderValidator(),
  864. factory.GetResultWriter(),
  865. )
  866. routes = append(routes, &router.Route{
  867. Endpoint: policyListEndpoint,
  868. Handler: policyListHandler,
  869. Router: r,
  870. })
  871. // GET /api/projects/{project_id}/policy/{policy_id} -> policy.NewPolicyGetHandler
  872. policyGetEndpoint := factory.NewAPIEndpoint(
  873. &types.APIRequestMetadata{
  874. Verb: types.APIVerbGet,
  875. Method: types.HTTPVerbGet,
  876. Path: &types.Path{
  877. Parent: basePath,
  878. RelativePath: fmt.Sprintf("%s/policy/{%s}", relPath, types.URLParamPolicyID),
  879. },
  880. Scopes: []types.PermissionScope{
  881. types.UserScope,
  882. types.ProjectScope,
  883. types.SettingsScope,
  884. },
  885. },
  886. )
  887. policyGetHandler := policy.NewPolicyGetHandler(
  888. config,
  889. factory.GetDecoderValidator(),
  890. factory.GetResultWriter(),
  891. )
  892. routes = append(routes, &router.Route{
  893. Endpoint: policyGetEndpoint,
  894. Handler: policyGetHandler,
  895. Router: r,
  896. })
  897. // POST /api/projects/{project_id}/api_token -> api_token.NewAPITokenCreateHandler
  898. apiTokenCreateEndpoint := factory.NewAPIEndpoint(
  899. &types.APIRequestMetadata{
  900. Verb: types.APIVerbCreate,
  901. Method: types.HTTPVerbPost,
  902. Path: &types.Path{
  903. Parent: basePath,
  904. RelativePath: relPath + "/api_token",
  905. },
  906. Scopes: []types.PermissionScope{
  907. types.UserScope,
  908. types.ProjectScope,
  909. types.SettingsScope,
  910. },
  911. },
  912. )
  913. apiTokenCreateHandler := api_token.NewAPITokenCreateHandler(
  914. config,
  915. factory.GetDecoderValidator(),
  916. factory.GetResultWriter(),
  917. )
  918. routes = append(routes, &router.Route{
  919. Endpoint: apiTokenCreateEndpoint,
  920. Handler: apiTokenCreateHandler,
  921. Router: r,
  922. })
  923. // GET /api/projects/{project_id}/api_token -> api_token.NewAPITokenListHandler
  924. apiTokenListEndpoint := factory.NewAPIEndpoint(
  925. &types.APIRequestMetadata{
  926. Verb: types.APIVerbList,
  927. Method: types.HTTPVerbGet,
  928. Path: &types.Path{
  929. Parent: basePath,
  930. RelativePath: fmt.Sprintf("%s/api_token", relPath),
  931. },
  932. Scopes: []types.PermissionScope{
  933. types.UserScope,
  934. types.ProjectScope,
  935. types.SettingsScope,
  936. },
  937. },
  938. )
  939. apiTokenListHandler := api_token.NewAPITokenListHandler(
  940. config,
  941. factory.GetDecoderValidator(),
  942. factory.GetResultWriter(),
  943. )
  944. routes = append(routes, &router.Route{
  945. Endpoint: apiTokenListEndpoint,
  946. Handler: apiTokenListHandler,
  947. Router: r,
  948. })
  949. // GET /api/projects/{project_id}/api_token/{api_token_id} -> api_token.NewAPITokenGetHandler
  950. apiTokenGetEndpoint := factory.NewAPIEndpoint(
  951. &types.APIRequestMetadata{
  952. Verb: types.APIVerbGet,
  953. Method: types.HTTPVerbGet,
  954. Path: &types.Path{
  955. Parent: basePath,
  956. RelativePath: fmt.Sprintf("%s/api_token/{%s}", relPath, types.URLParamTokenID),
  957. },
  958. Scopes: []types.PermissionScope{
  959. types.UserScope,
  960. types.ProjectScope,
  961. types.SettingsScope,
  962. },
  963. },
  964. )
  965. apiTokenGetHandler := api_token.NewAPITokenGetHandler(
  966. config,
  967. factory.GetDecoderValidator(),
  968. factory.GetResultWriter(),
  969. )
  970. routes = append(routes, &router.Route{
  971. Endpoint: apiTokenGetEndpoint,
  972. Handler: apiTokenGetHandler,
  973. Router: r,
  974. })
  975. // POST /api/projects/{project_id}/api_token/{api_token_id}/revoke -> api_token.NewAPITokenRevokeHandler
  976. apiTokenRevokeEndpoint := factory.NewAPIEndpoint(
  977. &types.APIRequestMetadata{
  978. Verb: types.APIVerbUpdate,
  979. Method: types.HTTPVerbPost,
  980. Path: &types.Path{
  981. Parent: basePath,
  982. RelativePath: fmt.Sprintf("%s/api_token/{%s}/revoke", relPath, types.URLParamTokenID),
  983. },
  984. Scopes: []types.PermissionScope{
  985. types.UserScope,
  986. types.ProjectScope,
  987. types.SettingsScope,
  988. },
  989. },
  990. )
  991. apiTokenRevokeHandler := api_token.NewAPITokenRevokeHandler(
  992. config,
  993. factory.GetDecoderValidator(),
  994. factory.GetResultWriter(),
  995. )
  996. routes = append(routes, &router.Route{
  997. Endpoint: apiTokenRevokeEndpoint,
  998. Handler: apiTokenRevokeHandler,
  999. Router: r,
  1000. })
  1001. // POST /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoCreateHandler
  1002. hrCreateEndpoint := factory.NewAPIEndpoint(
  1003. &types.APIRequestMetadata{
  1004. Verb: types.APIVerbCreate,
  1005. Method: types.HTTPVerbPost,
  1006. Path: &types.Path{
  1007. Parent: basePath,
  1008. RelativePath: relPath + "/helmrepos",
  1009. },
  1010. Scopes: []types.PermissionScope{
  1011. types.UserScope,
  1012. types.ProjectScope,
  1013. },
  1014. },
  1015. )
  1016. hrCreateHandler := helmrepo.NewHelmRepoCreateHandler(
  1017. config,
  1018. factory.GetDecoderValidator(),
  1019. factory.GetResultWriter(),
  1020. )
  1021. routes = append(routes, &router.Route{
  1022. Endpoint: hrCreateEndpoint,
  1023. Handler: hrCreateHandler,
  1024. Router: r,
  1025. })
  1026. // GET /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoListHandler
  1027. hrListEndpoint := factory.NewAPIEndpoint(
  1028. &types.APIRequestMetadata{
  1029. Verb: types.APIVerbList,
  1030. Method: types.HTTPVerbGet,
  1031. Path: &types.Path{
  1032. Parent: basePath,
  1033. RelativePath: relPath + "/helmrepos",
  1034. },
  1035. Scopes: []types.PermissionScope{
  1036. types.UserScope,
  1037. types.ProjectScope,
  1038. },
  1039. },
  1040. )
  1041. hrListHandler := helmrepo.NewHelmRepoListHandler(
  1042. config,
  1043. factory.GetResultWriter(),
  1044. )
  1045. routes = append(routes, &router.Route{
  1046. Endpoint: hrListEndpoint,
  1047. Handler: hrListHandler,
  1048. Router: r,
  1049. })
  1050. // GET /api/projects/{project_id}/tags -> project.NewGetTagsHandler
  1051. getTagsEndpoint := factory.NewAPIEndpoint(
  1052. &types.APIRequestMetadata{
  1053. Verb: types.APIVerbGet,
  1054. Method: types.HTTPVerbGet,
  1055. Path: &types.Path{
  1056. Parent: basePath,
  1057. RelativePath: relPath + "/tags",
  1058. },
  1059. Scopes: []types.PermissionScope{
  1060. types.UserScope,
  1061. types.ProjectScope,
  1062. },
  1063. },
  1064. )
  1065. getTagsHandler := project.NewGetTagsHandler(
  1066. config,
  1067. factory.GetResultWriter(),
  1068. )
  1069. routes = append(routes, &router.Route{
  1070. Endpoint: getTagsEndpoint,
  1071. Handler: getTagsHandler,
  1072. Router: r,
  1073. })
  1074. // POST /api/projects/{project_id}/tags -> project.NewCreateTagHandler
  1075. createTagEndpoint := factory.NewAPIEndpoint(
  1076. &types.APIRequestMetadata{
  1077. Verb: types.APIVerbCreate,
  1078. Method: types.HTTPVerbPost,
  1079. Path: &types.Path{
  1080. Parent: basePath,
  1081. RelativePath: relPath + "/tags",
  1082. },
  1083. Scopes: []types.PermissionScope{
  1084. types.UserScope,
  1085. types.ProjectScope,
  1086. },
  1087. },
  1088. )
  1089. createTagHandler := project.NewCreateTagHandler(
  1090. config,
  1091. factory.GetDecoderValidator(),
  1092. factory.GetResultWriter(),
  1093. )
  1094. routes = append(routes, &router.Route{
  1095. Endpoint: createTagEndpoint,
  1096. Handler: createTagHandler,
  1097. Router: r,
  1098. })
  1099. return routes, newPath
  1100. }