project.go 31 KB

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