project.go 30 KB

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