project.go 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828
  1. package router
  2. import (
  3. "fmt"
  4. "github.com/porter-dev/porter/api/server/handlers/deployment_target"
  5. "github.com/go-chi/chi/v5"
  6. apiContract "github.com/porter-dev/porter/api/server/handlers/api_contract"
  7. "github.com/porter-dev/porter/api/server/handlers/api_token"
  8. "github.com/porter-dev/porter/api/server/handlers/billing"
  9. "github.com/porter-dev/porter/api/server/handlers/cluster"
  10. "github.com/porter-dev/porter/api/server/handlers/datastore"
  11. "github.com/porter-dev/porter/api/server/handlers/gitinstallation"
  12. "github.com/porter-dev/porter/api/server/handlers/helmrepo"
  13. "github.com/porter-dev/porter/api/server/handlers/infra"
  14. "github.com/porter-dev/porter/api/server/handlers/policy"
  15. "github.com/porter-dev/porter/api/server/handlers/project"
  16. "github.com/porter-dev/porter/api/server/handlers/registry"
  17. "github.com/porter-dev/porter/api/server/shared"
  18. "github.com/porter-dev/porter/api/server/shared/config"
  19. "github.com/porter-dev/porter/api/server/shared/router"
  20. "github.com/porter-dev/porter/api/types"
  21. )
  22. func NewProjectScopedRegisterer(children ...*router.Registerer) *router.Registerer {
  23. return &router.Registerer{
  24. GetRoutes: GetProjectScopedRoutes,
  25. Children: children,
  26. }
  27. }
  28. func GetProjectScopedRoutes(
  29. r chi.Router,
  30. config *config.Config,
  31. basePath *types.Path,
  32. factory shared.APIEndpointFactory,
  33. children ...*router.Registerer,
  34. ) []*router.Route {
  35. routes, projPath := getProjectRoutes(r, config, basePath, factory)
  36. if len(children) > 0 {
  37. r.Route(projPath.RelativePath, func(r chi.Router) {
  38. for _, child := range children {
  39. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  40. routes = append(routes, childRoutes...)
  41. }
  42. })
  43. }
  44. return routes
  45. }
  46. func getProjectRoutes(
  47. r chi.Router,
  48. config *config.Config,
  49. basePath *types.Path,
  50. factory shared.APIEndpointFactory,
  51. ) ([]*router.Route, *types.Path) {
  52. relPath := "/projects/{project_id}"
  53. newPath := &types.Path{
  54. Parent: basePath,
  55. RelativePath: relPath,
  56. }
  57. routes := make([]*router.Route, 0)
  58. // GET /api/projects/{project_id} -> project.NewProjectGetHandler
  59. getEndpoint := factory.NewAPIEndpoint(
  60. &types.APIRequestMetadata{
  61. Verb: types.APIVerbGet,
  62. Method: types.HTTPVerbGet,
  63. Path: &types.Path{
  64. Parent: basePath,
  65. RelativePath: relPath,
  66. },
  67. Scopes: []types.PermissionScope{
  68. types.UserScope,
  69. types.ProjectScope,
  70. },
  71. },
  72. )
  73. getHandler := project.NewProjectGetHandler(
  74. config,
  75. factory.GetResultWriter(),
  76. )
  77. routes = append(routes, &router.Route{
  78. Endpoint: getEndpoint,
  79. Handler: getHandler,
  80. Router: r,
  81. })
  82. // DELETE /api/projects/{project_id} -> project.NewProjectDeleteHandler
  83. deleteEndpoint := factory.NewAPIEndpoint(
  84. &types.APIRequestMetadata{
  85. Verb: types.APIVerbDelete,
  86. Method: types.HTTPVerbDelete,
  87. Path: &types.Path{
  88. Parent: basePath,
  89. RelativePath: relPath,
  90. },
  91. Scopes: []types.PermissionScope{
  92. types.UserScope,
  93. types.ProjectScope,
  94. },
  95. },
  96. )
  97. deleteHandler := project.NewProjectDeleteHandler(
  98. config,
  99. factory.GetResultWriter(),
  100. )
  101. routes = append(routes, &router.Route{
  102. Endpoint: deleteEndpoint,
  103. Handler: deleteHandler,
  104. Router: r,
  105. })
  106. // GET /api/projects/{project_id}/policy -> project.NewProjectGetPolicyHandler
  107. getPolicyEndpoint := factory.NewAPIEndpoint(
  108. &types.APIRequestMetadata{
  109. Verb: types.APIVerbGet,
  110. Method: types.HTTPVerbGet,
  111. Path: &types.Path{
  112. Parent: basePath,
  113. RelativePath: relPath + "/policy",
  114. },
  115. Scopes: []types.PermissionScope{
  116. types.UserScope,
  117. types.ProjectScope,
  118. },
  119. },
  120. )
  121. getPolicyHandler := project.NewProjectGetPolicyHandler(
  122. config,
  123. factory.GetResultWriter(),
  124. )
  125. routes = append(routes, &router.Route{
  126. Endpoint: getPolicyEndpoint,
  127. Handler: getPolicyHandler,
  128. Router: r,
  129. })
  130. // GET /api/projects/{project_id}/onboarding -> project.NewProjectGetOnboardingHandler
  131. getOnboardingEndpoint := factory.NewAPIEndpoint(
  132. &types.APIRequestMetadata{
  133. Verb: types.APIVerbGet,
  134. Method: types.HTTPVerbGet,
  135. Path: &types.Path{
  136. Parent: basePath,
  137. RelativePath: relPath + "/onboarding",
  138. },
  139. Scopes: []types.PermissionScope{
  140. types.UserScope,
  141. types.ProjectScope,
  142. },
  143. },
  144. )
  145. getOnboardingHandler := project.NewOnboardingGetHandler(
  146. config,
  147. factory.GetDecoderValidator(),
  148. factory.GetResultWriter(),
  149. )
  150. routes = append(routes, &router.Route{
  151. Endpoint: getOnboardingEndpoint,
  152. Handler: getOnboardingHandler,
  153. Router: r,
  154. })
  155. // POST /api/projects/{project_id}/onboarding -> project.NewProjectGetOnboardingHandler
  156. updateOnboardingEndpoint := factory.NewAPIEndpoint(
  157. &types.APIRequestMetadata{
  158. Verb: types.APIVerbUpdate,
  159. Method: types.HTTPVerbPost,
  160. Path: &types.Path{
  161. Parent: basePath,
  162. RelativePath: relPath + "/onboarding",
  163. },
  164. Scopes: []types.PermissionScope{
  165. types.UserScope,
  166. types.ProjectScope,
  167. },
  168. },
  169. )
  170. updateOnboardingHandler := project.NewOnboardingUpdateHandler(
  171. config,
  172. factory.GetDecoderValidator(),
  173. factory.GetResultWriter(),
  174. )
  175. routes = append(routes, &router.Route{
  176. Endpoint: updateOnboardingEndpoint,
  177. Handler: updateOnboardingHandler,
  178. Router: r,
  179. })
  180. // POST /api/projects/{project_id}/onboarding_step -> project.UpdateOnboardingStepHandler
  181. updateOnboardingStepEndpoint := factory.NewAPIEndpoint(
  182. &types.APIRequestMetadata{
  183. Verb: types.APIVerbUpdate,
  184. Method: types.HTTPVerbPost,
  185. Path: &types.Path{
  186. Parent: basePath,
  187. RelativePath: relPath + "/onboarding_step",
  188. },
  189. Scopes: []types.PermissionScope{
  190. types.UserScope,
  191. types.ProjectScope,
  192. },
  193. },
  194. )
  195. updateOnboardingStepHandler := project.NewUpdateOnboardingStepHandler(
  196. config,
  197. factory.GetDecoderValidator(),
  198. factory.GetResultWriter(),
  199. )
  200. routes = append(routes, &router.Route{
  201. Endpoint: updateOnboardingStepEndpoint,
  202. Handler: updateOnboardingStepHandler,
  203. Router: r,
  204. })
  205. // POST /api/projects/{project_id}/invite_admin -> project.NewProjectInviteAdminHandler
  206. projectInviteAdminEndpoint := factory.NewAPIEndpoint(
  207. &types.APIRequestMetadata{
  208. Verb: types.APIVerbCreate,
  209. Method: types.HTTPVerbPost,
  210. Path: &types.Path{
  211. Parent: basePath,
  212. RelativePath: relPath + "/invite_admin",
  213. },
  214. Scopes: []types.PermissionScope{
  215. types.UserScope,
  216. types.ProjectScope,
  217. },
  218. },
  219. )
  220. projectInviteAdminHandler := project.NewProjectInviteAdminHandler(
  221. config,
  222. factory.GetDecoderValidator(),
  223. factory.GetResultWriter(),
  224. )
  225. routes = append(routes, &router.Route{
  226. Endpoint: projectInviteAdminEndpoint,
  227. Handler: projectInviteAdminHandler,
  228. Router: r,
  229. })
  230. // GET /api/projects/{project_id}/usage -> project.NewProjectGetUsageHandler
  231. getUsageEndpoint := factory.NewAPIEndpoint(
  232. &types.APIRequestMetadata{
  233. Verb: types.APIVerbGet,
  234. Method: types.HTTPVerbGet,
  235. Path: &types.Path{
  236. Parent: basePath,
  237. RelativePath: relPath + "/usage",
  238. },
  239. Scopes: []types.PermissionScope{
  240. types.UserScope,
  241. types.ProjectScope,
  242. },
  243. },
  244. )
  245. getUsageHandler := project.NewProjectGetUsageHandler(
  246. config,
  247. factory.GetResultWriter(),
  248. )
  249. routes = append(routes, &router.Route{
  250. Endpoint: getUsageEndpoint,
  251. Handler: getUsageHandler,
  252. Router: r,
  253. })
  254. // GET /api/projects/{project_id}/billing -> project.NewCheckPaymentEnabledHandler
  255. checkPaymentEndpoint := factory.NewAPIEndpoint(
  256. &types.APIRequestMetadata{
  257. Verb: types.APIVerbGet,
  258. Method: types.HTTPVerbGet,
  259. Path: &types.Path{
  260. Parent: basePath,
  261. RelativePath: relPath + "/billing",
  262. },
  263. Scopes: []types.PermissionScope{
  264. types.UserScope,
  265. types.ProjectScope,
  266. },
  267. },
  268. )
  269. checkPaymentHandler := billing.NewCheckPaymentEnabledHandler(
  270. config,
  271. factory.GetResultWriter(),
  272. )
  273. routes = append(routes, &router.Route{
  274. Endpoint: checkPaymentEndpoint,
  275. Handler: checkPaymentHandler,
  276. Router: r,
  277. })
  278. // GET /api/projects/{project_id}/billing/payment_method -> project.NewListBillingHandler
  279. listBillingEndpoint := factory.NewAPIEndpoint(
  280. &types.APIRequestMetadata{
  281. Verb: types.APIVerbGet,
  282. Method: types.HTTPVerbGet,
  283. Path: &types.Path{
  284. Parent: basePath,
  285. RelativePath: relPath + "/billing/payment_method",
  286. },
  287. Scopes: []types.PermissionScope{
  288. types.UserScope,
  289. types.ProjectScope,
  290. },
  291. },
  292. )
  293. listBillingHandler := billing.NewListBillingHandler(
  294. config,
  295. factory.GetResultWriter(),
  296. )
  297. routes = append(routes, &router.Route{
  298. Endpoint: listBillingEndpoint,
  299. Handler: listBillingHandler,
  300. Router: r,
  301. })
  302. // POST /api/projects/{project_id}/billing/payment_method -> project.NewCreateBillingHandler
  303. createBillingEndpoint := factory.NewAPIEndpoint(
  304. &types.APIRequestMetadata{
  305. Verb: types.APIVerbCreate,
  306. Method: types.HTTPVerbPost,
  307. Path: &types.Path{
  308. Parent: basePath,
  309. RelativePath: relPath + "/billing/payment_method",
  310. },
  311. Scopes: []types.PermissionScope{
  312. types.UserScope,
  313. types.ProjectScope,
  314. },
  315. },
  316. )
  317. createBillingHandler := billing.NewCreateBillingHandler(
  318. config,
  319. factory.GetDecoderValidator(),
  320. factory.GetResultWriter(),
  321. )
  322. routes = append(routes, &router.Route{
  323. Endpoint: createBillingEndpoint,
  324. Handler: createBillingHandler,
  325. Router: r,
  326. })
  327. // PUT /api/projects/{project_id}/billing/payment_method/{payment_method_id}/default -> project.NewSetDefaultBillingHandler
  328. setDefaultBillingEndpoint := factory.NewAPIEndpoint(
  329. &types.APIRequestMetadata{
  330. Verb: types.APIVerbUpdate,
  331. Method: types.HTTPVerbPut,
  332. Path: &types.Path{
  333. Parent: basePath,
  334. RelativePath: fmt.Sprintf("%s/billing/payment_method/{%s}/default", relPath, types.URLParamPaymentMethodID),
  335. },
  336. Scopes: []types.PermissionScope{
  337. types.UserScope,
  338. types.ProjectScope,
  339. },
  340. },
  341. )
  342. setDefaultBillingHandler := billing.NewSetDefaultBillingHandler(
  343. config,
  344. factory.GetResultWriter(),
  345. )
  346. routes = append(routes, &router.Route{
  347. Endpoint: setDefaultBillingEndpoint,
  348. Handler: setDefaultBillingHandler,
  349. Router: r,
  350. })
  351. // DELETE /api/projects/{project_id}/billing/payment_method/{payment_method_id} -> project.NewDeleteBillingHandler
  352. deleteBillingEndpoint := factory.NewAPIEndpoint(
  353. &types.APIRequestMetadata{
  354. Verb: types.APIVerbDelete,
  355. Method: types.HTTPVerbDelete,
  356. Path: &types.Path{
  357. Parent: basePath,
  358. RelativePath: fmt.Sprintf("%s/billing/payment_method/{%s}", relPath, types.URLParamPaymentMethodID),
  359. },
  360. Scopes: []types.PermissionScope{
  361. types.UserScope,
  362. types.ProjectScope,
  363. },
  364. },
  365. )
  366. deleteBillingHandler := billing.NewDeleteBillingHandler(
  367. config,
  368. factory.GetResultWriter(),
  369. )
  370. routes = append(routes, &router.Route{
  371. Endpoint: deleteBillingEndpoint,
  372. Handler: deleteBillingHandler,
  373. Router: r,
  374. })
  375. // POST /api/projects/{project_id}/billing/customer/ -> project.NewGetOrCreateCustomerHandler
  376. getOrCreateBillingCustomerEndpoint := factory.NewAPIEndpoint(
  377. &types.APIRequestMetadata{
  378. Verb: types.APIVerbCreate,
  379. Method: types.HTTPVerbPost,
  380. Path: &types.Path{
  381. Parent: basePath,
  382. RelativePath: relPath + "/billing/customer",
  383. },
  384. Scopes: []types.PermissionScope{
  385. types.UserScope,
  386. types.ProjectScope,
  387. },
  388. },
  389. )
  390. getOrCreateBillingCustomerHandler := billing.NewCreateBillingCustomerIfNotExists(
  391. config,
  392. factory.GetResultWriter(),
  393. )
  394. routes = append(routes, &router.Route{
  395. Endpoint: getOrCreateBillingCustomerEndpoint,
  396. Handler: getOrCreateBillingCustomerHandler,
  397. Router: r,
  398. })
  399. // GET /api/projects/{project_id}/billing/publishable_key -> project.NewGetPublishableKeyHandler
  400. publishableKeyEndpoint := factory.NewAPIEndpoint(
  401. &types.APIRequestMetadata{
  402. Verb: types.APIVerbGet,
  403. Method: types.HTTPVerbGet,
  404. Path: &types.Path{
  405. Parent: basePath,
  406. RelativePath: relPath + "/billing/publishable_key",
  407. },
  408. Scopes: []types.PermissionScope{
  409. types.ProjectScope,
  410. },
  411. },
  412. )
  413. publishableKeyHandler := billing.NewGetPublishableKeyHandler(
  414. config,
  415. factory.GetDecoderValidator(),
  416. factory.GetResultWriter(),
  417. )
  418. routes = append(routes, &router.Route{
  419. Endpoint: publishableKeyEndpoint,
  420. Handler: publishableKeyHandler,
  421. Router: r,
  422. })
  423. // GET /api/projects/{project_id}/clusters -> cluster.NewClusterListHandler
  424. listClusterEndpoint := factory.NewAPIEndpoint(
  425. &types.APIRequestMetadata{
  426. Verb: types.APIVerbList,
  427. Method: types.HTTPVerbGet,
  428. Path: &types.Path{
  429. Parent: basePath,
  430. RelativePath: relPath + "/clusters",
  431. },
  432. Scopes: []types.PermissionScope{
  433. types.UserScope,
  434. types.ProjectScope,
  435. },
  436. },
  437. )
  438. listClusterHandler := cluster.NewClusterListHandler(
  439. config,
  440. factory.GetResultWriter(),
  441. )
  442. routes = append(routes, &router.Route{
  443. Endpoint: listClusterEndpoint,
  444. Handler: listClusterHandler,
  445. Router: r,
  446. })
  447. // GET /api/projects/{project_id}/gitrepos -> gitinstallation.NewGitRepoListHandler
  448. listGitReposEndpoint := factory.NewAPIEndpoint(
  449. &types.APIRequestMetadata{
  450. Verb: types.APIVerbList,
  451. Method: types.HTTPVerbGet,
  452. Path: &types.Path{
  453. Parent: basePath,
  454. RelativePath: relPath + "/gitrepos",
  455. },
  456. Scopes: []types.PermissionScope{
  457. types.UserScope,
  458. types.ProjectScope,
  459. },
  460. },
  461. )
  462. listGitReposHandler := gitinstallation.NewGitRepoListHandler(
  463. config,
  464. factory.GetResultWriter(),
  465. )
  466. routes = append(routes, &router.Route{
  467. Endpoint: listGitReposEndpoint,
  468. Handler: listGitReposHandler,
  469. Router: r,
  470. })
  471. // GET /api/projects/{project_id}/collaborators -> project.NewCollaboratorsListHandler
  472. listCollaboratorsEndpoint := factory.NewAPIEndpoint(
  473. &types.APIRequestMetadata{
  474. Verb: types.APIVerbList,
  475. Method: types.HTTPVerbGet,
  476. Path: &types.Path{
  477. Parent: basePath,
  478. RelativePath: relPath + "/collaborators",
  479. },
  480. Scopes: []types.PermissionScope{
  481. types.UserScope,
  482. types.ProjectScope,
  483. },
  484. },
  485. )
  486. listCollaboratorsHandler := project.NewCollaboratorsListHandler(
  487. config,
  488. factory.GetResultWriter(),
  489. )
  490. routes = append(routes, &router.Route{
  491. Endpoint: listCollaboratorsEndpoint,
  492. Handler: listCollaboratorsHandler,
  493. Router: r,
  494. })
  495. // GET /api/projects/{project_id}/roles -> project.NewRolesListHandler
  496. listRolesEndpoint := factory.NewAPIEndpoint(
  497. &types.APIRequestMetadata{
  498. Verb: types.APIVerbList,
  499. Method: types.HTTPVerbGet,
  500. Path: &types.Path{
  501. Parent: basePath,
  502. RelativePath: relPath + "/roles",
  503. },
  504. Scopes: []types.PermissionScope{
  505. types.UserScope,
  506. types.ProjectScope,
  507. },
  508. },
  509. )
  510. listRolesHandler := project.NewRolesListHandler(
  511. config,
  512. factory.GetResultWriter(),
  513. )
  514. routes = append(routes, &router.Route{
  515. Endpoint: listRolesEndpoint,
  516. Handler: listRolesHandler,
  517. Router: r,
  518. })
  519. // GET /api/projects/{project_id}/datastores -> datastore.NewListAllDatastoresForProjectHandler
  520. listDatastoresEndpoint := factory.NewAPIEndpoint(
  521. &types.APIRequestMetadata{
  522. Verb: types.APIVerbList,
  523. Method: types.HTTPVerbGet,
  524. Path: &types.Path{
  525. Parent: basePath,
  526. RelativePath: relPath + "/datastores",
  527. },
  528. Scopes: []types.PermissionScope{
  529. types.UserScope,
  530. types.ProjectScope,
  531. },
  532. },
  533. )
  534. listDatastoresHandler := datastore.NewListDatastoresHandler(
  535. config,
  536. factory.GetDecoderValidator(),
  537. factory.GetResultWriter(),
  538. )
  539. routes = append(routes, &router.Route{
  540. Endpoint: listDatastoresEndpoint,
  541. Handler: listDatastoresHandler,
  542. Router: r,
  543. })
  544. // GET /api/projects/{project_id}/datastores -> datastore.NewGetDatastoreHandler
  545. getDatastoreEndpoint := factory.NewAPIEndpoint(
  546. &types.APIRequestMetadata{
  547. Verb: types.APIVerbList,
  548. Method: types.HTTPVerbGet,
  549. Path: &types.Path{
  550. Parent: basePath,
  551. RelativePath: fmt.Sprintf("%s/datastores/{%s}", relPath, types.URLParamDatastoreName),
  552. },
  553. Scopes: []types.PermissionScope{
  554. types.UserScope,
  555. types.ProjectScope,
  556. },
  557. },
  558. )
  559. getDatastoreHandler := datastore.NewGetDatastoreHandler(
  560. config,
  561. factory.GetDecoderValidator(),
  562. factory.GetResultWriter(),
  563. )
  564. routes = append(routes, &router.Route{
  565. Endpoint: getDatastoreEndpoint,
  566. Handler: getDatastoreHandler,
  567. Router: r,
  568. })
  569. // GET /api/projects/{project_id}/datastores -> datastore.NewGetDatastoreCredentialHandler
  570. getDatastoreCredentialEndpoint := factory.NewAPIEndpoint(
  571. &types.APIRequestMetadata{
  572. Verb: types.APIVerbList,
  573. Method: types.HTTPVerbGet,
  574. Path: &types.Path{
  575. Parent: basePath,
  576. RelativePath: fmt.Sprintf("%s/datastores/{%s}/credential", relPath, types.URLParamDatastoreName),
  577. },
  578. Scopes: []types.PermissionScope{
  579. types.UserScope,
  580. types.ProjectScope,
  581. },
  582. },
  583. )
  584. getDatastoreCredentialHandler := datastore.NewGetDatastoreCredentialHandler(
  585. config,
  586. factory.GetDecoderValidator(),
  587. factory.GetResultWriter(),
  588. )
  589. routes = append(routes, &router.Route{
  590. Endpoint: getDatastoreCredentialEndpoint,
  591. Handler: getDatastoreCredentialHandler,
  592. Router: r,
  593. })
  594. // POST /api/projects/{project_id}/datastores/{datastore_name}/create-proxy -> cluster.NewCreateDatastoreProxyHandler
  595. createDatastoreProxyEndpoint := factory.NewAPIEndpoint(
  596. &types.APIRequestMetadata{
  597. Verb: types.APIVerbUpdate,
  598. Method: types.HTTPVerbPost,
  599. Path: &types.Path{
  600. Parent: basePath,
  601. RelativePath: fmt.Sprintf("%s/datastores/{%s}/create-proxy", relPath, types.URLParamDatastoreName),
  602. },
  603. Scopes: []types.PermissionScope{
  604. types.UserScope,
  605. types.ProjectScope,
  606. },
  607. },
  608. )
  609. createDatastoreProxyHandler := datastore.NewCreateDatastoreProxyHandler(
  610. config,
  611. factory.GetDecoderValidator(),
  612. factory.GetResultWriter(),
  613. )
  614. routes = append(routes, &router.Route{
  615. Endpoint: createDatastoreProxyEndpoint,
  616. Handler: createDatastoreProxyHandler,
  617. Router: r,
  618. })
  619. // DELETE /api/projects/{project_id}/datastores/{datastore_name} -> cloud_provider.NewDeleteDatastoreHandler
  620. deleteDatastoreEndpoint := factory.NewAPIEndpoint(
  621. &types.APIRequestMetadata{
  622. Verb: types.APIVerbDelete,
  623. Method: types.HTTPVerbDelete,
  624. Path: &types.Path{
  625. Parent: basePath,
  626. RelativePath: fmt.Sprintf("%s/datastores/{%s}", relPath, types.URLParamDatastoreName),
  627. },
  628. Scopes: []types.PermissionScope{
  629. types.UserScope,
  630. types.ProjectScope,
  631. },
  632. },
  633. )
  634. deleteDatastoreHandler := datastore.NewDeleteDatastoreHandler(
  635. config,
  636. factory.GetDecoderValidator(),
  637. factory.GetResultWriter(),
  638. )
  639. routes = append(routes, &router.Route{
  640. Endpoint: deleteDatastoreEndpoint,
  641. Handler: deleteDatastoreHandler,
  642. Router: r,
  643. })
  644. // POST /api/projects/{project_id}/roles -> project.NewRoleUpdateHandler
  645. updateRoleEndpoint := factory.NewAPIEndpoint(
  646. &types.APIRequestMetadata{
  647. Verb: types.APIVerbUpdate,
  648. Method: types.HTTPVerbPost,
  649. Path: &types.Path{
  650. Parent: basePath,
  651. RelativePath: relPath + "/roles",
  652. },
  653. Scopes: []types.PermissionScope{
  654. types.UserScope,
  655. types.ProjectScope,
  656. },
  657. },
  658. )
  659. updateRoleHandler := project.NewRoleUpdateHandler(
  660. config,
  661. factory.GetDecoderValidator(),
  662. factory.GetResultWriter(),
  663. )
  664. routes = append(routes, &router.Route{
  665. Endpoint: updateRoleEndpoint,
  666. Handler: updateRoleHandler,
  667. Router: r,
  668. })
  669. // DELETE /api/projects/{project_id}/roles -> project.NewRoleDeleteHandler
  670. deleteRoleEndpoint := factory.NewAPIEndpoint(
  671. &types.APIRequestMetadata{
  672. Verb: types.APIVerbDelete,
  673. Method: types.HTTPVerbDelete,
  674. Path: &types.Path{
  675. Parent: basePath,
  676. RelativePath: relPath + "/roles",
  677. },
  678. Scopes: []types.PermissionScope{
  679. types.UserScope,
  680. types.ProjectScope,
  681. },
  682. },
  683. )
  684. deleteRoleHandler := project.NewRoleDeleteHandler(
  685. config,
  686. factory.GetDecoderValidator(),
  687. factory.GetResultWriter(),
  688. )
  689. routes = append(routes, &router.Route{
  690. Endpoint: deleteRoleEndpoint,
  691. Handler: deleteRoleHandler,
  692. Router: r,
  693. })
  694. // GET /api/projects/{project_id}/registries -> registry.NewRegistryListHandler
  695. listRegistriesEndpoint := factory.NewAPIEndpoint(
  696. &types.APIRequestMetadata{
  697. Verb: types.APIVerbList,
  698. Method: types.HTTPVerbGet,
  699. Path: &types.Path{
  700. Parent: basePath,
  701. RelativePath: relPath + "/registries",
  702. },
  703. Scopes: []types.PermissionScope{
  704. types.UserScope,
  705. types.ProjectScope,
  706. },
  707. },
  708. )
  709. listRegistriesHandler := registry.NewRegistryListHandler(
  710. config,
  711. factory.GetResultWriter(),
  712. )
  713. routes = append(routes, &router.Route{
  714. Endpoint: listRegistriesEndpoint,
  715. Handler: listRegistriesHandler,
  716. Router: r,
  717. })
  718. // POST /api/projects/{project_id}/registries -> registry.NewRegistryCreateHandler
  719. createRegistryEndpoint := factory.NewAPIEndpoint(
  720. &types.APIRequestMetadata{
  721. Verb: types.APIVerbCreate,
  722. Method: types.HTTPVerbPost,
  723. Path: &types.Path{
  724. Parent: basePath,
  725. RelativePath: relPath + "/registries",
  726. },
  727. Scopes: []types.PermissionScope{
  728. types.UserScope,
  729. types.ProjectScope,
  730. },
  731. },
  732. )
  733. createRegistryHandler := registry.NewRegistryCreateHandler(
  734. config,
  735. factory.GetDecoderValidator(),
  736. factory.GetResultWriter(),
  737. )
  738. routes = append(routes, &router.Route{
  739. Endpoint: createRegistryEndpoint,
  740. Handler: createRegistryHandler,
  741. Router: r,
  742. })
  743. // GET /api/projects/{project_id}/registries/ecr/token -> registry.NewRegistryGetECRTokenHandler
  744. getECRTokenEndpoint := factory.NewAPIEndpoint(
  745. &types.APIRequestMetadata{
  746. Verb: types.APIVerbGet,
  747. Method: types.HTTPVerbGet,
  748. Path: &types.Path{
  749. Parent: basePath,
  750. RelativePath: relPath + "/registries/ecr/token",
  751. },
  752. Scopes: []types.PermissionScope{
  753. types.UserScope,
  754. types.ProjectScope,
  755. },
  756. },
  757. )
  758. getECRTokenHandler := registry.NewRegistryGetECRTokenHandler(
  759. config,
  760. factory.GetDecoderValidator(),
  761. factory.GetResultWriter(),
  762. )
  763. routes = append(routes, &router.Route{
  764. Endpoint: getECRTokenEndpoint,
  765. Handler: getECRTokenHandler,
  766. Router: r,
  767. })
  768. // GET /api/projects/{project_id}/registries/docr/token -> registry.NewRegistryGetDOCRTokenHandler
  769. getDOCRTokenEndpoint := factory.NewAPIEndpoint(
  770. &types.APIRequestMetadata{
  771. Verb: types.APIVerbGet,
  772. Method: types.HTTPVerbGet,
  773. Path: &types.Path{
  774. Parent: basePath,
  775. RelativePath: relPath + "/registries/docr/token",
  776. },
  777. Scopes: []types.PermissionScope{
  778. types.UserScope,
  779. types.ProjectScope,
  780. },
  781. },
  782. )
  783. getDOCRTokenHandler := registry.NewRegistryGetDOCRTokenHandler(
  784. config,
  785. factory.GetDecoderValidator(),
  786. factory.GetResultWriter(),
  787. )
  788. routes = append(routes, &router.Route{
  789. Endpoint: getDOCRTokenEndpoint,
  790. Handler: getDOCRTokenHandler,
  791. Router: r,
  792. })
  793. // GET /api/projects/{project_id}/registries/gcr/token -> registry.NewRegistryGetGCRTokenHandler
  794. getGCRTokenEndpoint := factory.NewAPIEndpoint(
  795. &types.APIRequestMetadata{
  796. Verb: types.APIVerbGet,
  797. Method: types.HTTPVerbGet,
  798. Path: &types.Path{
  799. Parent: basePath,
  800. RelativePath: relPath + "/registries/gcr/token",
  801. },
  802. Scopes: []types.PermissionScope{
  803. types.UserScope,
  804. types.ProjectScope,
  805. },
  806. },
  807. )
  808. getGCRTokenHandler := registry.NewRegistryGetGCRTokenHandler(
  809. config,
  810. factory.GetDecoderValidator(),
  811. factory.GetResultWriter(),
  812. )
  813. routes = append(routes, &router.Route{
  814. Endpoint: getGCRTokenEndpoint,
  815. Handler: getGCRTokenHandler,
  816. Router: r,
  817. })
  818. // GET /api/projects/{project_id}/registries/gar/token -> registry.NewRegistryGetGARTokenHandler
  819. getGARTokenEndpoint := factory.NewAPIEndpoint(
  820. &types.APIRequestMetadata{
  821. Verb: types.APIVerbGet,
  822. Method: types.HTTPVerbGet,
  823. Path: &types.Path{
  824. Parent: basePath,
  825. RelativePath: relPath + "/registries/gar/token",
  826. },
  827. Scopes: []types.PermissionScope{
  828. types.UserScope,
  829. types.ProjectScope,
  830. },
  831. },
  832. )
  833. getGARTokenHandler := registry.NewRegistryGetGARTokenHandler(
  834. config,
  835. factory.GetDecoderValidator(),
  836. factory.GetResultWriter(),
  837. )
  838. routes = append(routes, &router.Route{
  839. Endpoint: getGARTokenEndpoint,
  840. Handler: getGARTokenHandler,
  841. Router: r,
  842. })
  843. // GET /api/projects/{project_id}/registries/acr/token -> registry.NewRegistryGetACRTokenHandler
  844. getACRTokenEndpoint := factory.NewAPIEndpoint(
  845. &types.APIRequestMetadata{
  846. Verb: types.APIVerbGet,
  847. Method: types.HTTPVerbGet,
  848. Path: &types.Path{
  849. Parent: basePath,
  850. RelativePath: relPath + "/registries/acr/token",
  851. },
  852. Scopes: []types.PermissionScope{
  853. types.UserScope,
  854. types.ProjectScope,
  855. },
  856. },
  857. )
  858. getACRTokenHandler := registry.NewRegistryGetACRTokenHandler(
  859. config,
  860. factory.GetDecoderValidator(),
  861. factory.GetResultWriter(),
  862. )
  863. routes = append(routes, &router.Route{
  864. Endpoint: getACRTokenEndpoint,
  865. Handler: getACRTokenHandler,
  866. Router: r,
  867. })
  868. // GET /api/projects/{project_id}/registries/dockerhub/token -> registry.NewRegistryGetDockerhubTokenHandler
  869. getDockerhubTokenEndpoint := factory.NewAPIEndpoint(
  870. &types.APIRequestMetadata{
  871. Verb: types.APIVerbGet,
  872. Method: types.HTTPVerbGet,
  873. Path: &types.Path{
  874. Parent: basePath,
  875. RelativePath: relPath + "/registries/dockerhub/token",
  876. },
  877. Scopes: []types.PermissionScope{
  878. types.UserScope,
  879. types.ProjectScope,
  880. },
  881. },
  882. )
  883. getDockerhubTokenHandler := registry.NewRegistryGetDockerhubTokenHandler(
  884. config,
  885. factory.GetDecoderValidator(),
  886. factory.GetResultWriter(),
  887. )
  888. routes = append(routes, &router.Route{
  889. Endpoint: getDockerhubTokenEndpoint,
  890. Handler: getDockerhubTokenHandler,
  891. Router: r,
  892. })
  893. // POST /api/projects/{project_id}/infras -> infra.NewInfraCreateHandler
  894. createInfraEndpoint := factory.NewAPIEndpoint(
  895. &types.APIRequestMetadata{
  896. Verb: types.APIVerbCreate,
  897. Method: types.HTTPVerbPost,
  898. Path: &types.Path{
  899. Parent: basePath,
  900. RelativePath: relPath + "/infras",
  901. },
  902. Scopes: []types.PermissionScope{
  903. types.UserScope,
  904. types.ProjectScope,
  905. },
  906. },
  907. )
  908. createInfraHandler := infra.NewInfraCreateHandler(
  909. config,
  910. factory.GetDecoderValidator(),
  911. factory.GetResultWriter(),
  912. )
  913. routes = append(routes, &router.Route{
  914. Endpoint: createInfraEndpoint,
  915. Handler: createInfraHandler,
  916. Router: r,
  917. })
  918. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  919. getTemplatesEndpoint := factory.NewAPIEndpoint(
  920. &types.APIRequestMetadata{
  921. Verb: types.APIVerbGet,
  922. Method: types.HTTPVerbGet,
  923. Path: &types.Path{
  924. Parent: basePath,
  925. RelativePath: relPath + "/infras/templates",
  926. },
  927. Scopes: []types.PermissionScope{
  928. types.UserScope,
  929. types.ProjectScope,
  930. },
  931. },
  932. )
  933. getTemplatesHandler := infra.NewInfraListTemplateHandler(
  934. config,
  935. factory.GetResultWriter(),
  936. )
  937. routes = append(routes, &router.Route{
  938. Endpoint: getTemplatesEndpoint,
  939. Handler: getTemplatesHandler,
  940. Router: r,
  941. })
  942. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  943. getTemplateEndpoint := factory.NewAPIEndpoint(
  944. &types.APIRequestMetadata{
  945. Verb: types.APIVerbGet,
  946. Method: types.HTTPVerbGet,
  947. Path: &types.Path{
  948. Parent: basePath,
  949. RelativePath: fmt.Sprintf("%s/infras/templates/{%s}/{%s}", relPath, types.URLParamTemplateName, types.URLParamTemplateVersion),
  950. },
  951. Scopes: []types.PermissionScope{
  952. types.UserScope,
  953. types.ProjectScope,
  954. },
  955. },
  956. )
  957. getTemplateHandler := infra.NewInfraGetTemplateHandler(
  958. config,
  959. factory.GetResultWriter(),
  960. )
  961. routes = append(routes, &router.Route{
  962. Endpoint: getTemplateEndpoint,
  963. Handler: getTemplateHandler,
  964. Router: r,
  965. })
  966. // // POST /api/projects/{project_id}/provision/ecr -> provision.NewProvisionECRHandler
  967. // provisionECREndpoint := factory.NewAPIEndpoint(
  968. // &types.APIRequestMetadata{
  969. // Verb: types.APIVerbCreate,
  970. // Method: types.HTTPVerbPost,
  971. // Path: &types.Path{
  972. // Parent: basePath,
  973. // RelativePath: relPath + "/provision/ecr",
  974. // },
  975. // Scopes: []types.PermissionScope{
  976. // types.UserScope,
  977. // types.ProjectScope,
  978. // },
  979. // },
  980. // )
  981. // provisionECRHandler := provision.NewProvisionECRHandler(
  982. // config,
  983. // factory.GetDecoderValidator(),
  984. // factory.GetResultWriter(),
  985. // )
  986. // routes = append(routes, &router.Route{
  987. // Endpoint: provisionECREndpoint,
  988. // Handler: provisionECRHandler,
  989. // Router: r,
  990. // })
  991. // // POST /api/projects/{project_id}/provision/eks -> provision.NewProvisionEKSHandler
  992. // provisionEKSEndpoint := factory.NewAPIEndpoint(
  993. // &types.APIRequestMetadata{
  994. // Verb: types.APIVerbCreate,
  995. // Method: types.HTTPVerbPost,
  996. // Path: &types.Path{
  997. // Parent: basePath,
  998. // RelativePath: relPath + "/provision/eks",
  999. // },
  1000. // Scopes: []types.PermissionScope{
  1001. // types.UserScope,
  1002. // types.ProjectScope,
  1003. // },
  1004. // CheckUsage: true,
  1005. // UsageMetric: types.Clusters,
  1006. // },
  1007. // )
  1008. // provisionEKSHandler := provision.NewProvisionEKSHandler(
  1009. // config,
  1010. // factory.GetDecoderValidator(),
  1011. // factory.GetResultWriter(),
  1012. // )
  1013. // routes = append(routes, &router.Route{
  1014. // Endpoint: provisionEKSEndpoint,
  1015. // Handler: provisionEKSHandler,
  1016. // Router: r,
  1017. // })
  1018. // // POST /api/projects/{project_id}/provision/docr -> provision.NewProvisionDOCRHandler
  1019. // provisionDOCREndpoint := factory.NewAPIEndpoint(
  1020. // &types.APIRequestMetadata{
  1021. // Verb: types.APIVerbCreate,
  1022. // Method: types.HTTPVerbPost,
  1023. // Path: &types.Path{
  1024. // Parent: basePath,
  1025. // RelativePath: relPath + "/provision/docr",
  1026. // },
  1027. // Scopes: []types.PermissionScope{
  1028. // types.UserScope,
  1029. // types.ProjectScope,
  1030. // },
  1031. // },
  1032. // )
  1033. // provisionDOCRHandler := provision.NewProvisionDOCRHandler(
  1034. // config,
  1035. // factory.GetDecoderValidator(),
  1036. // factory.GetResultWriter(),
  1037. // )
  1038. // routes = append(routes, &router.Route{
  1039. // Endpoint: provisionDOCREndpoint,
  1040. // Handler: provisionDOCRHandler,
  1041. // Router: r,
  1042. // })
  1043. // // POST /api/projects/{project_id}/provision/doks -> provision.NewProvisionDOKSHandler
  1044. // provisionDOKSEndpoint := factory.NewAPIEndpoint(
  1045. // &types.APIRequestMetadata{
  1046. // Verb: types.APIVerbCreate,
  1047. // Method: types.HTTPVerbPost,
  1048. // Path: &types.Path{
  1049. // Parent: basePath,
  1050. // RelativePath: relPath + "/provision/doks",
  1051. // },
  1052. // Scopes: []types.PermissionScope{
  1053. // types.UserScope,
  1054. // types.ProjectScope,
  1055. // },
  1056. // CheckUsage: true,
  1057. // UsageMetric: types.Clusters,
  1058. // },
  1059. // )
  1060. // provisionDOKSHandler := provision.NewProvisionDOKSHandler(
  1061. // config,
  1062. // factory.GetDecoderValidator(),
  1063. // factory.GetResultWriter(),
  1064. // )
  1065. // routes = append(routes, &router.Route{
  1066. // Endpoint: provisionDOKSEndpoint,
  1067. // Handler: provisionDOKSHandler,
  1068. // Router: r,
  1069. // })
  1070. // // POST /api/projects/{project_id}/provision/gcr -> provision.NewProvisionGCRHandler
  1071. // provisionGCREndpoint := factory.NewAPIEndpoint(
  1072. // &types.APIRequestMetadata{
  1073. // Verb: types.APIVerbCreate,
  1074. // Method: types.HTTPVerbPost,
  1075. // Path: &types.Path{
  1076. // Parent: basePath,
  1077. // RelativePath: relPath + "/provision/gcr",
  1078. // },
  1079. // Scopes: []types.PermissionScope{
  1080. // types.UserScope,
  1081. // types.ProjectScope,
  1082. // },
  1083. // },
  1084. // )
  1085. // provisionGCRHandler := provision.NewProvisionGCRHandler(
  1086. // config,
  1087. // factory.GetDecoderValidator(),
  1088. // factory.GetResultWriter(),
  1089. // )
  1090. // routes = append(routes, &router.Route{
  1091. // Endpoint: provisionGCREndpoint,
  1092. // Handler: provisionGCRHandler,
  1093. // Router: r,
  1094. // })
  1095. // // POST /api/projects/{project_id}/provision/gke -> provision.NewProvisionGKEHandler
  1096. // provisionGKEEndpoint := factory.NewAPIEndpoint(
  1097. // &types.APIRequestMetadata{
  1098. // Verb: types.APIVerbCreate,
  1099. // Method: types.HTTPVerbPost,
  1100. // Path: &types.Path{
  1101. // Parent: basePath,
  1102. // RelativePath: relPath + "/provision/gke",
  1103. // },
  1104. // Scopes: []types.PermissionScope{
  1105. // types.UserScope,
  1106. // types.ProjectScope,
  1107. // },
  1108. // CheckUsage: true,
  1109. // UsageMetric: types.Clusters,
  1110. // },
  1111. // )
  1112. // provisionGKEHandler := provision.NewProvisionGKEHandler(
  1113. // config,
  1114. // factory.GetDecoderValidator(),
  1115. // factory.GetResultWriter(),
  1116. // )
  1117. // routes = append(routes, &router.Route{
  1118. // Endpoint: provisionGKEEndpoint,
  1119. // Handler: provisionGKEHandler,
  1120. // Router: r,
  1121. // })
  1122. // POST /api/projects/{project_id}/connect -> project.NewProjectConnectHandler
  1123. connectEndpoint := factory.NewAPIEndpoint(
  1124. &types.APIRequestMetadata{
  1125. Verb: types.APIVerbCreate,
  1126. Method: types.HTTPVerbPost,
  1127. Path: &types.Path{
  1128. Parent: basePath,
  1129. RelativePath: relPath + "/connect",
  1130. },
  1131. Scopes: []types.PermissionScope{
  1132. types.UserScope,
  1133. types.ProjectScope,
  1134. types.SettingsScope,
  1135. },
  1136. },
  1137. )
  1138. connectHandler := project.NewConnectHandler(
  1139. config,
  1140. factory.GetDecoderValidator(),
  1141. factory.GetResultWriter(),
  1142. )
  1143. routes = append(routes, &router.Route{
  1144. Endpoint: connectEndpoint,
  1145. Handler: connectHandler,
  1146. Router: r,
  1147. })
  1148. // POST /api/projects/{project_id}/policy -> policy.NewPolicyCreateHandler
  1149. policyCreateEndpoint := factory.NewAPIEndpoint(
  1150. &types.APIRequestMetadata{
  1151. Verb: types.APIVerbCreate,
  1152. Method: types.HTTPVerbPost,
  1153. Path: &types.Path{
  1154. Parent: basePath,
  1155. RelativePath: relPath + "/policy",
  1156. },
  1157. Scopes: []types.PermissionScope{
  1158. types.UserScope,
  1159. types.ProjectScope,
  1160. types.SettingsScope,
  1161. },
  1162. },
  1163. )
  1164. policyCreateHandler := policy.NewPolicyCreateHandler(
  1165. config,
  1166. factory.GetDecoderValidator(),
  1167. factory.GetResultWriter(),
  1168. )
  1169. routes = append(routes, &router.Route{
  1170. Endpoint: policyCreateEndpoint,
  1171. Handler: policyCreateHandler,
  1172. Router: r,
  1173. })
  1174. // GET /api/projects/{project_id}/policies -> policy.NewPolicyListHandler
  1175. policyListEndpoint := factory.NewAPIEndpoint(
  1176. &types.APIRequestMetadata{
  1177. Verb: types.APIVerbList,
  1178. Method: types.HTTPVerbGet,
  1179. Path: &types.Path{
  1180. Parent: basePath,
  1181. RelativePath: relPath + "/policies",
  1182. },
  1183. Scopes: []types.PermissionScope{
  1184. types.UserScope,
  1185. types.ProjectScope,
  1186. types.SettingsScope,
  1187. },
  1188. },
  1189. )
  1190. policyListHandler := policy.NewPolicyListHandler(
  1191. config,
  1192. factory.GetDecoderValidator(),
  1193. factory.GetResultWriter(),
  1194. )
  1195. routes = append(routes, &router.Route{
  1196. Endpoint: policyListEndpoint,
  1197. Handler: policyListHandler,
  1198. Router: r,
  1199. })
  1200. // GET /api/projects/{project_id}/policy/{policy_id} -> policy.NewPolicyGetHandler
  1201. policyGetEndpoint := factory.NewAPIEndpoint(
  1202. &types.APIRequestMetadata{
  1203. Verb: types.APIVerbGet,
  1204. Method: types.HTTPVerbGet,
  1205. Path: &types.Path{
  1206. Parent: basePath,
  1207. RelativePath: fmt.Sprintf("%s/policy/{%s}", relPath, types.URLParamPolicyID),
  1208. },
  1209. Scopes: []types.PermissionScope{
  1210. types.UserScope,
  1211. types.ProjectScope,
  1212. types.SettingsScope,
  1213. },
  1214. },
  1215. )
  1216. policyGetHandler := policy.NewPolicyGetHandler(
  1217. config,
  1218. factory.GetDecoderValidator(),
  1219. factory.GetResultWriter(),
  1220. )
  1221. routes = append(routes, &router.Route{
  1222. Endpoint: policyGetEndpoint,
  1223. Handler: policyGetHandler,
  1224. Router: r,
  1225. })
  1226. // POST /api/projects/{project_id}/api_token -> api_token.NewAPITokenCreateHandler
  1227. apiTokenCreateEndpoint := factory.NewAPIEndpoint(
  1228. &types.APIRequestMetadata{
  1229. Verb: types.APIVerbCreate,
  1230. Method: types.HTTPVerbPost,
  1231. Path: &types.Path{
  1232. Parent: basePath,
  1233. RelativePath: relPath + "/api_token",
  1234. },
  1235. Scopes: []types.PermissionScope{
  1236. types.UserScope,
  1237. types.ProjectScope,
  1238. types.SettingsScope,
  1239. },
  1240. },
  1241. )
  1242. apiTokenCreateHandler := api_token.NewAPITokenCreateHandler(
  1243. config,
  1244. factory.GetDecoderValidator(),
  1245. factory.GetResultWriter(),
  1246. )
  1247. routes = append(routes, &router.Route{
  1248. Endpoint: apiTokenCreateEndpoint,
  1249. Handler: apiTokenCreateHandler,
  1250. Router: r,
  1251. })
  1252. // GET /api/projects/{project_id}/api_token -> api_token.NewAPITokenListHandler
  1253. apiTokenListEndpoint := factory.NewAPIEndpoint(
  1254. &types.APIRequestMetadata{
  1255. Verb: types.APIVerbList,
  1256. Method: types.HTTPVerbGet,
  1257. Path: &types.Path{
  1258. Parent: basePath,
  1259. RelativePath: fmt.Sprintf("%s/api_token", relPath),
  1260. },
  1261. Scopes: []types.PermissionScope{
  1262. types.UserScope,
  1263. types.ProjectScope,
  1264. types.SettingsScope,
  1265. },
  1266. },
  1267. )
  1268. apiTokenListHandler := api_token.NewAPITokenListHandler(
  1269. config,
  1270. factory.GetDecoderValidator(),
  1271. factory.GetResultWriter(),
  1272. )
  1273. routes = append(routes, &router.Route{
  1274. Endpoint: apiTokenListEndpoint,
  1275. Handler: apiTokenListHandler,
  1276. Router: r,
  1277. })
  1278. // GET /api/projects/{project_id}/api_token/{api_token_id} -> api_token.NewAPITokenGetHandler
  1279. apiTokenGetEndpoint := factory.NewAPIEndpoint(
  1280. &types.APIRequestMetadata{
  1281. Verb: types.APIVerbGet,
  1282. Method: types.HTTPVerbGet,
  1283. Path: &types.Path{
  1284. Parent: basePath,
  1285. RelativePath: fmt.Sprintf("%s/api_token/{%s}", relPath, types.URLParamTokenID),
  1286. },
  1287. Scopes: []types.PermissionScope{
  1288. types.UserScope,
  1289. types.ProjectScope,
  1290. types.SettingsScope,
  1291. },
  1292. },
  1293. )
  1294. apiTokenGetHandler := api_token.NewAPITokenGetHandler(
  1295. config,
  1296. factory.GetDecoderValidator(),
  1297. factory.GetResultWriter(),
  1298. )
  1299. routes = append(routes, &router.Route{
  1300. Endpoint: apiTokenGetEndpoint,
  1301. Handler: apiTokenGetHandler,
  1302. Router: r,
  1303. })
  1304. // POST /api/projects/{project_id}/api_token/{api_token_id}/revoke -> api_token.NewAPITokenRevokeHandler
  1305. apiTokenRevokeEndpoint := factory.NewAPIEndpoint(
  1306. &types.APIRequestMetadata{
  1307. Verb: types.APIVerbUpdate,
  1308. Method: types.HTTPVerbPost,
  1309. Path: &types.Path{
  1310. Parent: basePath,
  1311. RelativePath: fmt.Sprintf("%s/api_token/{%s}/revoke", relPath, types.URLParamTokenID),
  1312. },
  1313. Scopes: []types.PermissionScope{
  1314. types.UserScope,
  1315. types.ProjectScope,
  1316. types.SettingsScope,
  1317. },
  1318. },
  1319. )
  1320. apiTokenRevokeHandler := api_token.NewAPITokenRevokeHandler(
  1321. config,
  1322. factory.GetDecoderValidator(),
  1323. factory.GetResultWriter(),
  1324. )
  1325. routes = append(routes, &router.Route{
  1326. Endpoint: apiTokenRevokeEndpoint,
  1327. Handler: apiTokenRevokeHandler,
  1328. Router: r,
  1329. })
  1330. // POST /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoCreateHandler
  1331. hrCreateEndpoint := factory.NewAPIEndpoint(
  1332. &types.APIRequestMetadata{
  1333. Verb: types.APIVerbCreate,
  1334. Method: types.HTTPVerbPost,
  1335. Path: &types.Path{
  1336. Parent: basePath,
  1337. RelativePath: relPath + "/helmrepos",
  1338. },
  1339. Scopes: []types.PermissionScope{
  1340. types.UserScope,
  1341. types.ProjectScope,
  1342. },
  1343. },
  1344. )
  1345. hrCreateHandler := helmrepo.NewHelmRepoCreateHandler(
  1346. config,
  1347. factory.GetDecoderValidator(),
  1348. factory.GetResultWriter(),
  1349. )
  1350. routes = append(routes, &router.Route{
  1351. Endpoint: hrCreateEndpoint,
  1352. Handler: hrCreateHandler,
  1353. Router: r,
  1354. })
  1355. // GET /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoListHandler
  1356. hrListEndpoint := factory.NewAPIEndpoint(
  1357. &types.APIRequestMetadata{
  1358. Verb: types.APIVerbList,
  1359. Method: types.HTTPVerbGet,
  1360. Path: &types.Path{
  1361. Parent: basePath,
  1362. RelativePath: relPath + "/helmrepos",
  1363. },
  1364. Scopes: []types.PermissionScope{
  1365. types.UserScope,
  1366. types.ProjectScope,
  1367. },
  1368. },
  1369. )
  1370. hrListHandler := helmrepo.NewHelmRepoListHandler(
  1371. config,
  1372. factory.GetResultWriter(),
  1373. )
  1374. routes = append(routes, &router.Route{
  1375. Endpoint: hrListEndpoint,
  1376. Handler: hrListHandler,
  1377. Router: r,
  1378. })
  1379. // GET /api/projects/{project_id}/tags -> project.NewGetTagsHandler
  1380. getTagsEndpoint := factory.NewAPIEndpoint(
  1381. &types.APIRequestMetadata{
  1382. Verb: types.APIVerbGet,
  1383. Method: types.HTTPVerbGet,
  1384. Path: &types.Path{
  1385. Parent: basePath,
  1386. RelativePath: relPath + "/tags",
  1387. },
  1388. Scopes: []types.PermissionScope{
  1389. types.UserScope,
  1390. types.ProjectScope,
  1391. },
  1392. },
  1393. )
  1394. getTagsHandler := project.NewGetTagsHandler(
  1395. config,
  1396. factory.GetResultWriter(),
  1397. )
  1398. routes = append(routes, &router.Route{
  1399. Endpoint: getTagsEndpoint,
  1400. Handler: getTagsHandler,
  1401. Router: r,
  1402. })
  1403. // POST /api/projects/{project_id}/tags -> project.NewCreateTagHandler
  1404. createTagEndpoint := factory.NewAPIEndpoint(
  1405. &types.APIRequestMetadata{
  1406. Verb: types.APIVerbCreate,
  1407. Method: types.HTTPVerbPost,
  1408. Path: &types.Path{
  1409. Parent: basePath,
  1410. RelativePath: relPath + "/tags",
  1411. },
  1412. Scopes: []types.PermissionScope{
  1413. types.UserScope,
  1414. types.ProjectScope,
  1415. },
  1416. },
  1417. )
  1418. createTagHandler := project.NewCreateTagHandler(
  1419. config,
  1420. factory.GetDecoderValidator(),
  1421. factory.GetResultWriter(),
  1422. )
  1423. routes = append(routes, &router.Route{
  1424. Endpoint: createTagEndpoint,
  1425. Handler: createTagHandler,
  1426. Router: r,
  1427. })
  1428. // POST /api/projects/{project_id}/contract -> apiContract.NewAPIContractUpdateHandler
  1429. updateAPIContractEndpoint := factory.NewAPIEndpoint(
  1430. &types.APIRequestMetadata{
  1431. Verb: types.APIVerbCreate,
  1432. Method: types.HTTPVerbPost,
  1433. Path: &types.Path{
  1434. Parent: basePath,
  1435. RelativePath: relPath + "/contract",
  1436. },
  1437. Scopes: []types.PermissionScope{
  1438. types.UserScope,
  1439. types.ProjectScope,
  1440. },
  1441. },
  1442. )
  1443. updateAPIContractHandler := apiContract.NewAPIContractUpdateHandler(
  1444. config,
  1445. factory.GetDecoderValidator(),
  1446. factory.GetResultWriter(),
  1447. )
  1448. routes = append(routes, &router.Route{
  1449. Endpoint: updateAPIContractEndpoint,
  1450. Handler: updateAPIContractHandler,
  1451. Router: r,
  1452. })
  1453. // GET /api/projects/{project_id}/contracts -> apiContract.NewAPIContractRevisionListHandler
  1454. listAPIContractRevisionsEndpoint := factory.NewAPIEndpoint(
  1455. &types.APIRequestMetadata{
  1456. Verb: types.APIVerbGet,
  1457. Method: types.HTTPVerbGet,
  1458. Path: &types.Path{
  1459. Parent: basePath,
  1460. RelativePath: relPath + "/contracts",
  1461. },
  1462. Scopes: []types.PermissionScope{
  1463. types.UserScope,
  1464. types.ProjectScope,
  1465. },
  1466. },
  1467. )
  1468. listAPIContractRevisionHandler := apiContract.NewAPIContractRevisionListHandler(
  1469. config,
  1470. factory.GetDecoderValidator(),
  1471. factory.GetResultWriter(),
  1472. )
  1473. routes = append(routes, &router.Route{
  1474. Endpoint: listAPIContractRevisionsEndpoint,
  1475. Handler: listAPIContractRevisionHandler,
  1476. Router: r,
  1477. })
  1478. // DELETE /api/projects/{project_id}/contracts/{revision_id} -> apiContract.NewAPIContractUpdateHandler
  1479. deleteAPIContractRevisionsEndpoint := factory.NewAPIEndpoint(
  1480. &types.APIRequestMetadata{
  1481. Verb: types.APIVerbDelete,
  1482. Method: types.HTTPVerbDelete,
  1483. Path: &types.Path{
  1484. Parent: basePath,
  1485. RelativePath: fmt.Sprintf("%s/contracts/{%s}", relPath, types.URLParamAPIContractRevisionID),
  1486. },
  1487. Scopes: []types.PermissionScope{
  1488. types.UserScope,
  1489. types.ProjectScope,
  1490. types.APIContractRevisionScope,
  1491. },
  1492. },
  1493. )
  1494. deleteAPIContractRevisionHandler := apiContract.NewAPIContractRevisionDeleteHandler(
  1495. config,
  1496. factory.GetDecoderValidator(),
  1497. factory.GetResultWriter(),
  1498. )
  1499. routes = append(routes, &router.Route{
  1500. Endpoint: deleteAPIContractRevisionsEndpoint,
  1501. Handler: deleteAPIContractRevisionHandler,
  1502. Router: r,
  1503. })
  1504. // POST /api/projects/{project_id}/contract/preflight -> apiContract.NewPreflightCheckHandler
  1505. preflightCheckEndpoint := factory.NewAPIEndpoint(
  1506. &types.APIRequestMetadata{
  1507. Verb: types.APIVerbCreate,
  1508. Method: types.HTTPVerbPost,
  1509. Path: &types.Path{
  1510. Parent: basePath,
  1511. RelativePath: fmt.Sprintf("%s/contract/preflight", relPath),
  1512. },
  1513. Scopes: []types.PermissionScope{
  1514. types.UserScope,
  1515. types.ProjectScope,
  1516. },
  1517. },
  1518. )
  1519. preflightCheckHandler := apiContract.NewPreflightCheckHandler(
  1520. config,
  1521. factory.GetDecoderValidator(),
  1522. factory.GetResultWriter(),
  1523. )
  1524. routes = append(routes, &router.Route{
  1525. Endpoint: preflightCheckEndpoint,
  1526. Handler: preflightCheckHandler,
  1527. Router: r,
  1528. })
  1529. // POST /api/projects/{project_id}/rename -> cluster.newRenamProject
  1530. renameProjectEndpoint := factory.NewAPIEndpoint(
  1531. &types.APIRequestMetadata{
  1532. Verb: types.APIVerbCreate,
  1533. Method: types.HTTPVerbPost,
  1534. Path: &types.Path{
  1535. Parent: basePath,
  1536. RelativePath: relPath + "/rename",
  1537. },
  1538. Scopes: []types.PermissionScope{
  1539. types.UserScope,
  1540. types.ProjectScope,
  1541. },
  1542. },
  1543. )
  1544. renameProjectHandler := project.NewRenameProjectHandler(
  1545. config,
  1546. factory.GetDecoderValidator(),
  1547. factory.GetResultWriter(),
  1548. )
  1549. routes = append(routes, &router.Route{
  1550. Endpoint: renameProjectEndpoint,
  1551. Handler: renameProjectHandler,
  1552. Router: r,
  1553. })
  1554. // GET /api/projects/{project_id}/images -> project.ImagesHandler
  1555. imagesEndpoint := factory.NewAPIEndpoint(
  1556. &types.APIRequestMetadata{
  1557. Verb: types.APIVerbList,
  1558. Method: types.HTTPVerbGet,
  1559. Path: &types.Path{
  1560. Parent: basePath,
  1561. RelativePath: relPath + "/images",
  1562. },
  1563. Scopes: []types.PermissionScope{
  1564. types.UserScope,
  1565. types.ProjectScope,
  1566. },
  1567. },
  1568. )
  1569. imagesHandler := project.NewImagesHandler(
  1570. config,
  1571. factory.GetResultWriter(),
  1572. )
  1573. routes = append(routes, &router.Route{
  1574. Endpoint: imagesEndpoint,
  1575. Handler: imagesHandler,
  1576. Router: r,
  1577. })
  1578. // GET /api/projects/{project_id}/targets -> deployment_target.ListDeploymentTargetHandler
  1579. listDeploymentTargetEndpoint := factory.NewAPIEndpoint(
  1580. &types.APIRequestMetadata{
  1581. Verb: types.APIVerbGet,
  1582. Method: types.HTTPVerbGet,
  1583. Path: &types.Path{
  1584. Parent: basePath,
  1585. RelativePath: fmt.Sprintf("%s/targets", relPath),
  1586. },
  1587. Scopes: []types.PermissionScope{
  1588. types.UserScope,
  1589. types.ProjectScope,
  1590. },
  1591. },
  1592. )
  1593. listDeploymentTargetHandler := deployment_target.NewListDeploymentTargetsHandler(
  1594. config,
  1595. factory.GetDecoderValidator(),
  1596. factory.GetResultWriter(),
  1597. )
  1598. routes = append(routes, &router.Route{
  1599. Endpoint: listDeploymentTargetEndpoint,
  1600. Handler: listDeploymentTargetHandler,
  1601. Router: r,
  1602. })
  1603. // GET /api/projects/{project_id}/targets -> deployment_target.ListDeploymentTargetHandler
  1604. createDeploymentTargetEndpoint := factory.NewAPIEndpoint(
  1605. &types.APIRequestMetadata{
  1606. Verb: types.APIVerbCreate,
  1607. Method: types.HTTPVerbPost,
  1608. Path: &types.Path{
  1609. Parent: basePath,
  1610. RelativePath: fmt.Sprintf("%s/targets", relPath),
  1611. },
  1612. Scopes: []types.PermissionScope{
  1613. types.UserScope,
  1614. types.ProjectScope,
  1615. },
  1616. },
  1617. )
  1618. createDeploymentTargetHandler := deployment_target.NewCreateDeploymentTargetHandler(
  1619. config,
  1620. factory.GetDecoderValidator(),
  1621. factory.GetResultWriter(),
  1622. )
  1623. routes = append(routes, &router.Route{
  1624. Endpoint: createDeploymentTargetEndpoint,
  1625. Handler: createDeploymentTargetHandler,
  1626. Router: r,
  1627. })
  1628. return routes, newPath
  1629. }