project.go 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. package router
  2. import (
  3. "fmt"
  4. "github.com/go-chi/chi"
  5. "github.com/porter-dev/porter/api/server/handlers/api_token"
  6. "github.com/porter-dev/porter/api/server/handlers/billing"
  7. "github.com/porter-dev/porter/api/server/handlers/cluster"
  8. "github.com/porter-dev/porter/api/server/handlers/gitinstallation"
  9. "github.com/porter-dev/porter/api/server/handlers/infra"
  10. "github.com/porter-dev/porter/api/server/handlers/policy"
  11. "github.com/porter-dev/porter/api/server/handlers/project"
  12. "github.com/porter-dev/porter/api/server/handlers/registry"
  13. "github.com/porter-dev/porter/api/server/shared"
  14. "github.com/porter-dev/porter/api/server/shared/config"
  15. "github.com/porter-dev/porter/api/types"
  16. )
  17. func NewProjectScopedRegisterer(children ...*Registerer) *Registerer {
  18. return &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 ...*Registerer,
  29. ) []*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. ) ([]*Route, *types.Path) {
  47. relPath := "/projects/{project_id}"
  48. newPath := &types.Path{
  49. Parent: basePath,
  50. RelativePath: relPath,
  51. }
  52. routes := make([]*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, &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, &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, &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, &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, &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, &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, &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, &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, &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, &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, &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, &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, &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, &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, &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, &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, &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, &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, &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, &Route{
  536. Endpoint: getGCRTokenEndpoint,
  537. Handler: getGCRTokenHandler,
  538. Router: r,
  539. })
  540. // GET /api/projects/{project_id}/registries/dockerhub/token -> registry.NewRegistryGetDockerhubTokenHandler
  541. getDockerhubTokenEndpoint := factory.NewAPIEndpoint(
  542. &types.APIRequestMetadata{
  543. Verb: types.APIVerbGet,
  544. Method: types.HTTPVerbGet,
  545. Path: &types.Path{
  546. Parent: basePath,
  547. RelativePath: relPath + "/registries/dockerhub/token",
  548. },
  549. Scopes: []types.PermissionScope{
  550. types.UserScope,
  551. types.ProjectScope,
  552. },
  553. },
  554. )
  555. getDockerhubTokenHandler := registry.NewRegistryGetDockerhubTokenHandler(
  556. config,
  557. factory.GetDecoderValidator(),
  558. factory.GetResultWriter(),
  559. )
  560. routes = append(routes, &Route{
  561. Endpoint: getDockerhubTokenEndpoint,
  562. Handler: getDockerhubTokenHandler,
  563. Router: r,
  564. })
  565. // POST /api/projects/{project_id}/infras -> infra.NewInfraCreateHandler
  566. createInfraEndpoint := factory.NewAPIEndpoint(
  567. &types.APIRequestMetadata{
  568. Verb: types.APIVerbCreate,
  569. Method: types.HTTPVerbPost,
  570. Path: &types.Path{
  571. Parent: basePath,
  572. RelativePath: relPath + "/infras",
  573. },
  574. Scopes: []types.PermissionScope{
  575. types.UserScope,
  576. types.ProjectScope,
  577. },
  578. },
  579. )
  580. createInfraHandler := infra.NewInfraCreateHandler(
  581. config,
  582. factory.GetDecoderValidator(),
  583. factory.GetResultWriter(),
  584. )
  585. routes = append(routes, &Route{
  586. Endpoint: createInfraEndpoint,
  587. Handler: createInfraHandler,
  588. Router: r,
  589. })
  590. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  591. getTemplatesEndpoint := factory.NewAPIEndpoint(
  592. &types.APIRequestMetadata{
  593. Verb: types.APIVerbGet,
  594. Method: types.HTTPVerbGet,
  595. Path: &types.Path{
  596. Parent: basePath,
  597. RelativePath: relPath + "/infras/templates",
  598. },
  599. Scopes: []types.PermissionScope{
  600. types.UserScope,
  601. types.ProjectScope,
  602. },
  603. },
  604. )
  605. getTemplatesHandler := infra.NewInfraListTemplateHandler(
  606. config,
  607. factory.GetResultWriter(),
  608. )
  609. routes = append(routes, &Route{
  610. Endpoint: getTemplatesEndpoint,
  611. Handler: getTemplatesHandler,
  612. Router: r,
  613. })
  614. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  615. getTemplateEndpoint := factory.NewAPIEndpoint(
  616. &types.APIRequestMetadata{
  617. Verb: types.APIVerbGet,
  618. Method: types.HTTPVerbGet,
  619. Path: &types.Path{
  620. Parent: basePath,
  621. RelativePath: fmt.Sprintf("%s/infras/templates/{%s}/{%s}", relPath, types.URLParamTemplateName, types.URLParamTemplateVersion),
  622. },
  623. Scopes: []types.PermissionScope{
  624. types.UserScope,
  625. types.ProjectScope,
  626. },
  627. },
  628. )
  629. getTemplateHandler := infra.NewInfraGetTemplateHandler(
  630. config,
  631. factory.GetResultWriter(),
  632. )
  633. routes = append(routes, &Route{
  634. Endpoint: getTemplateEndpoint,
  635. Handler: getTemplateHandler,
  636. Router: r,
  637. })
  638. // // POST /api/projects/{project_id}/provision/ecr -> provision.NewProvisionECRHandler
  639. // provisionECREndpoint := factory.NewAPIEndpoint(
  640. // &types.APIRequestMetadata{
  641. // Verb: types.APIVerbCreate,
  642. // Method: types.HTTPVerbPost,
  643. // Path: &types.Path{
  644. // Parent: basePath,
  645. // RelativePath: relPath + "/provision/ecr",
  646. // },
  647. // Scopes: []types.PermissionScope{
  648. // types.UserScope,
  649. // types.ProjectScope,
  650. // },
  651. // },
  652. // )
  653. // provisionECRHandler := provision.NewProvisionECRHandler(
  654. // config,
  655. // factory.GetDecoderValidator(),
  656. // factory.GetResultWriter(),
  657. // )
  658. // routes = append(routes, &Route{
  659. // Endpoint: provisionECREndpoint,
  660. // Handler: provisionECRHandler,
  661. // Router: r,
  662. // })
  663. // // POST /api/projects/{project_id}/provision/eks -> provision.NewProvisionEKSHandler
  664. // provisionEKSEndpoint := factory.NewAPIEndpoint(
  665. // &types.APIRequestMetadata{
  666. // Verb: types.APIVerbCreate,
  667. // Method: types.HTTPVerbPost,
  668. // Path: &types.Path{
  669. // Parent: basePath,
  670. // RelativePath: relPath + "/provision/eks",
  671. // },
  672. // Scopes: []types.PermissionScope{
  673. // types.UserScope,
  674. // types.ProjectScope,
  675. // },
  676. // CheckUsage: true,
  677. // UsageMetric: types.Clusters,
  678. // },
  679. // )
  680. // provisionEKSHandler := provision.NewProvisionEKSHandler(
  681. // config,
  682. // factory.GetDecoderValidator(),
  683. // factory.GetResultWriter(),
  684. // )
  685. // routes = append(routes, &Route{
  686. // Endpoint: provisionEKSEndpoint,
  687. // Handler: provisionEKSHandler,
  688. // Router: r,
  689. // })
  690. // // POST /api/projects/{project_id}/provision/docr -> provision.NewProvisionDOCRHandler
  691. // provisionDOCREndpoint := factory.NewAPIEndpoint(
  692. // &types.APIRequestMetadata{
  693. // Verb: types.APIVerbCreate,
  694. // Method: types.HTTPVerbPost,
  695. // Path: &types.Path{
  696. // Parent: basePath,
  697. // RelativePath: relPath + "/provision/docr",
  698. // },
  699. // Scopes: []types.PermissionScope{
  700. // types.UserScope,
  701. // types.ProjectScope,
  702. // },
  703. // },
  704. // )
  705. // provisionDOCRHandler := provision.NewProvisionDOCRHandler(
  706. // config,
  707. // factory.GetDecoderValidator(),
  708. // factory.GetResultWriter(),
  709. // )
  710. // routes = append(routes, &Route{
  711. // Endpoint: provisionDOCREndpoint,
  712. // Handler: provisionDOCRHandler,
  713. // Router: r,
  714. // })
  715. // // POST /api/projects/{project_id}/provision/doks -> provision.NewProvisionDOKSHandler
  716. // provisionDOKSEndpoint := factory.NewAPIEndpoint(
  717. // &types.APIRequestMetadata{
  718. // Verb: types.APIVerbCreate,
  719. // Method: types.HTTPVerbPost,
  720. // Path: &types.Path{
  721. // Parent: basePath,
  722. // RelativePath: relPath + "/provision/doks",
  723. // },
  724. // Scopes: []types.PermissionScope{
  725. // types.UserScope,
  726. // types.ProjectScope,
  727. // },
  728. // CheckUsage: true,
  729. // UsageMetric: types.Clusters,
  730. // },
  731. // )
  732. // provisionDOKSHandler := provision.NewProvisionDOKSHandler(
  733. // config,
  734. // factory.GetDecoderValidator(),
  735. // factory.GetResultWriter(),
  736. // )
  737. // routes = append(routes, &Route{
  738. // Endpoint: provisionDOKSEndpoint,
  739. // Handler: provisionDOKSHandler,
  740. // Router: r,
  741. // })
  742. // // POST /api/projects/{project_id}/provision/gcr -> provision.NewProvisionGCRHandler
  743. // provisionGCREndpoint := factory.NewAPIEndpoint(
  744. // &types.APIRequestMetadata{
  745. // Verb: types.APIVerbCreate,
  746. // Method: types.HTTPVerbPost,
  747. // Path: &types.Path{
  748. // Parent: basePath,
  749. // RelativePath: relPath + "/provision/gcr",
  750. // },
  751. // Scopes: []types.PermissionScope{
  752. // types.UserScope,
  753. // types.ProjectScope,
  754. // },
  755. // },
  756. // )
  757. // provisionGCRHandler := provision.NewProvisionGCRHandler(
  758. // config,
  759. // factory.GetDecoderValidator(),
  760. // factory.GetResultWriter(),
  761. // )
  762. // routes = append(routes, &Route{
  763. // Endpoint: provisionGCREndpoint,
  764. // Handler: provisionGCRHandler,
  765. // Router: r,
  766. // })
  767. // // POST /api/projects/{project_id}/provision/gke -> provision.NewProvisionGKEHandler
  768. // provisionGKEEndpoint := factory.NewAPIEndpoint(
  769. // &types.APIRequestMetadata{
  770. // Verb: types.APIVerbCreate,
  771. // Method: types.HTTPVerbPost,
  772. // Path: &types.Path{
  773. // Parent: basePath,
  774. // RelativePath: relPath + "/provision/gke",
  775. // },
  776. // Scopes: []types.PermissionScope{
  777. // types.UserScope,
  778. // types.ProjectScope,
  779. // },
  780. // CheckUsage: true,
  781. // UsageMetric: types.Clusters,
  782. // },
  783. // )
  784. // provisionGKEHandler := provision.NewProvisionGKEHandler(
  785. // config,
  786. // factory.GetDecoderValidator(),
  787. // factory.GetResultWriter(),
  788. // )
  789. // routes = append(routes, &Route{
  790. // Endpoint: provisionGKEEndpoint,
  791. // Handler: provisionGKEHandler,
  792. // Router: r,
  793. // })
  794. // POST /api/projects/{project_id}/policy -> policy.NewPolicyCreateHandler
  795. policyCreateEndpoint := factory.NewAPIEndpoint(
  796. &types.APIRequestMetadata{
  797. Verb: types.APIVerbCreate,
  798. Method: types.HTTPVerbPost,
  799. Path: &types.Path{
  800. Parent: basePath,
  801. RelativePath: relPath + "/policy",
  802. },
  803. Scopes: []types.PermissionScope{
  804. types.UserScope,
  805. types.ProjectScope,
  806. types.SettingsScope,
  807. },
  808. },
  809. )
  810. policyCreateHandler := policy.NewPolicyCreateHandler(
  811. config,
  812. factory.GetDecoderValidator(),
  813. factory.GetResultWriter(),
  814. )
  815. routes = append(routes, &Route{
  816. Endpoint: policyCreateEndpoint,
  817. Handler: policyCreateHandler,
  818. Router: r,
  819. })
  820. // GET /api/projects/{project_id}/policy -> policy.NewPolicyListHandler
  821. policyListEndpoint := factory.NewAPIEndpoint(
  822. &types.APIRequestMetadata{
  823. Verb: types.APIVerbList,
  824. Method: types.HTTPVerbGet,
  825. Path: &types.Path{
  826. Parent: basePath,
  827. RelativePath: relPath + "/policy",
  828. },
  829. Scopes: []types.PermissionScope{
  830. types.UserScope,
  831. types.ProjectScope,
  832. types.SettingsScope,
  833. },
  834. },
  835. )
  836. policyListHandler := policy.NewPolicyListHandler(
  837. config,
  838. factory.GetDecoderValidator(),
  839. factory.GetResultWriter(),
  840. )
  841. routes = append(routes, &Route{
  842. Endpoint: policyListEndpoint,
  843. Handler: policyListHandler,
  844. Router: r,
  845. })
  846. // GET /api/projects/{project_id}/policy/{policy_id} -> policy.NewPolicyGetHandler
  847. policyGetEndpoint := factory.NewAPIEndpoint(
  848. &types.APIRequestMetadata{
  849. Verb: types.APIVerbGet,
  850. Method: types.HTTPVerbGet,
  851. Path: &types.Path{
  852. Parent: basePath,
  853. RelativePath: fmt.Sprintf("%s/policy/{%s}", relPath, types.URLParamPolicyID),
  854. },
  855. Scopes: []types.PermissionScope{
  856. types.UserScope,
  857. types.ProjectScope,
  858. types.SettingsScope,
  859. },
  860. },
  861. )
  862. policyGetHandler := policy.NewPolicyGetHandler(
  863. config,
  864. factory.GetDecoderValidator(),
  865. factory.GetResultWriter(),
  866. )
  867. routes = append(routes, &Route{
  868. Endpoint: policyGetEndpoint,
  869. Handler: policyGetHandler,
  870. Router: r,
  871. })
  872. // POST /api/projects/{project_id}/api_token -> api_token.NewAPITokenCreateHandler
  873. apiTokenCreateEndpoint := factory.NewAPIEndpoint(
  874. &types.APIRequestMetadata{
  875. Verb: types.APIVerbCreate,
  876. Method: types.HTTPVerbPost,
  877. Path: &types.Path{
  878. Parent: basePath,
  879. RelativePath: relPath + "/api_token",
  880. },
  881. Scopes: []types.PermissionScope{
  882. types.UserScope,
  883. types.ProjectScope,
  884. types.SettingsScope,
  885. },
  886. },
  887. )
  888. apiTokenCreateHandler := api_token.NewAPITokenCreateHandler(
  889. config,
  890. factory.GetDecoderValidator(),
  891. factory.GetResultWriter(),
  892. )
  893. routes = append(routes, &Route{
  894. Endpoint: apiTokenCreateEndpoint,
  895. Handler: apiTokenCreateHandler,
  896. Router: r,
  897. })
  898. // GET /api/projects/{project_id}/api_token -> api_token.NewAPITokenListHandler
  899. apiTokenListEndpoint := factory.NewAPIEndpoint(
  900. &types.APIRequestMetadata{
  901. Verb: types.APIVerbList,
  902. Method: types.HTTPVerbGet,
  903. Path: &types.Path{
  904. Parent: basePath,
  905. RelativePath: fmt.Sprintf("%s/api_token", relPath),
  906. },
  907. Scopes: []types.PermissionScope{
  908. types.UserScope,
  909. types.ProjectScope,
  910. types.SettingsScope,
  911. },
  912. },
  913. )
  914. apiTokenListHandler := api_token.NewAPITokenListHandler(
  915. config,
  916. factory.GetDecoderValidator(),
  917. factory.GetResultWriter(),
  918. )
  919. routes = append(routes, &Route{
  920. Endpoint: apiTokenListEndpoint,
  921. Handler: apiTokenListHandler,
  922. Router: r,
  923. })
  924. // GET /api/projects/{project_id}/api_token/{api_token_id} -> api_token.NewAPITokenGetHandler
  925. apiTokenGetEndpoint := factory.NewAPIEndpoint(
  926. &types.APIRequestMetadata{
  927. Verb: types.APIVerbGet,
  928. Method: types.HTTPVerbGet,
  929. Path: &types.Path{
  930. Parent: basePath,
  931. RelativePath: fmt.Sprintf("%s/api_token/{%s}", relPath, types.URLParamTokenID),
  932. },
  933. Scopes: []types.PermissionScope{
  934. types.UserScope,
  935. types.ProjectScope,
  936. types.SettingsScope,
  937. },
  938. },
  939. )
  940. apiTokenGetHandler := api_token.NewAPITokenGetHandler(
  941. config,
  942. factory.GetDecoderValidator(),
  943. factory.GetResultWriter(),
  944. )
  945. routes = append(routes, &Route{
  946. Endpoint: apiTokenGetEndpoint,
  947. Handler: apiTokenGetHandler,
  948. Router: r,
  949. })
  950. return routes, newPath
  951. }