project.go 32 KB

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