project.go 19 KB

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