project.go 25 KB

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