project.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. package router
  2. import (
  3. "fmt"
  4. "github.com/go-chi/chi"
  5. "github.com/porter-dev/porter/api/server/handlers/billing"
  6. "github.com/porter-dev/porter/api/server/handlers/cluster"
  7. "github.com/porter-dev/porter/api/server/handlers/gitinstallation"
  8. "github.com/porter-dev/porter/api/server/handlers/helmrepo"
  9. "github.com/porter-dev/porter/api/server/handlers/infra"
  10. "github.com/porter-dev/porter/api/server/handlers/project"
  11. "github.com/porter-dev/porter/api/server/handlers/registry"
  12. "github.com/porter-dev/porter/api/server/shared"
  13. "github.com/porter-dev/porter/api/server/shared/config"
  14. "github.com/porter-dev/porter/api/types"
  15. )
  16. func NewProjectScopedRegisterer(children ...*Registerer) *Registerer {
  17. return &Registerer{
  18. GetRoutes: GetProjectScopedRoutes,
  19. Children: children,
  20. }
  21. }
  22. func GetProjectScopedRoutes(
  23. r chi.Router,
  24. config *config.Config,
  25. basePath *types.Path,
  26. factory shared.APIEndpointFactory,
  27. children ...*Registerer,
  28. ) []*Route {
  29. routes, projPath := getProjectRoutes(r, config, basePath, factory)
  30. if len(children) > 0 {
  31. r.Route(projPath.RelativePath, func(r chi.Router) {
  32. for _, child := range children {
  33. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  34. routes = append(routes, childRoutes...)
  35. }
  36. })
  37. }
  38. return routes
  39. }
  40. func getProjectRoutes(
  41. r chi.Router,
  42. config *config.Config,
  43. basePath *types.Path,
  44. factory shared.APIEndpointFactory,
  45. ) ([]*Route, *types.Path) {
  46. relPath := "/projects/{project_id}"
  47. newPath := &types.Path{
  48. Parent: basePath,
  49. RelativePath: relPath,
  50. }
  51. routes := make([]*Route, 0)
  52. // GET /api/projects/{project_id} -> project.NewProjectGetHandler
  53. getEndpoint := factory.NewAPIEndpoint(
  54. &types.APIRequestMetadata{
  55. Verb: types.APIVerbGet,
  56. Method: types.HTTPVerbGet,
  57. Path: &types.Path{
  58. Parent: basePath,
  59. RelativePath: relPath,
  60. },
  61. Scopes: []types.PermissionScope{
  62. types.UserScope,
  63. types.ProjectScope,
  64. },
  65. },
  66. )
  67. getHandler := project.NewProjectGetHandler(
  68. config,
  69. factory.GetResultWriter(),
  70. )
  71. routes = append(routes, &Route{
  72. Endpoint: getEndpoint,
  73. Handler: getHandler,
  74. Router: r,
  75. })
  76. // DELETE /api/projects/{project_id} -> project.NewProjectDeleteHandler
  77. deleteEndpoint := factory.NewAPIEndpoint(
  78. &types.APIRequestMetadata{
  79. Verb: types.APIVerbDelete,
  80. Method: types.HTTPVerbDelete,
  81. Path: &types.Path{
  82. Parent: basePath,
  83. RelativePath: relPath,
  84. },
  85. Scopes: []types.PermissionScope{
  86. types.UserScope,
  87. types.ProjectScope,
  88. },
  89. },
  90. )
  91. deleteHandler := project.NewProjectDeleteHandler(
  92. config,
  93. factory.GetResultWriter(),
  94. )
  95. routes = append(routes, &Route{
  96. Endpoint: deleteEndpoint,
  97. Handler: deleteHandler,
  98. Router: r,
  99. })
  100. // GET /api/projects/{project_id}/policy -> project.NewProjectGetPolicyHandler
  101. getPolicyEndpoint := factory.NewAPIEndpoint(
  102. &types.APIRequestMetadata{
  103. Verb: types.APIVerbGet,
  104. Method: types.HTTPVerbGet,
  105. Path: &types.Path{
  106. Parent: basePath,
  107. RelativePath: relPath + "/policy",
  108. },
  109. Scopes: []types.PermissionScope{
  110. types.UserScope,
  111. types.ProjectScope,
  112. },
  113. },
  114. )
  115. getPolicyHandler := project.NewProjectGetPolicyHandler(
  116. config,
  117. factory.GetResultWriter(),
  118. )
  119. routes = append(routes, &Route{
  120. Endpoint: getPolicyEndpoint,
  121. Handler: getPolicyHandler,
  122. Router: r,
  123. })
  124. // GET /api/projects/{project_id}/onboarding -> project.NewProjectGetOnboardingHandler
  125. getOnboardingEndpoint := factory.NewAPIEndpoint(
  126. &types.APIRequestMetadata{
  127. Verb: types.APIVerbGet,
  128. Method: types.HTTPVerbGet,
  129. Path: &types.Path{
  130. Parent: basePath,
  131. RelativePath: relPath + "/onboarding",
  132. },
  133. Scopes: []types.PermissionScope{
  134. types.UserScope,
  135. types.ProjectScope,
  136. },
  137. },
  138. )
  139. getOnboardingHandler := project.NewOnboardingGetHandler(
  140. config,
  141. factory.GetDecoderValidator(),
  142. factory.GetResultWriter(),
  143. )
  144. routes = append(routes, &Route{
  145. Endpoint: getOnboardingEndpoint,
  146. Handler: getOnboardingHandler,
  147. Router: r,
  148. })
  149. // POST /api/projects/{project_id}/onboarding -> project.NewProjectGetOnboardingHandler
  150. updateOnboardingEndpoint := factory.NewAPIEndpoint(
  151. &types.APIRequestMetadata{
  152. Verb: types.APIVerbUpdate,
  153. Method: types.HTTPVerbPost,
  154. Path: &types.Path{
  155. Parent: basePath,
  156. RelativePath: relPath + "/onboarding",
  157. },
  158. Scopes: []types.PermissionScope{
  159. types.UserScope,
  160. types.ProjectScope,
  161. },
  162. },
  163. )
  164. updateOnboardingHandler := project.NewOnboardingUpdateHandler(
  165. config,
  166. factory.GetDecoderValidator(),
  167. factory.GetResultWriter(),
  168. )
  169. routes = append(routes, &Route{
  170. Endpoint: updateOnboardingEndpoint,
  171. Handler: updateOnboardingHandler,
  172. Router: r,
  173. })
  174. // GET /api/projects/{project_id}/usage -> project.NewProjectGetUsageHandler
  175. getUsageEndpoint := factory.NewAPIEndpoint(
  176. &types.APIRequestMetadata{
  177. Verb: types.APIVerbGet,
  178. Method: types.HTTPVerbGet,
  179. Path: &types.Path{
  180. Parent: basePath,
  181. RelativePath: relPath + "/usage",
  182. },
  183. Scopes: []types.PermissionScope{
  184. types.UserScope,
  185. types.ProjectScope,
  186. },
  187. },
  188. )
  189. getUsageHandler := project.NewProjectGetUsageHandler(
  190. config,
  191. factory.GetResultWriter(),
  192. )
  193. routes = append(routes, &Route{
  194. Endpoint: getUsageEndpoint,
  195. Handler: getUsageHandler,
  196. Router: r,
  197. })
  198. // GET /api/projects/{project_id}/billing -> project.NewProjectGetBillingHandler
  199. getBillingEndpoint := factory.NewAPIEndpoint(
  200. &types.APIRequestMetadata{
  201. Verb: types.APIVerbGet,
  202. Method: types.HTTPVerbGet,
  203. Path: &types.Path{
  204. Parent: basePath,
  205. RelativePath: relPath + "/billing",
  206. },
  207. Scopes: []types.PermissionScope{
  208. types.UserScope,
  209. types.ProjectScope,
  210. },
  211. },
  212. )
  213. getBillingHandler := project.NewProjectGetBillingHandler(
  214. config,
  215. factory.GetResultWriter(),
  216. )
  217. routes = append(routes, &Route{
  218. Endpoint: getBillingEndpoint,
  219. Handler: getBillingHandler,
  220. Router: r,
  221. })
  222. // GET /api/projects/{project_id}/billing/token -> billing.NewBillingGetTokenEndpoint
  223. getBillingTokenEndpoint := factory.NewAPIEndpoint(
  224. &types.APIRequestMetadata{
  225. Verb: types.APIVerbGet,
  226. Method: types.HTTPVerbGet,
  227. Path: &types.Path{
  228. Parent: basePath,
  229. RelativePath: relPath + "/billing/token",
  230. },
  231. Scopes: []types.PermissionScope{
  232. types.UserScope,
  233. types.ProjectScope,
  234. types.SettingsScope,
  235. },
  236. },
  237. )
  238. getBillingTokenHandler := billing.NewBillingGetTokenHandler(
  239. config,
  240. factory.GetDecoderValidator(),
  241. factory.GetResultWriter(),
  242. )
  243. routes = append(routes, &Route{
  244. Endpoint: getBillingTokenEndpoint,
  245. Handler: getBillingTokenHandler,
  246. Router: r,
  247. })
  248. // GET /api/billing_webhook -> billing.NewBillingWebhookHandler
  249. getBillingWebhookEndpoint := factory.NewAPIEndpoint(
  250. &types.APIRequestMetadata{
  251. Verb: types.APIVerbCreate,
  252. Method: types.HTTPVerbPost,
  253. Path: &types.Path{
  254. Parent: basePath,
  255. RelativePath: "/billing_webhook",
  256. },
  257. Scopes: []types.PermissionScope{},
  258. },
  259. )
  260. getBillingWebhookHandler := billing.NewBillingWebhookHandler(
  261. config,
  262. factory.GetDecoderValidator(),
  263. )
  264. routes = append(routes, &Route{
  265. Endpoint: getBillingWebhookEndpoint,
  266. Handler: getBillingWebhookHandler,
  267. Router: r,
  268. })
  269. // GET /api/projects/{project_id}/clusters -> cluster.NewClusterListHandler
  270. listClusterEndpoint := factory.NewAPIEndpoint(
  271. &types.APIRequestMetadata{
  272. Verb: types.APIVerbList,
  273. Method: types.HTTPVerbGet,
  274. Path: &types.Path{
  275. Parent: basePath,
  276. RelativePath: relPath + "/clusters",
  277. },
  278. Scopes: []types.PermissionScope{
  279. types.UserScope,
  280. types.ProjectScope,
  281. },
  282. },
  283. )
  284. listClusterHandler := cluster.NewClusterListHandler(
  285. config,
  286. factory.GetResultWriter(),
  287. )
  288. routes = append(routes, &Route{
  289. Endpoint: listClusterEndpoint,
  290. Handler: listClusterHandler,
  291. Router: r,
  292. })
  293. // GET /api/projects/{project_id}/gitrepos -> gitinstallation.NewGitRepoListHandler
  294. listGitReposEndpoint := factory.NewAPIEndpoint(
  295. &types.APIRequestMetadata{
  296. Verb: types.APIVerbList,
  297. Method: types.HTTPVerbGet,
  298. Path: &types.Path{
  299. Parent: basePath,
  300. RelativePath: relPath + "/gitrepos",
  301. },
  302. Scopes: []types.PermissionScope{
  303. types.UserScope,
  304. types.ProjectScope,
  305. },
  306. },
  307. )
  308. listGitReposHandler := gitinstallation.NewGitRepoListHandler(
  309. config,
  310. factory.GetResultWriter(),
  311. )
  312. routes = append(routes, &Route{
  313. Endpoint: listGitReposEndpoint,
  314. Handler: listGitReposHandler,
  315. Router: r,
  316. })
  317. // GET /api/projects/{project_id}/collaborators -> project.NewCollaboratorsListHandler
  318. listCollaboratorsEndpoint := factory.NewAPIEndpoint(
  319. &types.APIRequestMetadata{
  320. Verb: types.APIVerbList,
  321. Method: types.HTTPVerbGet,
  322. Path: &types.Path{
  323. Parent: basePath,
  324. RelativePath: relPath + "/collaborators",
  325. },
  326. Scopes: []types.PermissionScope{
  327. types.UserScope,
  328. types.ProjectScope,
  329. },
  330. },
  331. )
  332. listCollaboratorsHandler := project.NewCollaboratorsListHandler(
  333. config,
  334. factory.GetResultWriter(),
  335. )
  336. routes = append(routes, &Route{
  337. Endpoint: listCollaboratorsEndpoint,
  338. Handler: listCollaboratorsHandler,
  339. Router: r,
  340. })
  341. // GET /api/projects/{project_id}/roles -> project.NewRolesListHandler
  342. listRolesEndpoint := factory.NewAPIEndpoint(
  343. &types.APIRequestMetadata{
  344. Verb: types.APIVerbList,
  345. Method: types.HTTPVerbGet,
  346. Path: &types.Path{
  347. Parent: basePath,
  348. RelativePath: relPath + "/roles",
  349. },
  350. Scopes: []types.PermissionScope{
  351. types.UserScope,
  352. types.ProjectScope,
  353. },
  354. },
  355. )
  356. listRolesHandler := project.NewRolesListHandler(
  357. config,
  358. factory.GetResultWriter(),
  359. )
  360. routes = append(routes, &Route{
  361. Endpoint: listRolesEndpoint,
  362. Handler: listRolesHandler,
  363. Router: r,
  364. })
  365. // POST /api/projects/{project_id}/roles -> project.NewRoleUpdateHandler
  366. updateRoleEndpoint := factory.NewAPIEndpoint(
  367. &types.APIRequestMetadata{
  368. Verb: types.APIVerbUpdate,
  369. Method: types.HTTPVerbPost,
  370. Path: &types.Path{
  371. Parent: basePath,
  372. RelativePath: relPath + "/roles",
  373. },
  374. Scopes: []types.PermissionScope{
  375. types.UserScope,
  376. types.ProjectScope,
  377. },
  378. },
  379. )
  380. updateRoleHandler := project.NewRoleUpdateHandler(
  381. config,
  382. factory.GetDecoderValidator(),
  383. factory.GetResultWriter(),
  384. )
  385. routes = append(routes, &Route{
  386. Endpoint: updateRoleEndpoint,
  387. Handler: updateRoleHandler,
  388. Router: r,
  389. })
  390. // DELETE /api/projects/{project_id}/roles -> project.NewRoleDeleteHandler
  391. deleteRoleEndpoint := factory.NewAPIEndpoint(
  392. &types.APIRequestMetadata{
  393. Verb: types.APIVerbDelete,
  394. Method: types.HTTPVerbDelete,
  395. Path: &types.Path{
  396. Parent: basePath,
  397. RelativePath: relPath + "/roles",
  398. },
  399. Scopes: []types.PermissionScope{
  400. types.UserScope,
  401. types.ProjectScope,
  402. },
  403. },
  404. )
  405. deleteRoleHandler := project.NewRoleDeleteHandler(
  406. config,
  407. factory.GetDecoderValidator(),
  408. factory.GetResultWriter(),
  409. )
  410. routes = append(routes, &Route{
  411. Endpoint: deleteRoleEndpoint,
  412. Handler: deleteRoleHandler,
  413. Router: r,
  414. })
  415. // GET /api/projects/{project_id}/registries -> registry.NewRegistryListHandler
  416. listRegistriesEndpoint := factory.NewAPIEndpoint(
  417. &types.APIRequestMetadata{
  418. Verb: types.APIVerbList,
  419. Method: types.HTTPVerbGet,
  420. Path: &types.Path{
  421. Parent: basePath,
  422. RelativePath: relPath + "/registries",
  423. },
  424. Scopes: []types.PermissionScope{
  425. types.UserScope,
  426. types.ProjectScope,
  427. },
  428. },
  429. )
  430. listRegistriesHandler := registry.NewRegistryListHandler(
  431. config,
  432. factory.GetResultWriter(),
  433. )
  434. routes = append(routes, &Route{
  435. Endpoint: listRegistriesEndpoint,
  436. Handler: listRegistriesHandler,
  437. Router: r,
  438. })
  439. // POST /api/projects/{project_id}/registries -> registry.NewRegistryCreateHandler
  440. createRegistryEndpoint := factory.NewAPIEndpoint(
  441. &types.APIRequestMetadata{
  442. Verb: types.APIVerbCreate,
  443. Method: types.HTTPVerbPost,
  444. Path: &types.Path{
  445. Parent: basePath,
  446. RelativePath: relPath + "/registries",
  447. },
  448. Scopes: []types.PermissionScope{
  449. types.UserScope,
  450. types.ProjectScope,
  451. },
  452. },
  453. )
  454. createRegistryHandler := registry.NewRegistryCreateHandler(
  455. config,
  456. factory.GetDecoderValidator(),
  457. factory.GetResultWriter(),
  458. )
  459. routes = append(routes, &Route{
  460. Endpoint: createRegistryEndpoint,
  461. Handler: createRegistryHandler,
  462. Router: r,
  463. })
  464. // GET /api/projects/{project_id}/registries/ecr/token -> registry.NewRegistryGetECRTokenHandler
  465. getECRTokenEndpoint := factory.NewAPIEndpoint(
  466. &types.APIRequestMetadata{
  467. Verb: types.APIVerbGet,
  468. Method: types.HTTPVerbGet,
  469. Path: &types.Path{
  470. Parent: basePath,
  471. RelativePath: relPath + "/registries/ecr/token",
  472. },
  473. Scopes: []types.PermissionScope{
  474. types.UserScope,
  475. types.ProjectScope,
  476. },
  477. },
  478. )
  479. getECRTokenHandler := registry.NewRegistryGetECRTokenHandler(
  480. config,
  481. factory.GetDecoderValidator(),
  482. factory.GetResultWriter(),
  483. )
  484. routes = append(routes, &Route{
  485. Endpoint: getECRTokenEndpoint,
  486. Handler: getECRTokenHandler,
  487. Router: r,
  488. })
  489. // GET /api/projects/{project_id}/registries/docr/token -> registry.NewRegistryGetDOCRTokenHandler
  490. getDOCRTokenEndpoint := factory.NewAPIEndpoint(
  491. &types.APIRequestMetadata{
  492. Verb: types.APIVerbGet,
  493. Method: types.HTTPVerbGet,
  494. Path: &types.Path{
  495. Parent: basePath,
  496. RelativePath: relPath + "/registries/docr/token",
  497. },
  498. Scopes: []types.PermissionScope{
  499. types.UserScope,
  500. types.ProjectScope,
  501. },
  502. },
  503. )
  504. getDOCRTokenHandler := registry.NewRegistryGetDOCRTokenHandler(
  505. config,
  506. factory.GetDecoderValidator(),
  507. factory.GetResultWriter(),
  508. )
  509. routes = append(routes, &Route{
  510. Endpoint: getDOCRTokenEndpoint,
  511. Handler: getDOCRTokenHandler,
  512. Router: r,
  513. })
  514. // GET /api/projects/{project_id}/registries/gcr/token -> registry.NewRegistryGetGCRTokenHandler
  515. getGCRTokenEndpoint := factory.NewAPIEndpoint(
  516. &types.APIRequestMetadata{
  517. Verb: types.APIVerbGet,
  518. Method: types.HTTPVerbGet,
  519. Path: &types.Path{
  520. Parent: basePath,
  521. RelativePath: relPath + "/registries/gcr/token",
  522. },
  523. Scopes: []types.PermissionScope{
  524. types.UserScope,
  525. types.ProjectScope,
  526. },
  527. },
  528. )
  529. getGCRTokenHandler := registry.NewRegistryGetGCRTokenHandler(
  530. config,
  531. factory.GetDecoderValidator(),
  532. factory.GetResultWriter(),
  533. )
  534. routes = append(routes, &Route{
  535. Endpoint: getGCRTokenEndpoint,
  536. Handler: getGCRTokenHandler,
  537. Router: r,
  538. })
  539. // GET /api/projects/{project_id}/registries/acr/token -> registry.NewRegistryGetACRTokenHandler
  540. getACRTokenEndpoint := factory.NewAPIEndpoint(
  541. &types.APIRequestMetadata{
  542. Verb: types.APIVerbGet,
  543. Method: types.HTTPVerbGet,
  544. Path: &types.Path{
  545. Parent: basePath,
  546. RelativePath: relPath + "/registries/acr/token",
  547. },
  548. Scopes: []types.PermissionScope{
  549. types.UserScope,
  550. types.ProjectScope,
  551. },
  552. },
  553. )
  554. getACRTokenHandler := registry.NewRegistryGetACRTokenHandler(
  555. config,
  556. factory.GetDecoderValidator(),
  557. factory.GetResultWriter(),
  558. )
  559. routes = append(routes, &Route{
  560. Endpoint: getACRTokenEndpoint,
  561. Handler: getACRTokenHandler,
  562. Router: r,
  563. })
  564. // GET /api/projects/{project_id}/registries/dockerhub/token -> registry.NewRegistryGetDockerhubTokenHandler
  565. getDockerhubTokenEndpoint := factory.NewAPIEndpoint(
  566. &types.APIRequestMetadata{
  567. Verb: types.APIVerbGet,
  568. Method: types.HTTPVerbGet,
  569. Path: &types.Path{
  570. Parent: basePath,
  571. RelativePath: relPath + "/registries/dockerhub/token",
  572. },
  573. Scopes: []types.PermissionScope{
  574. types.UserScope,
  575. types.ProjectScope,
  576. },
  577. },
  578. )
  579. getDockerhubTokenHandler := registry.NewRegistryGetDockerhubTokenHandler(
  580. config,
  581. factory.GetDecoderValidator(),
  582. factory.GetResultWriter(),
  583. )
  584. routes = append(routes, &Route{
  585. Endpoint: getDockerhubTokenEndpoint,
  586. Handler: getDockerhubTokenHandler,
  587. Router: r,
  588. })
  589. // POST /api/projects/{project_id}/infras -> infra.NewInfraCreateHandler
  590. createInfraEndpoint := factory.NewAPIEndpoint(
  591. &types.APIRequestMetadata{
  592. Verb: types.APIVerbCreate,
  593. Method: types.HTTPVerbPost,
  594. Path: &types.Path{
  595. Parent: basePath,
  596. RelativePath: relPath + "/infras",
  597. },
  598. Scopes: []types.PermissionScope{
  599. types.UserScope,
  600. types.ProjectScope,
  601. },
  602. },
  603. )
  604. createInfraHandler := infra.NewInfraCreateHandler(
  605. config,
  606. factory.GetDecoderValidator(),
  607. factory.GetResultWriter(),
  608. )
  609. routes = append(routes, &Route{
  610. Endpoint: createInfraEndpoint,
  611. Handler: createInfraHandler,
  612. Router: r,
  613. })
  614. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  615. getTemplatesEndpoint := factory.NewAPIEndpoint(
  616. &types.APIRequestMetadata{
  617. Verb: types.APIVerbGet,
  618. Method: types.HTTPVerbGet,
  619. Path: &types.Path{
  620. Parent: basePath,
  621. RelativePath: relPath + "/infras/templates",
  622. },
  623. Scopes: []types.PermissionScope{
  624. types.UserScope,
  625. types.ProjectScope,
  626. },
  627. },
  628. )
  629. getTemplatesHandler := infra.NewInfraListTemplateHandler(
  630. config,
  631. factory.GetResultWriter(),
  632. )
  633. routes = append(routes, &Route{
  634. Endpoint: getTemplatesEndpoint,
  635. Handler: getTemplatesHandler,
  636. Router: r,
  637. })
  638. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  639. getTemplateEndpoint := factory.NewAPIEndpoint(
  640. &types.APIRequestMetadata{
  641. Verb: types.APIVerbGet,
  642. Method: types.HTTPVerbGet,
  643. Path: &types.Path{
  644. Parent: basePath,
  645. RelativePath: fmt.Sprintf("%s/infras/templates/{%s}/{%s}", relPath, types.URLParamTemplateName, types.URLParamTemplateVersion),
  646. },
  647. Scopes: []types.PermissionScope{
  648. types.UserScope,
  649. types.ProjectScope,
  650. },
  651. },
  652. )
  653. getTemplateHandler := infra.NewInfraGetTemplateHandler(
  654. config,
  655. factory.GetResultWriter(),
  656. )
  657. routes = append(routes, &Route{
  658. Endpoint: getTemplateEndpoint,
  659. Handler: getTemplateHandler,
  660. Router: r,
  661. })
  662. // // POST /api/projects/{project_id}/provision/ecr -> provision.NewProvisionECRHandler
  663. // provisionECREndpoint := factory.NewAPIEndpoint(
  664. // &types.APIRequestMetadata{
  665. // Verb: types.APIVerbCreate,
  666. // Method: types.HTTPVerbPost,
  667. // Path: &types.Path{
  668. // Parent: basePath,
  669. // RelativePath: relPath + "/provision/ecr",
  670. // },
  671. // Scopes: []types.PermissionScope{
  672. // types.UserScope,
  673. // types.ProjectScope,
  674. // },
  675. // },
  676. // )
  677. // provisionECRHandler := provision.NewProvisionECRHandler(
  678. // config,
  679. // factory.GetDecoderValidator(),
  680. // factory.GetResultWriter(),
  681. // )
  682. // routes = append(routes, &Route{
  683. // Endpoint: provisionECREndpoint,
  684. // Handler: provisionECRHandler,
  685. // Router: r,
  686. // })
  687. // // POST /api/projects/{project_id}/provision/eks -> provision.NewProvisionEKSHandler
  688. // provisionEKSEndpoint := factory.NewAPIEndpoint(
  689. // &types.APIRequestMetadata{
  690. // Verb: types.APIVerbCreate,
  691. // Method: types.HTTPVerbPost,
  692. // Path: &types.Path{
  693. // Parent: basePath,
  694. // RelativePath: relPath + "/provision/eks",
  695. // },
  696. // Scopes: []types.PermissionScope{
  697. // types.UserScope,
  698. // types.ProjectScope,
  699. // },
  700. // CheckUsage: true,
  701. // UsageMetric: types.Clusters,
  702. // },
  703. // )
  704. // provisionEKSHandler := provision.NewProvisionEKSHandler(
  705. // config,
  706. // factory.GetDecoderValidator(),
  707. // factory.GetResultWriter(),
  708. // )
  709. // routes = append(routes, &Route{
  710. // Endpoint: provisionEKSEndpoint,
  711. // Handler: provisionEKSHandler,
  712. // Router: r,
  713. // })
  714. // // POST /api/projects/{project_id}/provision/docr -> provision.NewProvisionDOCRHandler
  715. // provisionDOCREndpoint := factory.NewAPIEndpoint(
  716. // &types.APIRequestMetadata{
  717. // Verb: types.APIVerbCreate,
  718. // Method: types.HTTPVerbPost,
  719. // Path: &types.Path{
  720. // Parent: basePath,
  721. // RelativePath: relPath + "/provision/docr",
  722. // },
  723. // Scopes: []types.PermissionScope{
  724. // types.UserScope,
  725. // types.ProjectScope,
  726. // },
  727. // },
  728. // )
  729. // provisionDOCRHandler := provision.NewProvisionDOCRHandler(
  730. // config,
  731. // factory.GetDecoderValidator(),
  732. // factory.GetResultWriter(),
  733. // )
  734. // routes = append(routes, &Route{
  735. // Endpoint: provisionDOCREndpoint,
  736. // Handler: provisionDOCRHandler,
  737. // Router: r,
  738. // })
  739. // // POST /api/projects/{project_id}/provision/doks -> provision.NewProvisionDOKSHandler
  740. // provisionDOKSEndpoint := factory.NewAPIEndpoint(
  741. // &types.APIRequestMetadata{
  742. // Verb: types.APIVerbCreate,
  743. // Method: types.HTTPVerbPost,
  744. // Path: &types.Path{
  745. // Parent: basePath,
  746. // RelativePath: relPath + "/provision/doks",
  747. // },
  748. // Scopes: []types.PermissionScope{
  749. // types.UserScope,
  750. // types.ProjectScope,
  751. // },
  752. // CheckUsage: true,
  753. // UsageMetric: types.Clusters,
  754. // },
  755. // )
  756. // provisionDOKSHandler := provision.NewProvisionDOKSHandler(
  757. // config,
  758. // factory.GetDecoderValidator(),
  759. // factory.GetResultWriter(),
  760. // )
  761. // routes = append(routes, &Route{
  762. // Endpoint: provisionDOKSEndpoint,
  763. // Handler: provisionDOKSHandler,
  764. // Router: r,
  765. // })
  766. // // POST /api/projects/{project_id}/provision/gcr -> provision.NewProvisionGCRHandler
  767. // provisionGCREndpoint := factory.NewAPIEndpoint(
  768. // &types.APIRequestMetadata{
  769. // Verb: types.APIVerbCreate,
  770. // Method: types.HTTPVerbPost,
  771. // Path: &types.Path{
  772. // Parent: basePath,
  773. // RelativePath: relPath + "/provision/gcr",
  774. // },
  775. // Scopes: []types.PermissionScope{
  776. // types.UserScope,
  777. // types.ProjectScope,
  778. // },
  779. // },
  780. // )
  781. // provisionGCRHandler := provision.NewProvisionGCRHandler(
  782. // config,
  783. // factory.GetDecoderValidator(),
  784. // factory.GetResultWriter(),
  785. // )
  786. // routes = append(routes, &Route{
  787. // Endpoint: provisionGCREndpoint,
  788. // Handler: provisionGCRHandler,
  789. // Router: r,
  790. // })
  791. // // POST /api/projects/{project_id}/provision/gke -> provision.NewProvisionGKEHandler
  792. // provisionGKEEndpoint := factory.NewAPIEndpoint(
  793. // &types.APIRequestMetadata{
  794. // Verb: types.APIVerbCreate,
  795. // Method: types.HTTPVerbPost,
  796. // Path: &types.Path{
  797. // Parent: basePath,
  798. // RelativePath: relPath + "/provision/gke",
  799. // },
  800. // Scopes: []types.PermissionScope{
  801. // types.UserScope,
  802. // types.ProjectScope,
  803. // },
  804. // CheckUsage: true,
  805. // UsageMetric: types.Clusters,
  806. // },
  807. // )
  808. // provisionGKEHandler := provision.NewProvisionGKEHandler(
  809. // config,
  810. // factory.GetDecoderValidator(),
  811. // factory.GetResultWriter(),
  812. // )
  813. // routes = append(routes, &Route{
  814. // Endpoint: provisionGKEEndpoint,
  815. // Handler: provisionGKEHandler,
  816. // Router: r,
  817. // })
  818. // POST /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoCreateHandler
  819. hrCreateEndpoint := factory.NewAPIEndpoint(
  820. &types.APIRequestMetadata{
  821. Verb: types.APIVerbCreate,
  822. Method: types.HTTPVerbPost,
  823. Path: &types.Path{
  824. Parent: basePath,
  825. RelativePath: relPath + "/helmrepos",
  826. },
  827. Scopes: []types.PermissionScope{
  828. types.UserScope,
  829. types.ProjectScope,
  830. },
  831. },
  832. )
  833. hrCreateHandler := helmrepo.NewHelmRepoCreateHandler(
  834. config,
  835. factory.GetDecoderValidator(),
  836. factory.GetResultWriter(),
  837. )
  838. routes = append(routes, &Route{
  839. Endpoint: hrCreateEndpoint,
  840. Handler: hrCreateHandler,
  841. Router: r,
  842. })
  843. // GET /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoListHandler
  844. hrListEndpoint := factory.NewAPIEndpoint(
  845. &types.APIRequestMetadata{
  846. Verb: types.APIVerbList,
  847. Method: types.HTTPVerbGet,
  848. Path: &types.Path{
  849. Parent: basePath,
  850. RelativePath: relPath + "/helmrepos",
  851. },
  852. Scopes: []types.PermissionScope{
  853. types.UserScope,
  854. types.ProjectScope,
  855. },
  856. },
  857. )
  858. hrListHandler := helmrepo.NewHelmRepoListHandler(
  859. config,
  860. factory.GetResultWriter(),
  861. )
  862. routes = append(routes, &Route{
  863. Endpoint: hrListEndpoint,
  864. Handler: hrListHandler,
  865. Router: r,
  866. })
  867. return routes, newPath
  868. }