project.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  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/helmrepo"
  8. "github.com/porter-dev/porter/api/server/handlers/project"
  9. "github.com/porter-dev/porter/api/server/handlers/provision"
  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}/provision/ecr -> provision.NewProvisionECRHandler
  564. provisionECREndpoint := factory.NewAPIEndpoint(
  565. &types.APIRequestMetadata{
  566. Verb: types.APIVerbCreate,
  567. Method: types.HTTPVerbPost,
  568. Path: &types.Path{
  569. Parent: basePath,
  570. RelativePath: relPath + "/provision/ecr",
  571. },
  572. Scopes: []types.PermissionScope{
  573. types.UserScope,
  574. types.ProjectScope,
  575. },
  576. },
  577. )
  578. provisionECRHandler := provision.NewProvisionECRHandler(
  579. config,
  580. factory.GetDecoderValidator(),
  581. factory.GetResultWriter(),
  582. )
  583. routes = append(routes, &Route{
  584. Endpoint: provisionECREndpoint,
  585. Handler: provisionECRHandler,
  586. Router: r,
  587. })
  588. // POST /api/projects/{project_id}/provision/eks -> provision.NewProvisionEKSHandler
  589. provisionEKSEndpoint := factory.NewAPIEndpoint(
  590. &types.APIRequestMetadata{
  591. Verb: types.APIVerbCreate,
  592. Method: types.HTTPVerbPost,
  593. Path: &types.Path{
  594. Parent: basePath,
  595. RelativePath: relPath + "/provision/eks",
  596. },
  597. Scopes: []types.PermissionScope{
  598. types.UserScope,
  599. types.ProjectScope,
  600. },
  601. CheckUsage: true,
  602. UsageMetric: types.Clusters,
  603. },
  604. )
  605. provisionEKSHandler := provision.NewProvisionEKSHandler(
  606. config,
  607. factory.GetDecoderValidator(),
  608. factory.GetResultWriter(),
  609. )
  610. routes = append(routes, &Route{
  611. Endpoint: provisionEKSEndpoint,
  612. Handler: provisionEKSHandler,
  613. Router: r,
  614. })
  615. // POST /api/projects/{project_id}/provision/docr -> provision.NewProvisionDOCRHandler
  616. provisionDOCREndpoint := factory.NewAPIEndpoint(
  617. &types.APIRequestMetadata{
  618. Verb: types.APIVerbCreate,
  619. Method: types.HTTPVerbPost,
  620. Path: &types.Path{
  621. Parent: basePath,
  622. RelativePath: relPath + "/provision/docr",
  623. },
  624. Scopes: []types.PermissionScope{
  625. types.UserScope,
  626. types.ProjectScope,
  627. },
  628. },
  629. )
  630. provisionDOCRHandler := provision.NewProvisionDOCRHandler(
  631. config,
  632. factory.GetDecoderValidator(),
  633. factory.GetResultWriter(),
  634. )
  635. routes = append(routes, &Route{
  636. Endpoint: provisionDOCREndpoint,
  637. Handler: provisionDOCRHandler,
  638. Router: r,
  639. })
  640. // POST /api/projects/{project_id}/provision/doks -> provision.NewProvisionDOKSHandler
  641. provisionDOKSEndpoint := factory.NewAPIEndpoint(
  642. &types.APIRequestMetadata{
  643. Verb: types.APIVerbCreate,
  644. Method: types.HTTPVerbPost,
  645. Path: &types.Path{
  646. Parent: basePath,
  647. RelativePath: relPath + "/provision/doks",
  648. },
  649. Scopes: []types.PermissionScope{
  650. types.UserScope,
  651. types.ProjectScope,
  652. },
  653. CheckUsage: true,
  654. UsageMetric: types.Clusters,
  655. },
  656. )
  657. provisionDOKSHandler := provision.NewProvisionDOKSHandler(
  658. config,
  659. factory.GetDecoderValidator(),
  660. factory.GetResultWriter(),
  661. )
  662. routes = append(routes, &Route{
  663. Endpoint: provisionDOKSEndpoint,
  664. Handler: provisionDOKSHandler,
  665. Router: r,
  666. })
  667. // POST /api/projects/{project_id}/provision/gcr -> provision.NewProvisionGCRHandler
  668. provisionGCREndpoint := factory.NewAPIEndpoint(
  669. &types.APIRequestMetadata{
  670. Verb: types.APIVerbCreate,
  671. Method: types.HTTPVerbPost,
  672. Path: &types.Path{
  673. Parent: basePath,
  674. RelativePath: relPath + "/provision/gcr",
  675. },
  676. Scopes: []types.PermissionScope{
  677. types.UserScope,
  678. types.ProjectScope,
  679. },
  680. },
  681. )
  682. provisionGCRHandler := provision.NewProvisionGCRHandler(
  683. config,
  684. factory.GetDecoderValidator(),
  685. factory.GetResultWriter(),
  686. )
  687. routes = append(routes, &Route{
  688. Endpoint: provisionGCREndpoint,
  689. Handler: provisionGCRHandler,
  690. Router: r,
  691. })
  692. // POST /api/projects/{project_id}/provision/gke -> provision.NewProvisionGKEHandler
  693. provisionGKEEndpoint := factory.NewAPIEndpoint(
  694. &types.APIRequestMetadata{
  695. Verb: types.APIVerbCreate,
  696. Method: types.HTTPVerbPost,
  697. Path: &types.Path{
  698. Parent: basePath,
  699. RelativePath: relPath + "/provision/gke",
  700. },
  701. Scopes: []types.PermissionScope{
  702. types.UserScope,
  703. types.ProjectScope,
  704. },
  705. CheckUsage: true,
  706. UsageMetric: types.Clusters,
  707. },
  708. )
  709. provisionGKEHandler := provision.NewProvisionGKEHandler(
  710. config,
  711. factory.GetDecoderValidator(),
  712. factory.GetResultWriter(),
  713. )
  714. routes = append(routes, &Route{
  715. Endpoint: provisionGKEEndpoint,
  716. Handler: provisionGKEHandler,
  717. Router: r,
  718. })
  719. // POST /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoCreateHandler
  720. hrCreateEndpoint := factory.NewAPIEndpoint(
  721. &types.APIRequestMetadata{
  722. Verb: types.APIVerbCreate,
  723. Method: types.HTTPVerbPost,
  724. Path: &types.Path{
  725. Parent: basePath,
  726. RelativePath: relPath + "/helmrepos",
  727. },
  728. Scopes: []types.PermissionScope{
  729. types.UserScope,
  730. types.ProjectScope,
  731. },
  732. },
  733. )
  734. hrCreateHandler := helmrepo.NewHelmRepoCreateHandler(
  735. config,
  736. factory.GetDecoderValidator(),
  737. factory.GetResultWriter(),
  738. )
  739. routes = append(routes, &Route{
  740. Endpoint: hrCreateEndpoint,
  741. Handler: hrCreateHandler,
  742. Router: r,
  743. })
  744. // GET /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoListHandler
  745. hrListEndpoint := factory.NewAPIEndpoint(
  746. &types.APIRequestMetadata{
  747. Verb: types.APIVerbList,
  748. Method: types.HTTPVerbGet,
  749. Path: &types.Path{
  750. Parent: basePath,
  751. RelativePath: relPath + "/helmrepos",
  752. },
  753. Scopes: []types.PermissionScope{
  754. types.UserScope,
  755. types.ProjectScope,
  756. },
  757. },
  758. )
  759. hrListHandler := helmrepo.NewHelmRepoListHandler(
  760. config,
  761. factory.GetResultWriter(),
  762. )
  763. routes = append(routes, &Route{
  764. Endpoint: hrListEndpoint,
  765. Handler: hrListHandler,
  766. Router: r,
  767. })
  768. return routes, newPath
  769. }