2
0

project.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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}/usage -> project.NewProjectGetUsageHandler
  123. getUsageEndpoint := factory.NewAPIEndpoint(
  124. &types.APIRequestMetadata{
  125. Verb: types.APIVerbGet,
  126. Method: types.HTTPVerbGet,
  127. Path: &types.Path{
  128. Parent: basePath,
  129. RelativePath: relPath + "/usage",
  130. },
  131. Scopes: []types.PermissionScope{
  132. types.UserScope,
  133. types.ProjectScope,
  134. },
  135. },
  136. )
  137. getUsageHandler := project.NewProjectGetUsageHandler(
  138. config,
  139. factory.GetResultWriter(),
  140. )
  141. routes = append(routes, &Route{
  142. Endpoint: getUsageEndpoint,
  143. Handler: getUsageHandler,
  144. Router: r,
  145. })
  146. // GET /api/projects/{project_id}/billing -> project.NewProjectGetBillingHandler
  147. getBillingEndpoint := factory.NewAPIEndpoint(
  148. &types.APIRequestMetadata{
  149. Verb: types.APIVerbGet,
  150. Method: types.HTTPVerbGet,
  151. Path: &types.Path{
  152. Parent: basePath,
  153. RelativePath: relPath + "/billing",
  154. },
  155. Scopes: []types.PermissionScope{
  156. types.UserScope,
  157. types.ProjectScope,
  158. },
  159. },
  160. )
  161. getBillingHandler := project.NewProjectGetBillingHandler(
  162. config,
  163. factory.GetResultWriter(),
  164. )
  165. routes = append(routes, &Route{
  166. Endpoint: getBillingEndpoint,
  167. Handler: getBillingHandler,
  168. Router: r,
  169. })
  170. // GET /api/projects/{project_id}/billing/token -> billing.NewBillingGetTokenEndpoint
  171. getBillingTokenEndpoint := factory.NewAPIEndpoint(
  172. &types.APIRequestMetadata{
  173. Verb: types.APIVerbGet,
  174. Method: types.HTTPVerbGet,
  175. Path: &types.Path{
  176. Parent: basePath,
  177. RelativePath: relPath + "/billing/token",
  178. },
  179. Scopes: []types.PermissionScope{
  180. types.UserScope,
  181. types.ProjectScope,
  182. types.SettingsScope,
  183. },
  184. },
  185. )
  186. getBillingTokenHandler := billing.NewBillingGetTokenHandler(
  187. config,
  188. factory.GetDecoderValidator(),
  189. factory.GetResultWriter(),
  190. )
  191. routes = append(routes, &Route{
  192. Endpoint: getBillingTokenEndpoint,
  193. Handler: getBillingTokenHandler,
  194. Router: r,
  195. })
  196. // GET /api/billing_webhook -> billing.NewBillingWebhookHandler
  197. getBillingWebhookEndpoint := factory.NewAPIEndpoint(
  198. &types.APIRequestMetadata{
  199. Verb: types.APIVerbCreate,
  200. Method: types.HTTPVerbPost,
  201. Path: &types.Path{
  202. Parent: basePath,
  203. RelativePath: "/billing_webhook",
  204. },
  205. Scopes: []types.PermissionScope{},
  206. },
  207. )
  208. getBillingWebhookHandler := billing.NewBillingWebhookHandler(
  209. config,
  210. factory.GetDecoderValidator(),
  211. )
  212. routes = append(routes, &Route{
  213. Endpoint: getBillingWebhookEndpoint,
  214. Handler: getBillingWebhookHandler,
  215. Router: r,
  216. })
  217. // GET /api/projects/{project_id}/clusters -> cluster.NewClusterListHandler
  218. listClusterEndpoint := factory.NewAPIEndpoint(
  219. &types.APIRequestMetadata{
  220. Verb: types.APIVerbList,
  221. Method: types.HTTPVerbGet,
  222. Path: &types.Path{
  223. Parent: basePath,
  224. RelativePath: relPath + "/clusters",
  225. },
  226. Scopes: []types.PermissionScope{
  227. types.UserScope,
  228. types.ProjectScope,
  229. },
  230. },
  231. )
  232. listClusterHandler := cluster.NewClusterListHandler(
  233. config,
  234. factory.GetResultWriter(),
  235. )
  236. routes = append(routes, &Route{
  237. Endpoint: listClusterEndpoint,
  238. Handler: listClusterHandler,
  239. Router: r,
  240. })
  241. // GET /api/projects/{project_id}/gitrepos -> gitinstallation.NewGitRepoListHandler
  242. listGitReposEndpoint := factory.NewAPIEndpoint(
  243. &types.APIRequestMetadata{
  244. Verb: types.APIVerbList,
  245. Method: types.HTTPVerbGet,
  246. Path: &types.Path{
  247. Parent: basePath,
  248. RelativePath: relPath + "/gitrepos",
  249. },
  250. Scopes: []types.PermissionScope{
  251. types.UserScope,
  252. types.ProjectScope,
  253. },
  254. },
  255. )
  256. listGitReposHandler := gitinstallation.NewGitRepoListHandler(
  257. config,
  258. factory.GetResultWriter(),
  259. )
  260. routes = append(routes, &Route{
  261. Endpoint: listGitReposEndpoint,
  262. Handler: listGitReposHandler,
  263. Router: r,
  264. })
  265. // GET /api/projects/{project_id}/collaborators -> project.NewCollaboratorsListHandler
  266. listCollaboratorsEndpoint := factory.NewAPIEndpoint(
  267. &types.APIRequestMetadata{
  268. Verb: types.APIVerbList,
  269. Method: types.HTTPVerbGet,
  270. Path: &types.Path{
  271. Parent: basePath,
  272. RelativePath: relPath + "/collaborators",
  273. },
  274. Scopes: []types.PermissionScope{
  275. types.UserScope,
  276. types.ProjectScope,
  277. },
  278. },
  279. )
  280. listCollaboratorsHandler := project.NewCollaboratorsListHandler(
  281. config,
  282. factory.GetResultWriter(),
  283. )
  284. routes = append(routes, &Route{
  285. Endpoint: listCollaboratorsEndpoint,
  286. Handler: listCollaboratorsHandler,
  287. Router: r,
  288. })
  289. // GET /api/projects/{project_id}/roles -> project.NewRolesListHandler
  290. listRolesEndpoint := factory.NewAPIEndpoint(
  291. &types.APIRequestMetadata{
  292. Verb: types.APIVerbList,
  293. Method: types.HTTPVerbGet,
  294. Path: &types.Path{
  295. Parent: basePath,
  296. RelativePath: relPath + "/roles",
  297. },
  298. Scopes: []types.PermissionScope{
  299. types.UserScope,
  300. types.ProjectScope,
  301. },
  302. },
  303. )
  304. listRolesHandler := project.NewRolesListHandler(
  305. config,
  306. factory.GetResultWriter(),
  307. )
  308. routes = append(routes, &Route{
  309. Endpoint: listRolesEndpoint,
  310. Handler: listRolesHandler,
  311. Router: r,
  312. })
  313. // POST /api/projects/{project_id}/roles -> project.NewRoleUpdateHandler
  314. updateRoleEndpoint := factory.NewAPIEndpoint(
  315. &types.APIRequestMetadata{
  316. Verb: types.APIVerbUpdate,
  317. Method: types.HTTPVerbPost,
  318. Path: &types.Path{
  319. Parent: basePath,
  320. RelativePath: relPath + "/roles",
  321. },
  322. Scopes: []types.PermissionScope{
  323. types.UserScope,
  324. types.ProjectScope,
  325. },
  326. },
  327. )
  328. updateRoleHandler := project.NewRoleUpdateHandler(
  329. config,
  330. factory.GetDecoderValidator(),
  331. factory.GetResultWriter(),
  332. )
  333. routes = append(routes, &Route{
  334. Endpoint: updateRoleEndpoint,
  335. Handler: updateRoleHandler,
  336. Router: r,
  337. })
  338. // DELETE /api/projects/{project_id}/roles -> project.NewRoleDeleteHandler
  339. deleteRoleEndpoint := factory.NewAPIEndpoint(
  340. &types.APIRequestMetadata{
  341. Verb: types.APIVerbDelete,
  342. Method: types.HTTPVerbDelete,
  343. Path: &types.Path{
  344. Parent: basePath,
  345. RelativePath: relPath + "/roles",
  346. },
  347. Scopes: []types.PermissionScope{
  348. types.UserScope,
  349. types.ProjectScope,
  350. },
  351. },
  352. )
  353. deleteRoleHandler := project.NewRoleDeleteHandler(
  354. config,
  355. factory.GetDecoderValidator(),
  356. factory.GetResultWriter(),
  357. )
  358. routes = append(routes, &Route{
  359. Endpoint: deleteRoleEndpoint,
  360. Handler: deleteRoleHandler,
  361. Router: r,
  362. })
  363. // GET /api/projects/{project_id}/registries -> registry.NewRegistryListHandler
  364. listRegistriesEndpoint := factory.NewAPIEndpoint(
  365. &types.APIRequestMetadata{
  366. Verb: types.APIVerbList,
  367. Method: types.HTTPVerbGet,
  368. Path: &types.Path{
  369. Parent: basePath,
  370. RelativePath: relPath + "/registries",
  371. },
  372. Scopes: []types.PermissionScope{
  373. types.UserScope,
  374. types.ProjectScope,
  375. },
  376. },
  377. )
  378. listRegistriesHandler := registry.NewRegistryListHandler(
  379. config,
  380. factory.GetResultWriter(),
  381. )
  382. routes = append(routes, &Route{
  383. Endpoint: listRegistriesEndpoint,
  384. Handler: listRegistriesHandler,
  385. Router: r,
  386. })
  387. // POST /api/projects/{project_id}/registries -> registry.NewRegistryCreateHandler
  388. createRegistryEndpoint := factory.NewAPIEndpoint(
  389. &types.APIRequestMetadata{
  390. Verb: types.APIVerbCreate,
  391. Method: types.HTTPVerbPost,
  392. Path: &types.Path{
  393. Parent: basePath,
  394. RelativePath: relPath + "/registries",
  395. },
  396. Scopes: []types.PermissionScope{
  397. types.UserScope,
  398. types.ProjectScope,
  399. },
  400. },
  401. )
  402. createRegistryHandler := registry.NewRegistryCreateHandler(
  403. config,
  404. factory.GetDecoderValidator(),
  405. factory.GetResultWriter(),
  406. )
  407. routes = append(routes, &Route{
  408. Endpoint: createRegistryEndpoint,
  409. Handler: createRegistryHandler,
  410. Router: r,
  411. })
  412. // GET /api/projects/{project_id}/registries/ecr/token -> registry.NewRegistryGetECRTokenHandler
  413. getECRTokenEndpoint := factory.NewAPIEndpoint(
  414. &types.APIRequestMetadata{
  415. Verb: types.APIVerbGet,
  416. Method: types.HTTPVerbGet,
  417. Path: &types.Path{
  418. Parent: basePath,
  419. RelativePath: relPath + "/registries/ecr/token",
  420. },
  421. Scopes: []types.PermissionScope{
  422. types.UserScope,
  423. types.ProjectScope,
  424. },
  425. },
  426. )
  427. getECRTokenHandler := registry.NewRegistryGetECRTokenHandler(
  428. config,
  429. factory.GetDecoderValidator(),
  430. factory.GetResultWriter(),
  431. )
  432. routes = append(routes, &Route{
  433. Endpoint: getECRTokenEndpoint,
  434. Handler: getECRTokenHandler,
  435. Router: r,
  436. })
  437. // GET /api/projects/{project_id}/registries/docr/token -> registry.NewRegistryGetDOCRTokenHandler
  438. getDOCRTokenEndpoint := factory.NewAPIEndpoint(
  439. &types.APIRequestMetadata{
  440. Verb: types.APIVerbGet,
  441. Method: types.HTTPVerbGet,
  442. Path: &types.Path{
  443. Parent: basePath,
  444. RelativePath: relPath + "/registries/docr/token",
  445. },
  446. Scopes: []types.PermissionScope{
  447. types.UserScope,
  448. types.ProjectScope,
  449. },
  450. },
  451. )
  452. getDOCRTokenHandler := registry.NewRegistryGetDOCRTokenHandler(
  453. config,
  454. factory.GetDecoderValidator(),
  455. factory.GetResultWriter(),
  456. )
  457. routes = append(routes, &Route{
  458. Endpoint: getDOCRTokenEndpoint,
  459. Handler: getDOCRTokenHandler,
  460. Router: r,
  461. })
  462. // GET /api/projects/{project_id}/registries/gcr/token -> registry.NewRegistryGetGCRTokenHandler
  463. getGCRTokenEndpoint := factory.NewAPIEndpoint(
  464. &types.APIRequestMetadata{
  465. Verb: types.APIVerbGet,
  466. Method: types.HTTPVerbGet,
  467. Path: &types.Path{
  468. Parent: basePath,
  469. RelativePath: relPath + "/registries/gcr/token",
  470. },
  471. Scopes: []types.PermissionScope{
  472. types.UserScope,
  473. types.ProjectScope,
  474. },
  475. },
  476. )
  477. getGCRTokenHandler := registry.NewRegistryGetGCRTokenHandler(
  478. config,
  479. factory.GetDecoderValidator(),
  480. factory.GetResultWriter(),
  481. )
  482. routes = append(routes, &Route{
  483. Endpoint: getGCRTokenEndpoint,
  484. Handler: getGCRTokenHandler,
  485. Router: r,
  486. })
  487. // GET /api/projects/{project_id}/registries/dockerhub/token -> registry.NewRegistryGetDockerhubTokenHandler
  488. getDockerhubTokenEndpoint := factory.NewAPIEndpoint(
  489. &types.APIRequestMetadata{
  490. Verb: types.APIVerbGet,
  491. Method: types.HTTPVerbGet,
  492. Path: &types.Path{
  493. Parent: basePath,
  494. RelativePath: relPath + "/registries/dockerhub/token",
  495. },
  496. Scopes: []types.PermissionScope{
  497. types.UserScope,
  498. types.ProjectScope,
  499. },
  500. },
  501. )
  502. getDockerhubTokenHandler := registry.NewRegistryGetDockerhubTokenHandler(
  503. config,
  504. factory.GetDecoderValidator(),
  505. factory.GetResultWriter(),
  506. )
  507. routes = append(routes, &Route{
  508. Endpoint: getDockerhubTokenEndpoint,
  509. Handler: getDockerhubTokenHandler,
  510. Router: r,
  511. })
  512. // POST /api/projects/{project_id}/provision/ecr -> provision.NewProvisionECRHandler
  513. provisionECREndpoint := factory.NewAPIEndpoint(
  514. &types.APIRequestMetadata{
  515. Verb: types.APIVerbCreate,
  516. Method: types.HTTPVerbPost,
  517. Path: &types.Path{
  518. Parent: basePath,
  519. RelativePath: relPath + "/provision/ecr",
  520. },
  521. Scopes: []types.PermissionScope{
  522. types.UserScope,
  523. types.ProjectScope,
  524. },
  525. },
  526. )
  527. provisionECRHandler := provision.NewProvisionECRHandler(
  528. config,
  529. factory.GetDecoderValidator(),
  530. factory.GetResultWriter(),
  531. )
  532. routes = append(routes, &Route{
  533. Endpoint: provisionECREndpoint,
  534. Handler: provisionECRHandler,
  535. Router: r,
  536. })
  537. // POST /api/projects/{project_id}/provision/eks -> provision.NewProvisionEKSHandler
  538. provisionEKSEndpoint := factory.NewAPIEndpoint(
  539. &types.APIRequestMetadata{
  540. Verb: types.APIVerbCreate,
  541. Method: types.HTTPVerbPost,
  542. Path: &types.Path{
  543. Parent: basePath,
  544. RelativePath: relPath + "/provision/eks",
  545. },
  546. Scopes: []types.PermissionScope{
  547. types.UserScope,
  548. types.ProjectScope,
  549. },
  550. CheckUsage: true,
  551. UsageMetric: types.Clusters,
  552. },
  553. )
  554. provisionEKSHandler := provision.NewProvisionEKSHandler(
  555. config,
  556. factory.GetDecoderValidator(),
  557. factory.GetResultWriter(),
  558. )
  559. routes = append(routes, &Route{
  560. Endpoint: provisionEKSEndpoint,
  561. Handler: provisionEKSHandler,
  562. Router: r,
  563. })
  564. // POST /api/projects/{project_id}/provision/docr -> provision.NewProvisionDOCRHandler
  565. provisionDOCREndpoint := factory.NewAPIEndpoint(
  566. &types.APIRequestMetadata{
  567. Verb: types.APIVerbCreate,
  568. Method: types.HTTPVerbPost,
  569. Path: &types.Path{
  570. Parent: basePath,
  571. RelativePath: relPath + "/provision/docr",
  572. },
  573. Scopes: []types.PermissionScope{
  574. types.UserScope,
  575. types.ProjectScope,
  576. },
  577. },
  578. )
  579. provisionDOCRHandler := provision.NewProvisionDOCRHandler(
  580. config,
  581. factory.GetDecoderValidator(),
  582. factory.GetResultWriter(),
  583. )
  584. routes = append(routes, &Route{
  585. Endpoint: provisionDOCREndpoint,
  586. Handler: provisionDOCRHandler,
  587. Router: r,
  588. })
  589. // POST /api/projects/{project_id}/provision/doks -> provision.NewProvisionDOKSHandler
  590. provisionDOKSEndpoint := factory.NewAPIEndpoint(
  591. &types.APIRequestMetadata{
  592. Verb: types.APIVerbCreate,
  593. Method: types.HTTPVerbPost,
  594. Path: &types.Path{
  595. Parent: basePath,
  596. RelativePath: relPath + "/provision/doks",
  597. },
  598. Scopes: []types.PermissionScope{
  599. types.UserScope,
  600. types.ProjectScope,
  601. },
  602. CheckUsage: true,
  603. UsageMetric: types.Clusters,
  604. },
  605. )
  606. provisionDOKSHandler := provision.NewProvisionDOKSHandler(
  607. config,
  608. factory.GetDecoderValidator(),
  609. factory.GetResultWriter(),
  610. )
  611. routes = append(routes, &Route{
  612. Endpoint: provisionDOKSEndpoint,
  613. Handler: provisionDOKSHandler,
  614. Router: r,
  615. })
  616. // POST /api/projects/{project_id}/provision/gcr -> provision.NewProvisionGCRHandler
  617. provisionGCREndpoint := factory.NewAPIEndpoint(
  618. &types.APIRequestMetadata{
  619. Verb: types.APIVerbCreate,
  620. Method: types.HTTPVerbPost,
  621. Path: &types.Path{
  622. Parent: basePath,
  623. RelativePath: relPath + "/provision/gcr",
  624. },
  625. Scopes: []types.PermissionScope{
  626. types.UserScope,
  627. types.ProjectScope,
  628. },
  629. },
  630. )
  631. provisionGCRHandler := provision.NewProvisionGCRHandler(
  632. config,
  633. factory.GetDecoderValidator(),
  634. factory.GetResultWriter(),
  635. )
  636. routes = append(routes, &Route{
  637. Endpoint: provisionGCREndpoint,
  638. Handler: provisionGCRHandler,
  639. Router: r,
  640. })
  641. // POST /api/projects/{project_id}/provision/gke -> provision.NewProvisionGKEHandler
  642. provisionGKEEndpoint := factory.NewAPIEndpoint(
  643. &types.APIRequestMetadata{
  644. Verb: types.APIVerbCreate,
  645. Method: types.HTTPVerbPost,
  646. Path: &types.Path{
  647. Parent: basePath,
  648. RelativePath: relPath + "/provision/gke",
  649. },
  650. Scopes: []types.PermissionScope{
  651. types.UserScope,
  652. types.ProjectScope,
  653. },
  654. CheckUsage: true,
  655. UsageMetric: types.Clusters,
  656. },
  657. )
  658. provisionGKEHandler := provision.NewProvisionGKEHandler(
  659. config,
  660. factory.GetDecoderValidator(),
  661. factory.GetResultWriter(),
  662. )
  663. routes = append(routes, &Route{
  664. Endpoint: provisionGKEEndpoint,
  665. Handler: provisionGKEHandler,
  666. Router: r,
  667. })
  668. return routes, newPath
  669. }