project.go 21 KB

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