project.go 30 KB

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