project.go 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912
  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. // GET /api/projects/{project_id}/billing/plan -> project.NewListPlansHandler
  303. listPlanEndpoint := factory.NewAPIEndpoint(
  304. &types.APIRequestMetadata{
  305. Verb: types.APIVerbGet,
  306. Method: types.HTTPVerbGet,
  307. Path: &types.Path{
  308. Parent: basePath,
  309. RelativePath: relPath + "/billing/plan",
  310. },
  311. Scopes: []types.PermissionScope{
  312. types.UserScope,
  313. types.ProjectScope,
  314. },
  315. },
  316. )
  317. listPlanHandler := billing.NewListPlansHandler(
  318. config,
  319. factory.GetResultWriter(),
  320. )
  321. routes = append(routes, &router.Route{
  322. Endpoint: listPlanEndpoint,
  323. Handler: listPlanHandler,
  324. Router: r,
  325. })
  326. // GET /api/projects/{project_id}/billing/credits -> project.NewGetCreditsHandler
  327. listCreditsEndpoint := factory.NewAPIEndpoint(
  328. &types.APIRequestMetadata{
  329. Verb: types.APIVerbGet,
  330. Method: types.HTTPVerbGet,
  331. Path: &types.Path{
  332. Parent: basePath,
  333. RelativePath: relPath + "/billing/credits",
  334. },
  335. Scopes: []types.PermissionScope{
  336. types.UserScope,
  337. types.ProjectScope,
  338. },
  339. },
  340. )
  341. listCreditsHandler := billing.NewListCreditsHandler(
  342. config,
  343. factory.GetResultWriter(),
  344. )
  345. routes = append(routes, &router.Route{
  346. Endpoint: listCreditsEndpoint,
  347. Handler: listCreditsHandler,
  348. Router: r,
  349. })
  350. // POST /api/projects/{project_id}/billing/dashboard -> project.NewGetUsageDashboardHandler
  351. getUsageDashboardEndpoint := factory.NewAPIEndpoint(
  352. &types.APIRequestMetadata{
  353. Verb: types.APIVerbCreate,
  354. Method: types.HTTPVerbPost,
  355. Path: &types.Path{
  356. Parent: basePath,
  357. RelativePath: relPath + "/billing/dashboard",
  358. },
  359. Scopes: []types.PermissionScope{
  360. types.UserScope,
  361. types.ProjectScope,
  362. },
  363. },
  364. )
  365. getUsageDashboardHandler := billing.NewGetUsageDashboardHandler(
  366. config,
  367. factory.GetDecoderValidator(),
  368. factory.GetResultWriter(),
  369. )
  370. routes = append(routes, &router.Route{
  371. Endpoint: getUsageDashboardEndpoint,
  372. Handler: getUsageDashboardHandler,
  373. Router: r,
  374. })
  375. // POST /api/projects/{project_id}/billing/ingest -> project.NewGetUsageDashboardHandler
  376. ingestEventsEndpoint := factory.NewAPIEndpoint(
  377. &types.APIRequestMetadata{
  378. Verb: types.APIVerbCreate,
  379. Method: types.HTTPVerbPost,
  380. Path: &types.Path{
  381. Parent: basePath,
  382. RelativePath: relPath + "/billing/ingest",
  383. },
  384. Scopes: []types.PermissionScope{
  385. types.UserScope,
  386. types.ProjectScope,
  387. },
  388. },
  389. )
  390. ingestEventsHandler := billing.NewIngestEventsHandler(
  391. config,
  392. factory.GetDecoderValidator(),
  393. factory.GetResultWriter(),
  394. )
  395. routes = append(routes, &router.Route{
  396. Endpoint: ingestEventsEndpoint,
  397. Handler: ingestEventsHandler,
  398. Router: r,
  399. })
  400. // POST /api/projects/{project_id}/billing/payment_method -> project.NewCreateBillingHandler
  401. createBillingEndpoint := factory.NewAPIEndpoint(
  402. &types.APIRequestMetadata{
  403. Verb: types.APIVerbCreate,
  404. Method: types.HTTPVerbPost,
  405. Path: &types.Path{
  406. Parent: basePath,
  407. RelativePath: relPath + "/billing/payment_method",
  408. },
  409. Scopes: []types.PermissionScope{
  410. types.UserScope,
  411. types.ProjectScope,
  412. },
  413. },
  414. )
  415. createBillingHandler := billing.NewCreateBillingHandler(
  416. config,
  417. factory.GetDecoderValidator(),
  418. factory.GetResultWriter(),
  419. )
  420. routes = append(routes, &router.Route{
  421. Endpoint: createBillingEndpoint,
  422. Handler: createBillingHandler,
  423. Router: r,
  424. })
  425. // PUT /api/projects/{project_id}/billing/payment_method/{payment_method_id}/default -> project.NewSetDefaultBillingHandler
  426. setDefaultBillingEndpoint := factory.NewAPIEndpoint(
  427. &types.APIRequestMetadata{
  428. Verb: types.APIVerbUpdate,
  429. Method: types.HTTPVerbPut,
  430. Path: &types.Path{
  431. Parent: basePath,
  432. RelativePath: fmt.Sprintf("%s/billing/payment_method/{%s}/default", relPath, types.URLParamPaymentMethodID),
  433. },
  434. Scopes: []types.PermissionScope{
  435. types.UserScope,
  436. types.ProjectScope,
  437. },
  438. },
  439. )
  440. setDefaultBillingHandler := billing.NewSetDefaultBillingHandler(
  441. config,
  442. factory.GetResultWriter(),
  443. )
  444. routes = append(routes, &router.Route{
  445. Endpoint: setDefaultBillingEndpoint,
  446. Handler: setDefaultBillingHandler,
  447. Router: r,
  448. })
  449. // DELETE /api/projects/{project_id}/billing/payment_method/{payment_method_id} -> project.NewDeleteBillingHandler
  450. deleteBillingEndpoint := factory.NewAPIEndpoint(
  451. &types.APIRequestMetadata{
  452. Verb: types.APIVerbDelete,
  453. Method: types.HTTPVerbDelete,
  454. Path: &types.Path{
  455. Parent: basePath,
  456. RelativePath: fmt.Sprintf("%s/billing/payment_method/{%s}", relPath, types.URLParamPaymentMethodID),
  457. },
  458. Scopes: []types.PermissionScope{
  459. types.UserScope,
  460. types.ProjectScope,
  461. },
  462. },
  463. )
  464. deleteBillingHandler := billing.NewDeleteBillingHandler(
  465. config,
  466. factory.GetResultWriter(),
  467. )
  468. routes = append(routes, &router.Route{
  469. Endpoint: deleteBillingEndpoint,
  470. Handler: deleteBillingHandler,
  471. Router: r,
  472. })
  473. // GET /api/projects/{project_id}/billing/publishable_key -> project.NewGetPublishableKeyHandler
  474. publishableKeyEndpoint := factory.NewAPIEndpoint(
  475. &types.APIRequestMetadata{
  476. Verb: types.APIVerbGet,
  477. Method: types.HTTPVerbGet,
  478. Path: &types.Path{
  479. Parent: basePath,
  480. RelativePath: relPath + "/billing/publishable_key",
  481. },
  482. Scopes: []types.PermissionScope{
  483. types.UserScope,
  484. types.ProjectScope,
  485. },
  486. },
  487. )
  488. publishableKeyHandler := billing.NewGetPublishableKeyHandler(
  489. config,
  490. factory.GetDecoderValidator(),
  491. factory.GetResultWriter(),
  492. )
  493. routes = append(routes, &router.Route{
  494. Endpoint: publishableKeyEndpoint,
  495. Handler: publishableKeyHandler,
  496. Router: r,
  497. })
  498. // GET /api/projects/{project_id}/clusters -> cluster.NewClusterListHandler
  499. listClusterEndpoint := factory.NewAPIEndpoint(
  500. &types.APIRequestMetadata{
  501. Verb: types.APIVerbList,
  502. Method: types.HTTPVerbGet,
  503. Path: &types.Path{
  504. Parent: basePath,
  505. RelativePath: relPath + "/clusters",
  506. },
  507. Scopes: []types.PermissionScope{
  508. types.UserScope,
  509. types.ProjectScope,
  510. },
  511. },
  512. )
  513. listClusterHandler := cluster.NewClusterListHandler(
  514. config,
  515. factory.GetResultWriter(),
  516. )
  517. routes = append(routes, &router.Route{
  518. Endpoint: listClusterEndpoint,
  519. Handler: listClusterHandler,
  520. Router: r,
  521. })
  522. // GET /api/projects/{project_id}/gitrepos -> gitinstallation.NewGitRepoListHandler
  523. listGitReposEndpoint := factory.NewAPIEndpoint(
  524. &types.APIRequestMetadata{
  525. Verb: types.APIVerbList,
  526. Method: types.HTTPVerbGet,
  527. Path: &types.Path{
  528. Parent: basePath,
  529. RelativePath: relPath + "/gitrepos",
  530. },
  531. Scopes: []types.PermissionScope{
  532. types.UserScope,
  533. types.ProjectScope,
  534. },
  535. },
  536. )
  537. listGitReposHandler := gitinstallation.NewGitRepoListHandler(
  538. config,
  539. factory.GetResultWriter(),
  540. )
  541. routes = append(routes, &router.Route{
  542. Endpoint: listGitReposEndpoint,
  543. Handler: listGitReposHandler,
  544. Router: r,
  545. })
  546. // GET /api/projects/{project_id}/collaborators -> project.NewCollaboratorsListHandler
  547. listCollaboratorsEndpoint := factory.NewAPIEndpoint(
  548. &types.APIRequestMetadata{
  549. Verb: types.APIVerbList,
  550. Method: types.HTTPVerbGet,
  551. Path: &types.Path{
  552. Parent: basePath,
  553. RelativePath: relPath + "/collaborators",
  554. },
  555. Scopes: []types.PermissionScope{
  556. types.UserScope,
  557. types.ProjectScope,
  558. },
  559. },
  560. )
  561. listCollaboratorsHandler := project.NewCollaboratorsListHandler(
  562. config,
  563. factory.GetResultWriter(),
  564. )
  565. routes = append(routes, &router.Route{
  566. Endpoint: listCollaboratorsEndpoint,
  567. Handler: listCollaboratorsHandler,
  568. Router: r,
  569. })
  570. // GET /api/projects/{project_id}/roles -> project.NewRolesListHandler
  571. listRolesEndpoint := factory.NewAPIEndpoint(
  572. &types.APIRequestMetadata{
  573. Verb: types.APIVerbList,
  574. Method: types.HTTPVerbGet,
  575. Path: &types.Path{
  576. Parent: basePath,
  577. RelativePath: relPath + "/roles",
  578. },
  579. Scopes: []types.PermissionScope{
  580. types.UserScope,
  581. types.ProjectScope,
  582. },
  583. },
  584. )
  585. listRolesHandler := project.NewRolesListHandler(
  586. config,
  587. factory.GetResultWriter(),
  588. )
  589. routes = append(routes, &router.Route{
  590. Endpoint: listRolesEndpoint,
  591. Handler: listRolesHandler,
  592. Router: r,
  593. })
  594. // GET /api/projects/{project_id}/datastores -> datastore.NewListAllDatastoresForProjectHandler
  595. listDatastoresEndpoint := factory.NewAPIEndpoint(
  596. &types.APIRequestMetadata{
  597. Verb: types.APIVerbList,
  598. Method: types.HTTPVerbGet,
  599. Path: &types.Path{
  600. Parent: basePath,
  601. RelativePath: relPath + "/datastores",
  602. },
  603. Scopes: []types.PermissionScope{
  604. types.UserScope,
  605. types.ProjectScope,
  606. },
  607. },
  608. )
  609. listDatastoresHandler := datastore.NewListDatastoresHandler(
  610. config,
  611. factory.GetDecoderValidator(),
  612. factory.GetResultWriter(),
  613. )
  614. routes = append(routes, &router.Route{
  615. Endpoint: listDatastoresEndpoint,
  616. Handler: listDatastoresHandler,
  617. Router: r,
  618. })
  619. // GET /api/projects/{project_id}/datastores -> datastore.NewGetDatastoreHandler
  620. getDatastoreEndpoint := factory.NewAPIEndpoint(
  621. &types.APIRequestMetadata{
  622. Verb: types.APIVerbList,
  623. Method: types.HTTPVerbGet,
  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. getDatastoreHandler := datastore.NewGetDatastoreHandler(
  635. config,
  636. factory.GetDecoderValidator(),
  637. factory.GetResultWriter(),
  638. )
  639. routes = append(routes, &router.Route{
  640. Endpoint: getDatastoreEndpoint,
  641. Handler: getDatastoreHandler,
  642. Router: r,
  643. })
  644. // GET /api/projects/{project_id}/datastores -> datastore.NewGetDatastoreCredentialHandler
  645. getDatastoreCredentialEndpoint := factory.NewAPIEndpoint(
  646. &types.APIRequestMetadata{
  647. Verb: types.APIVerbList,
  648. Method: types.HTTPVerbGet,
  649. Path: &types.Path{
  650. Parent: basePath,
  651. RelativePath: fmt.Sprintf("%s/datastores/{%s}/credential", relPath, types.URLParamDatastoreName),
  652. },
  653. Scopes: []types.PermissionScope{
  654. types.UserScope,
  655. types.ProjectScope,
  656. },
  657. },
  658. )
  659. getDatastoreCredentialHandler := datastore.NewGetDatastoreCredentialHandler(
  660. config,
  661. factory.GetDecoderValidator(),
  662. factory.GetResultWriter(),
  663. )
  664. routes = append(routes, &router.Route{
  665. Endpoint: getDatastoreCredentialEndpoint,
  666. Handler: getDatastoreCredentialHandler,
  667. Router: r,
  668. })
  669. // POST /api/projects/{project_id}/datastores/{datastore_name}/create-proxy -> cluster.NewCreateDatastoreProxyHandler
  670. createDatastoreProxyEndpoint := factory.NewAPIEndpoint(
  671. &types.APIRequestMetadata{
  672. Verb: types.APIVerbUpdate,
  673. Method: types.HTTPVerbPost,
  674. Path: &types.Path{
  675. Parent: basePath,
  676. RelativePath: fmt.Sprintf("%s/datastores/{%s}/create-proxy", relPath, types.URLParamDatastoreName),
  677. },
  678. Scopes: []types.PermissionScope{
  679. types.UserScope,
  680. types.ProjectScope,
  681. },
  682. },
  683. )
  684. createDatastoreProxyHandler := datastore.NewCreateDatastoreProxyHandler(
  685. config,
  686. factory.GetDecoderValidator(),
  687. factory.GetResultWriter(),
  688. )
  689. routes = append(routes, &router.Route{
  690. Endpoint: createDatastoreProxyEndpoint,
  691. Handler: createDatastoreProxyHandler,
  692. Router: r,
  693. })
  694. // DELETE /api/projects/{project_id}/datastores/{datastore_name} -> cloud_provider.NewDeleteDatastoreHandler
  695. deleteDatastoreEndpoint := factory.NewAPIEndpoint(
  696. &types.APIRequestMetadata{
  697. Verb: types.APIVerbDelete,
  698. Method: types.HTTPVerbDelete,
  699. Path: &types.Path{
  700. Parent: basePath,
  701. RelativePath: fmt.Sprintf("%s/datastores/{%s}", relPath, types.URLParamDatastoreName),
  702. },
  703. Scopes: []types.PermissionScope{
  704. types.UserScope,
  705. types.ProjectScope,
  706. },
  707. },
  708. )
  709. deleteDatastoreHandler := datastore.NewDeleteDatastoreHandler(
  710. config,
  711. factory.GetDecoderValidator(),
  712. factory.GetResultWriter(),
  713. )
  714. routes = append(routes, &router.Route{
  715. Endpoint: deleteDatastoreEndpoint,
  716. Handler: deleteDatastoreHandler,
  717. Router: r,
  718. })
  719. // POST /api/projects/{project_id}/roles -> project.NewRoleUpdateHandler
  720. updateRoleEndpoint := factory.NewAPIEndpoint(
  721. &types.APIRequestMetadata{
  722. Verb: types.APIVerbUpdate,
  723. Method: types.HTTPVerbPost,
  724. Path: &types.Path{
  725. Parent: basePath,
  726. RelativePath: relPath + "/roles",
  727. },
  728. Scopes: []types.PermissionScope{
  729. types.UserScope,
  730. types.ProjectScope,
  731. },
  732. },
  733. )
  734. updateRoleHandler := project.NewRoleUpdateHandler(
  735. config,
  736. factory.GetDecoderValidator(),
  737. factory.GetResultWriter(),
  738. )
  739. routes = append(routes, &router.Route{
  740. Endpoint: updateRoleEndpoint,
  741. Handler: updateRoleHandler,
  742. Router: r,
  743. })
  744. // DELETE /api/projects/{project_id}/roles -> project.NewRoleDeleteHandler
  745. deleteRoleEndpoint := factory.NewAPIEndpoint(
  746. &types.APIRequestMetadata{
  747. Verb: types.APIVerbDelete,
  748. Method: types.HTTPVerbDelete,
  749. Path: &types.Path{
  750. Parent: basePath,
  751. RelativePath: relPath + "/roles",
  752. },
  753. Scopes: []types.PermissionScope{
  754. types.UserScope,
  755. types.ProjectScope,
  756. },
  757. },
  758. )
  759. deleteRoleHandler := project.NewRoleDeleteHandler(
  760. config,
  761. factory.GetDecoderValidator(),
  762. factory.GetResultWriter(),
  763. )
  764. routes = append(routes, &router.Route{
  765. Endpoint: deleteRoleEndpoint,
  766. Handler: deleteRoleHandler,
  767. Router: r,
  768. })
  769. // GET /api/projects/{project_id}/registries -> registry.NewRegistryListHandler
  770. listRegistriesEndpoint := factory.NewAPIEndpoint(
  771. &types.APIRequestMetadata{
  772. Verb: types.APIVerbList,
  773. Method: types.HTTPVerbGet,
  774. Path: &types.Path{
  775. Parent: basePath,
  776. RelativePath: relPath + "/registries",
  777. },
  778. Scopes: []types.PermissionScope{
  779. types.UserScope,
  780. types.ProjectScope,
  781. },
  782. },
  783. )
  784. listRegistriesHandler := registry.NewRegistryListHandler(
  785. config,
  786. factory.GetResultWriter(),
  787. )
  788. routes = append(routes, &router.Route{
  789. Endpoint: listRegistriesEndpoint,
  790. Handler: listRegistriesHandler,
  791. Router: r,
  792. })
  793. // POST /api/projects/{project_id}/registries -> registry.NewRegistryCreateHandler
  794. createRegistryEndpoint := factory.NewAPIEndpoint(
  795. &types.APIRequestMetadata{
  796. Verb: types.APIVerbCreate,
  797. Method: types.HTTPVerbPost,
  798. Path: &types.Path{
  799. Parent: basePath,
  800. RelativePath: relPath + "/registries",
  801. },
  802. Scopes: []types.PermissionScope{
  803. types.UserScope,
  804. types.ProjectScope,
  805. },
  806. },
  807. )
  808. createRegistryHandler := registry.NewRegistryCreateHandler(
  809. config,
  810. factory.GetDecoderValidator(),
  811. factory.GetResultWriter(),
  812. )
  813. routes = append(routes, &router.Route{
  814. Endpoint: createRegistryEndpoint,
  815. Handler: createRegistryHandler,
  816. Router: r,
  817. })
  818. // GET /api/projects/{project_id}/registries/ecr/token -> registry.NewRegistryGetECRTokenHandler
  819. getECRTokenEndpoint := factory.NewAPIEndpoint(
  820. &types.APIRequestMetadata{
  821. Verb: types.APIVerbGet,
  822. Method: types.HTTPVerbGet,
  823. Path: &types.Path{
  824. Parent: basePath,
  825. RelativePath: relPath + "/registries/ecr/token",
  826. },
  827. Scopes: []types.PermissionScope{
  828. types.UserScope,
  829. types.ProjectScope,
  830. },
  831. },
  832. )
  833. getECRTokenHandler := registry.NewRegistryGetECRTokenHandler(
  834. config,
  835. factory.GetDecoderValidator(),
  836. factory.GetResultWriter(),
  837. )
  838. routes = append(routes, &router.Route{
  839. Endpoint: getECRTokenEndpoint,
  840. Handler: getECRTokenHandler,
  841. Router: r,
  842. })
  843. // GET /api/projects/{project_id}/registries/docr/token -> registry.NewRegistryGetDOCRTokenHandler
  844. getDOCRTokenEndpoint := factory.NewAPIEndpoint(
  845. &types.APIRequestMetadata{
  846. Verb: types.APIVerbGet,
  847. Method: types.HTTPVerbGet,
  848. Path: &types.Path{
  849. Parent: basePath,
  850. RelativePath: relPath + "/registries/docr/token",
  851. },
  852. Scopes: []types.PermissionScope{
  853. types.UserScope,
  854. types.ProjectScope,
  855. },
  856. },
  857. )
  858. getDOCRTokenHandler := registry.NewRegistryGetDOCRTokenHandler(
  859. config,
  860. factory.GetDecoderValidator(),
  861. factory.GetResultWriter(),
  862. )
  863. routes = append(routes, &router.Route{
  864. Endpoint: getDOCRTokenEndpoint,
  865. Handler: getDOCRTokenHandler,
  866. Router: r,
  867. })
  868. // GET /api/projects/{project_id}/registries/gcr/token -> registry.NewRegistryGetGCRTokenHandler
  869. getGCRTokenEndpoint := factory.NewAPIEndpoint(
  870. &types.APIRequestMetadata{
  871. Verb: types.APIVerbGet,
  872. Method: types.HTTPVerbGet,
  873. Path: &types.Path{
  874. Parent: basePath,
  875. RelativePath: relPath + "/registries/gcr/token",
  876. },
  877. Scopes: []types.PermissionScope{
  878. types.UserScope,
  879. types.ProjectScope,
  880. },
  881. },
  882. )
  883. getGCRTokenHandler := registry.NewRegistryGetGCRTokenHandler(
  884. config,
  885. factory.GetDecoderValidator(),
  886. factory.GetResultWriter(),
  887. )
  888. routes = append(routes, &router.Route{
  889. Endpoint: getGCRTokenEndpoint,
  890. Handler: getGCRTokenHandler,
  891. Router: r,
  892. })
  893. // GET /api/projects/{project_id}/registries/gar/token -> registry.NewRegistryGetGARTokenHandler
  894. getGARTokenEndpoint := factory.NewAPIEndpoint(
  895. &types.APIRequestMetadata{
  896. Verb: types.APIVerbGet,
  897. Method: types.HTTPVerbGet,
  898. Path: &types.Path{
  899. Parent: basePath,
  900. RelativePath: relPath + "/registries/gar/token",
  901. },
  902. Scopes: []types.PermissionScope{
  903. types.UserScope,
  904. types.ProjectScope,
  905. },
  906. },
  907. )
  908. getGARTokenHandler := registry.NewRegistryGetGARTokenHandler(
  909. config,
  910. factory.GetDecoderValidator(),
  911. factory.GetResultWriter(),
  912. )
  913. routes = append(routes, &router.Route{
  914. Endpoint: getGARTokenEndpoint,
  915. Handler: getGARTokenHandler,
  916. Router: r,
  917. })
  918. // GET /api/projects/{project_id}/registries/acr/token -> registry.NewRegistryGetACRTokenHandler
  919. getACRTokenEndpoint := factory.NewAPIEndpoint(
  920. &types.APIRequestMetadata{
  921. Verb: types.APIVerbGet,
  922. Method: types.HTTPVerbGet,
  923. Path: &types.Path{
  924. Parent: basePath,
  925. RelativePath: relPath + "/registries/acr/token",
  926. },
  927. Scopes: []types.PermissionScope{
  928. types.UserScope,
  929. types.ProjectScope,
  930. },
  931. },
  932. )
  933. getACRTokenHandler := registry.NewRegistryGetACRTokenHandler(
  934. config,
  935. factory.GetDecoderValidator(),
  936. factory.GetResultWriter(),
  937. )
  938. routes = append(routes, &router.Route{
  939. Endpoint: getACRTokenEndpoint,
  940. Handler: getACRTokenHandler,
  941. Router: r,
  942. })
  943. // GET /api/projects/{project_id}/registries/dockerhub/token -> registry.NewRegistryGetDockerhubTokenHandler
  944. getDockerhubTokenEndpoint := factory.NewAPIEndpoint(
  945. &types.APIRequestMetadata{
  946. Verb: types.APIVerbGet,
  947. Method: types.HTTPVerbGet,
  948. Path: &types.Path{
  949. Parent: basePath,
  950. RelativePath: relPath + "/registries/dockerhub/token",
  951. },
  952. Scopes: []types.PermissionScope{
  953. types.UserScope,
  954. types.ProjectScope,
  955. },
  956. },
  957. )
  958. getDockerhubTokenHandler := registry.NewRegistryGetDockerhubTokenHandler(
  959. config,
  960. factory.GetDecoderValidator(),
  961. factory.GetResultWriter(),
  962. )
  963. routes = append(routes, &router.Route{
  964. Endpoint: getDockerhubTokenEndpoint,
  965. Handler: getDockerhubTokenHandler,
  966. Router: r,
  967. })
  968. // POST /api/projects/{project_id}/infras -> infra.NewInfraCreateHandler
  969. createInfraEndpoint := factory.NewAPIEndpoint(
  970. &types.APIRequestMetadata{
  971. Verb: types.APIVerbCreate,
  972. Method: types.HTTPVerbPost,
  973. Path: &types.Path{
  974. Parent: basePath,
  975. RelativePath: relPath + "/infras",
  976. },
  977. Scopes: []types.PermissionScope{
  978. types.UserScope,
  979. types.ProjectScope,
  980. },
  981. },
  982. )
  983. createInfraHandler := infra.NewInfraCreateHandler(
  984. config,
  985. factory.GetDecoderValidator(),
  986. factory.GetResultWriter(),
  987. )
  988. routes = append(routes, &router.Route{
  989. Endpoint: createInfraEndpoint,
  990. Handler: createInfraHandler,
  991. Router: r,
  992. })
  993. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  994. getTemplatesEndpoint := factory.NewAPIEndpoint(
  995. &types.APIRequestMetadata{
  996. Verb: types.APIVerbGet,
  997. Method: types.HTTPVerbGet,
  998. Path: &types.Path{
  999. Parent: basePath,
  1000. RelativePath: relPath + "/infras/templates",
  1001. },
  1002. Scopes: []types.PermissionScope{
  1003. types.UserScope,
  1004. types.ProjectScope,
  1005. },
  1006. },
  1007. )
  1008. getTemplatesHandler := infra.NewInfraListTemplateHandler(
  1009. config,
  1010. factory.GetResultWriter(),
  1011. )
  1012. routes = append(routes, &router.Route{
  1013. Endpoint: getTemplatesEndpoint,
  1014. Handler: getTemplatesHandler,
  1015. Router: r,
  1016. })
  1017. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  1018. getTemplateEndpoint := factory.NewAPIEndpoint(
  1019. &types.APIRequestMetadata{
  1020. Verb: types.APIVerbGet,
  1021. Method: types.HTTPVerbGet,
  1022. Path: &types.Path{
  1023. Parent: basePath,
  1024. RelativePath: fmt.Sprintf("%s/infras/templates/{%s}/{%s}", relPath, types.URLParamTemplateName, types.URLParamTemplateVersion),
  1025. },
  1026. Scopes: []types.PermissionScope{
  1027. types.UserScope,
  1028. types.ProjectScope,
  1029. },
  1030. },
  1031. )
  1032. getTemplateHandler := infra.NewInfraGetTemplateHandler(
  1033. config,
  1034. factory.GetResultWriter(),
  1035. )
  1036. routes = append(routes, &router.Route{
  1037. Endpoint: getTemplateEndpoint,
  1038. Handler: getTemplateHandler,
  1039. Router: r,
  1040. })
  1041. // // POST /api/projects/{project_id}/provision/ecr -> provision.NewProvisionECRHandler
  1042. // provisionECREndpoint := factory.NewAPIEndpoint(
  1043. // &types.APIRequestMetadata{
  1044. // Verb: types.APIVerbCreate,
  1045. // Method: types.HTTPVerbPost,
  1046. // Path: &types.Path{
  1047. // Parent: basePath,
  1048. // RelativePath: relPath + "/provision/ecr",
  1049. // },
  1050. // Scopes: []types.PermissionScope{
  1051. // types.UserScope,
  1052. // types.ProjectScope,
  1053. // },
  1054. // },
  1055. // )
  1056. // provisionECRHandler := provision.NewProvisionECRHandler(
  1057. // config,
  1058. // factory.GetDecoderValidator(),
  1059. // factory.GetResultWriter(),
  1060. // )
  1061. // routes = append(routes, &router.Route{
  1062. // Endpoint: provisionECREndpoint,
  1063. // Handler: provisionECRHandler,
  1064. // Router: r,
  1065. // })
  1066. // // POST /api/projects/{project_id}/provision/eks -> provision.NewProvisionEKSHandler
  1067. // provisionEKSEndpoint := factory.NewAPIEndpoint(
  1068. // &types.APIRequestMetadata{
  1069. // Verb: types.APIVerbCreate,
  1070. // Method: types.HTTPVerbPost,
  1071. // Path: &types.Path{
  1072. // Parent: basePath,
  1073. // RelativePath: relPath + "/provision/eks",
  1074. // },
  1075. // Scopes: []types.PermissionScope{
  1076. // types.UserScope,
  1077. // types.ProjectScope,
  1078. // },
  1079. // CheckUsage: true,
  1080. // UsageMetric: types.Clusters,
  1081. // },
  1082. // )
  1083. // provisionEKSHandler := provision.NewProvisionEKSHandler(
  1084. // config,
  1085. // factory.GetDecoderValidator(),
  1086. // factory.GetResultWriter(),
  1087. // )
  1088. // routes = append(routes, &router.Route{
  1089. // Endpoint: provisionEKSEndpoint,
  1090. // Handler: provisionEKSHandler,
  1091. // Router: r,
  1092. // })
  1093. // // POST /api/projects/{project_id}/provision/docr -> provision.NewProvisionDOCRHandler
  1094. // provisionDOCREndpoint := factory.NewAPIEndpoint(
  1095. // &types.APIRequestMetadata{
  1096. // Verb: types.APIVerbCreate,
  1097. // Method: types.HTTPVerbPost,
  1098. // Path: &types.Path{
  1099. // Parent: basePath,
  1100. // RelativePath: relPath + "/provision/docr",
  1101. // },
  1102. // Scopes: []types.PermissionScope{
  1103. // types.UserScope,
  1104. // types.ProjectScope,
  1105. // },
  1106. // },
  1107. // )
  1108. // provisionDOCRHandler := provision.NewProvisionDOCRHandler(
  1109. // config,
  1110. // factory.GetDecoderValidator(),
  1111. // factory.GetResultWriter(),
  1112. // )
  1113. // routes = append(routes, &router.Route{
  1114. // Endpoint: provisionDOCREndpoint,
  1115. // Handler: provisionDOCRHandler,
  1116. // Router: r,
  1117. // })
  1118. // // POST /api/projects/{project_id}/provision/doks -> provision.NewProvisionDOKSHandler
  1119. // provisionDOKSEndpoint := factory.NewAPIEndpoint(
  1120. // &types.APIRequestMetadata{
  1121. // Verb: types.APIVerbCreate,
  1122. // Method: types.HTTPVerbPost,
  1123. // Path: &types.Path{
  1124. // Parent: basePath,
  1125. // RelativePath: relPath + "/provision/doks",
  1126. // },
  1127. // Scopes: []types.PermissionScope{
  1128. // types.UserScope,
  1129. // types.ProjectScope,
  1130. // },
  1131. // CheckUsage: true,
  1132. // UsageMetric: types.Clusters,
  1133. // },
  1134. // )
  1135. // provisionDOKSHandler := provision.NewProvisionDOKSHandler(
  1136. // config,
  1137. // factory.GetDecoderValidator(),
  1138. // factory.GetResultWriter(),
  1139. // )
  1140. // routes = append(routes, &router.Route{
  1141. // Endpoint: provisionDOKSEndpoint,
  1142. // Handler: provisionDOKSHandler,
  1143. // Router: r,
  1144. // })
  1145. // // POST /api/projects/{project_id}/provision/gcr -> provision.NewProvisionGCRHandler
  1146. // provisionGCREndpoint := factory.NewAPIEndpoint(
  1147. // &types.APIRequestMetadata{
  1148. // Verb: types.APIVerbCreate,
  1149. // Method: types.HTTPVerbPost,
  1150. // Path: &types.Path{
  1151. // Parent: basePath,
  1152. // RelativePath: relPath + "/provision/gcr",
  1153. // },
  1154. // Scopes: []types.PermissionScope{
  1155. // types.UserScope,
  1156. // types.ProjectScope,
  1157. // },
  1158. // },
  1159. // )
  1160. // provisionGCRHandler := provision.NewProvisionGCRHandler(
  1161. // config,
  1162. // factory.GetDecoderValidator(),
  1163. // factory.GetResultWriter(),
  1164. // )
  1165. // routes = append(routes, &router.Route{
  1166. // Endpoint: provisionGCREndpoint,
  1167. // Handler: provisionGCRHandler,
  1168. // Router: r,
  1169. // })
  1170. // // POST /api/projects/{project_id}/provision/gke -> provision.NewProvisionGKEHandler
  1171. // provisionGKEEndpoint := factory.NewAPIEndpoint(
  1172. // &types.APIRequestMetadata{
  1173. // Verb: types.APIVerbCreate,
  1174. // Method: types.HTTPVerbPost,
  1175. // Path: &types.Path{
  1176. // Parent: basePath,
  1177. // RelativePath: relPath + "/provision/gke",
  1178. // },
  1179. // Scopes: []types.PermissionScope{
  1180. // types.UserScope,
  1181. // types.ProjectScope,
  1182. // },
  1183. // CheckUsage: true,
  1184. // UsageMetric: types.Clusters,
  1185. // },
  1186. // )
  1187. // provisionGKEHandler := provision.NewProvisionGKEHandler(
  1188. // config,
  1189. // factory.GetDecoderValidator(),
  1190. // factory.GetResultWriter(),
  1191. // )
  1192. // routes = append(routes, &router.Route{
  1193. // Endpoint: provisionGKEEndpoint,
  1194. // Handler: provisionGKEHandler,
  1195. // Router: r,
  1196. // })
  1197. // POST /api/projects/{project_id}/connect -> project.NewProjectConnectHandler
  1198. connectEndpoint := factory.NewAPIEndpoint(
  1199. &types.APIRequestMetadata{
  1200. Verb: types.APIVerbCreate,
  1201. Method: types.HTTPVerbPost,
  1202. Path: &types.Path{
  1203. Parent: basePath,
  1204. RelativePath: relPath + "/connect",
  1205. },
  1206. Scopes: []types.PermissionScope{
  1207. types.UserScope,
  1208. types.ProjectScope,
  1209. types.SettingsScope,
  1210. },
  1211. },
  1212. )
  1213. connectHandler := project.NewConnectHandler(
  1214. config,
  1215. factory.GetDecoderValidator(),
  1216. factory.GetResultWriter(),
  1217. )
  1218. routes = append(routes, &router.Route{
  1219. Endpoint: connectEndpoint,
  1220. Handler: connectHandler,
  1221. Router: r,
  1222. })
  1223. // POST /api/projects/{project_id}/policy -> policy.NewPolicyCreateHandler
  1224. policyCreateEndpoint := factory.NewAPIEndpoint(
  1225. &types.APIRequestMetadata{
  1226. Verb: types.APIVerbCreate,
  1227. Method: types.HTTPVerbPost,
  1228. Path: &types.Path{
  1229. Parent: basePath,
  1230. RelativePath: relPath + "/policy",
  1231. },
  1232. Scopes: []types.PermissionScope{
  1233. types.UserScope,
  1234. types.ProjectScope,
  1235. types.SettingsScope,
  1236. },
  1237. },
  1238. )
  1239. policyCreateHandler := policy.NewPolicyCreateHandler(
  1240. config,
  1241. factory.GetDecoderValidator(),
  1242. factory.GetResultWriter(),
  1243. )
  1244. routes = append(routes, &router.Route{
  1245. Endpoint: policyCreateEndpoint,
  1246. Handler: policyCreateHandler,
  1247. Router: r,
  1248. })
  1249. // GET /api/projects/{project_id}/policies -> policy.NewPolicyListHandler
  1250. policyListEndpoint := factory.NewAPIEndpoint(
  1251. &types.APIRequestMetadata{
  1252. Verb: types.APIVerbList,
  1253. Method: types.HTTPVerbGet,
  1254. Path: &types.Path{
  1255. Parent: basePath,
  1256. RelativePath: relPath + "/policies",
  1257. },
  1258. Scopes: []types.PermissionScope{
  1259. types.UserScope,
  1260. types.ProjectScope,
  1261. types.SettingsScope,
  1262. },
  1263. },
  1264. )
  1265. policyListHandler := policy.NewPolicyListHandler(
  1266. config,
  1267. factory.GetDecoderValidator(),
  1268. factory.GetResultWriter(),
  1269. )
  1270. routes = append(routes, &router.Route{
  1271. Endpoint: policyListEndpoint,
  1272. Handler: policyListHandler,
  1273. Router: r,
  1274. })
  1275. // GET /api/projects/{project_id}/policy/{policy_id} -> policy.NewPolicyGetHandler
  1276. policyGetEndpoint := factory.NewAPIEndpoint(
  1277. &types.APIRequestMetadata{
  1278. Verb: types.APIVerbGet,
  1279. Method: types.HTTPVerbGet,
  1280. Path: &types.Path{
  1281. Parent: basePath,
  1282. RelativePath: fmt.Sprintf("%s/policy/{%s}", relPath, types.URLParamPolicyID),
  1283. },
  1284. Scopes: []types.PermissionScope{
  1285. types.UserScope,
  1286. types.ProjectScope,
  1287. types.SettingsScope,
  1288. },
  1289. },
  1290. )
  1291. policyGetHandler := policy.NewPolicyGetHandler(
  1292. config,
  1293. factory.GetDecoderValidator(),
  1294. factory.GetResultWriter(),
  1295. )
  1296. routes = append(routes, &router.Route{
  1297. Endpoint: policyGetEndpoint,
  1298. Handler: policyGetHandler,
  1299. Router: r,
  1300. })
  1301. // POST /api/projects/{project_id}/api_token -> api_token.NewAPITokenCreateHandler
  1302. apiTokenCreateEndpoint := factory.NewAPIEndpoint(
  1303. &types.APIRequestMetadata{
  1304. Verb: types.APIVerbCreate,
  1305. Method: types.HTTPVerbPost,
  1306. Path: &types.Path{
  1307. Parent: basePath,
  1308. RelativePath: relPath + "/api_token",
  1309. },
  1310. Scopes: []types.PermissionScope{
  1311. types.UserScope,
  1312. types.ProjectScope,
  1313. types.SettingsScope,
  1314. },
  1315. },
  1316. )
  1317. apiTokenCreateHandler := api_token.NewAPITokenCreateHandler(
  1318. config,
  1319. factory.GetDecoderValidator(),
  1320. factory.GetResultWriter(),
  1321. )
  1322. routes = append(routes, &router.Route{
  1323. Endpoint: apiTokenCreateEndpoint,
  1324. Handler: apiTokenCreateHandler,
  1325. Router: r,
  1326. })
  1327. // GET /api/projects/{project_id}/api_token -> api_token.NewAPITokenListHandler
  1328. apiTokenListEndpoint := factory.NewAPIEndpoint(
  1329. &types.APIRequestMetadata{
  1330. Verb: types.APIVerbList,
  1331. Method: types.HTTPVerbGet,
  1332. Path: &types.Path{
  1333. Parent: basePath,
  1334. RelativePath: fmt.Sprintf("%s/api_token", relPath),
  1335. },
  1336. Scopes: []types.PermissionScope{
  1337. types.UserScope,
  1338. types.ProjectScope,
  1339. types.SettingsScope,
  1340. },
  1341. },
  1342. )
  1343. apiTokenListHandler := api_token.NewAPITokenListHandler(
  1344. config,
  1345. factory.GetDecoderValidator(),
  1346. factory.GetResultWriter(),
  1347. )
  1348. routes = append(routes, &router.Route{
  1349. Endpoint: apiTokenListEndpoint,
  1350. Handler: apiTokenListHandler,
  1351. Router: r,
  1352. })
  1353. // GET /api/projects/{project_id}/api_token/{api_token_id} -> api_token.NewAPITokenGetHandler
  1354. apiTokenGetEndpoint := factory.NewAPIEndpoint(
  1355. &types.APIRequestMetadata{
  1356. Verb: types.APIVerbGet,
  1357. Method: types.HTTPVerbGet,
  1358. Path: &types.Path{
  1359. Parent: basePath,
  1360. RelativePath: fmt.Sprintf("%s/api_token/{%s}", relPath, types.URLParamTokenID),
  1361. },
  1362. Scopes: []types.PermissionScope{
  1363. types.UserScope,
  1364. types.ProjectScope,
  1365. types.SettingsScope,
  1366. },
  1367. },
  1368. )
  1369. apiTokenGetHandler := api_token.NewAPITokenGetHandler(
  1370. config,
  1371. factory.GetDecoderValidator(),
  1372. factory.GetResultWriter(),
  1373. )
  1374. routes = append(routes, &router.Route{
  1375. Endpoint: apiTokenGetEndpoint,
  1376. Handler: apiTokenGetHandler,
  1377. Router: r,
  1378. })
  1379. // POST /api/projects/{project_id}/api_token/{api_token_id}/revoke -> api_token.NewAPITokenRevokeHandler
  1380. apiTokenRevokeEndpoint := factory.NewAPIEndpoint(
  1381. &types.APIRequestMetadata{
  1382. Verb: types.APIVerbUpdate,
  1383. Method: types.HTTPVerbPost,
  1384. Path: &types.Path{
  1385. Parent: basePath,
  1386. RelativePath: fmt.Sprintf("%s/api_token/{%s}/revoke", relPath, types.URLParamTokenID),
  1387. },
  1388. Scopes: []types.PermissionScope{
  1389. types.UserScope,
  1390. types.ProjectScope,
  1391. types.SettingsScope,
  1392. },
  1393. },
  1394. )
  1395. apiTokenRevokeHandler := api_token.NewAPITokenRevokeHandler(
  1396. config,
  1397. factory.GetDecoderValidator(),
  1398. factory.GetResultWriter(),
  1399. )
  1400. routes = append(routes, &router.Route{
  1401. Endpoint: apiTokenRevokeEndpoint,
  1402. Handler: apiTokenRevokeHandler,
  1403. Router: r,
  1404. })
  1405. // POST /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoCreateHandler
  1406. hrCreateEndpoint := factory.NewAPIEndpoint(
  1407. &types.APIRequestMetadata{
  1408. Verb: types.APIVerbCreate,
  1409. Method: types.HTTPVerbPost,
  1410. Path: &types.Path{
  1411. Parent: basePath,
  1412. RelativePath: relPath + "/helmrepos",
  1413. },
  1414. Scopes: []types.PermissionScope{
  1415. types.UserScope,
  1416. types.ProjectScope,
  1417. },
  1418. },
  1419. )
  1420. hrCreateHandler := helmrepo.NewHelmRepoCreateHandler(
  1421. config,
  1422. factory.GetDecoderValidator(),
  1423. factory.GetResultWriter(),
  1424. )
  1425. routes = append(routes, &router.Route{
  1426. Endpoint: hrCreateEndpoint,
  1427. Handler: hrCreateHandler,
  1428. Router: r,
  1429. })
  1430. // GET /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoListHandler
  1431. hrListEndpoint := factory.NewAPIEndpoint(
  1432. &types.APIRequestMetadata{
  1433. Verb: types.APIVerbList,
  1434. Method: types.HTTPVerbGet,
  1435. Path: &types.Path{
  1436. Parent: basePath,
  1437. RelativePath: relPath + "/helmrepos",
  1438. },
  1439. Scopes: []types.PermissionScope{
  1440. types.UserScope,
  1441. types.ProjectScope,
  1442. },
  1443. },
  1444. )
  1445. hrListHandler := helmrepo.NewHelmRepoListHandler(
  1446. config,
  1447. factory.GetResultWriter(),
  1448. )
  1449. routes = append(routes, &router.Route{
  1450. Endpoint: hrListEndpoint,
  1451. Handler: hrListHandler,
  1452. Router: r,
  1453. })
  1454. // GET /api/projects/{project_id}/tags -> project.NewGetTagsHandler
  1455. getTagsEndpoint := factory.NewAPIEndpoint(
  1456. &types.APIRequestMetadata{
  1457. Verb: types.APIVerbGet,
  1458. Method: types.HTTPVerbGet,
  1459. Path: &types.Path{
  1460. Parent: basePath,
  1461. RelativePath: relPath + "/tags",
  1462. },
  1463. Scopes: []types.PermissionScope{
  1464. types.UserScope,
  1465. types.ProjectScope,
  1466. },
  1467. },
  1468. )
  1469. getTagsHandler := project.NewGetTagsHandler(
  1470. config,
  1471. factory.GetResultWriter(),
  1472. )
  1473. routes = append(routes, &router.Route{
  1474. Endpoint: getTagsEndpoint,
  1475. Handler: getTagsHandler,
  1476. Router: r,
  1477. })
  1478. // POST /api/projects/{project_id}/tags -> project.NewCreateTagHandler
  1479. createTagEndpoint := factory.NewAPIEndpoint(
  1480. &types.APIRequestMetadata{
  1481. Verb: types.APIVerbCreate,
  1482. Method: types.HTTPVerbPost,
  1483. Path: &types.Path{
  1484. Parent: basePath,
  1485. RelativePath: relPath + "/tags",
  1486. },
  1487. Scopes: []types.PermissionScope{
  1488. types.UserScope,
  1489. types.ProjectScope,
  1490. },
  1491. },
  1492. )
  1493. createTagHandler := project.NewCreateTagHandler(
  1494. config,
  1495. factory.GetDecoderValidator(),
  1496. factory.GetResultWriter(),
  1497. )
  1498. routes = append(routes, &router.Route{
  1499. Endpoint: createTagEndpoint,
  1500. Handler: createTagHandler,
  1501. Router: r,
  1502. })
  1503. // POST /api/projects/{project_id}/contract -> apiContract.NewAPIContractUpdateHandler
  1504. updateAPIContractEndpoint := factory.NewAPIEndpoint(
  1505. &types.APIRequestMetadata{
  1506. Verb: types.APIVerbCreate,
  1507. Method: types.HTTPVerbPost,
  1508. Path: &types.Path{
  1509. Parent: basePath,
  1510. RelativePath: relPath + "/contract",
  1511. },
  1512. Scopes: []types.PermissionScope{
  1513. types.UserScope,
  1514. types.ProjectScope,
  1515. },
  1516. },
  1517. )
  1518. updateAPIContractHandler := apiContract.NewAPIContractUpdateHandler(
  1519. config,
  1520. factory.GetDecoderValidator(),
  1521. factory.GetResultWriter(),
  1522. )
  1523. routes = append(routes, &router.Route{
  1524. Endpoint: updateAPIContractEndpoint,
  1525. Handler: updateAPIContractHandler,
  1526. Router: r,
  1527. })
  1528. // GET /api/projects/{project_id}/contracts -> apiContract.NewAPIContractRevisionListHandler
  1529. listAPIContractRevisionsEndpoint := factory.NewAPIEndpoint(
  1530. &types.APIRequestMetadata{
  1531. Verb: types.APIVerbGet,
  1532. Method: types.HTTPVerbGet,
  1533. Path: &types.Path{
  1534. Parent: basePath,
  1535. RelativePath: relPath + "/contracts",
  1536. },
  1537. Scopes: []types.PermissionScope{
  1538. types.UserScope,
  1539. types.ProjectScope,
  1540. },
  1541. },
  1542. )
  1543. listAPIContractRevisionHandler := apiContract.NewAPIContractRevisionListHandler(
  1544. config,
  1545. factory.GetDecoderValidator(),
  1546. factory.GetResultWriter(),
  1547. )
  1548. routes = append(routes, &router.Route{
  1549. Endpoint: listAPIContractRevisionsEndpoint,
  1550. Handler: listAPIContractRevisionHandler,
  1551. Router: r,
  1552. })
  1553. // DELETE /api/projects/{project_id}/contracts/{revision_id} -> apiContract.NewAPIContractUpdateHandler
  1554. deleteAPIContractRevisionsEndpoint := factory.NewAPIEndpoint(
  1555. &types.APIRequestMetadata{
  1556. Verb: types.APIVerbDelete,
  1557. Method: types.HTTPVerbDelete,
  1558. Path: &types.Path{
  1559. Parent: basePath,
  1560. RelativePath: fmt.Sprintf("%s/contracts/{%s}", relPath, types.URLParamAPIContractRevisionID),
  1561. },
  1562. Scopes: []types.PermissionScope{
  1563. types.UserScope,
  1564. types.ProjectScope,
  1565. types.APIContractRevisionScope,
  1566. },
  1567. },
  1568. )
  1569. deleteAPIContractRevisionHandler := apiContract.NewAPIContractRevisionDeleteHandler(
  1570. config,
  1571. factory.GetDecoderValidator(),
  1572. factory.GetResultWriter(),
  1573. )
  1574. routes = append(routes, &router.Route{
  1575. Endpoint: deleteAPIContractRevisionsEndpoint,
  1576. Handler: deleteAPIContractRevisionHandler,
  1577. Router: r,
  1578. })
  1579. // POST /api/projects/{project_id}/contract/preflight -> apiContract.NewPreflightCheckHandler
  1580. preflightCheckEndpoint := factory.NewAPIEndpoint(
  1581. &types.APIRequestMetadata{
  1582. Verb: types.APIVerbCreate,
  1583. Method: types.HTTPVerbPost,
  1584. Path: &types.Path{
  1585. Parent: basePath,
  1586. RelativePath: fmt.Sprintf("%s/contract/preflight", relPath),
  1587. },
  1588. Scopes: []types.PermissionScope{
  1589. types.UserScope,
  1590. types.ProjectScope,
  1591. },
  1592. },
  1593. )
  1594. preflightCheckHandler := apiContract.NewPreflightCheckHandler(
  1595. config,
  1596. factory.GetDecoderValidator(),
  1597. factory.GetResultWriter(),
  1598. )
  1599. routes = append(routes, &router.Route{
  1600. Endpoint: preflightCheckEndpoint,
  1601. Handler: preflightCheckHandler,
  1602. Router: r,
  1603. })
  1604. // POST /api/projects/{project_id}/rename -> cluster.newRenamProject
  1605. renameProjectEndpoint := factory.NewAPIEndpoint(
  1606. &types.APIRequestMetadata{
  1607. Verb: types.APIVerbCreate,
  1608. Method: types.HTTPVerbPost,
  1609. Path: &types.Path{
  1610. Parent: basePath,
  1611. RelativePath: relPath + "/rename",
  1612. },
  1613. Scopes: []types.PermissionScope{
  1614. types.UserScope,
  1615. types.ProjectScope,
  1616. },
  1617. },
  1618. )
  1619. renameProjectHandler := project.NewRenameProjectHandler(
  1620. config,
  1621. factory.GetDecoderValidator(),
  1622. factory.GetResultWriter(),
  1623. )
  1624. routes = append(routes, &router.Route{
  1625. Endpoint: renameProjectEndpoint,
  1626. Handler: renameProjectHandler,
  1627. Router: r,
  1628. })
  1629. // GET /api/projects/{project_id}/images -> project.ImagesHandler
  1630. imagesEndpoint := factory.NewAPIEndpoint(
  1631. &types.APIRequestMetadata{
  1632. Verb: types.APIVerbList,
  1633. Method: types.HTTPVerbGet,
  1634. Path: &types.Path{
  1635. Parent: basePath,
  1636. RelativePath: relPath + "/images",
  1637. },
  1638. Scopes: []types.PermissionScope{
  1639. types.UserScope,
  1640. types.ProjectScope,
  1641. },
  1642. },
  1643. )
  1644. imagesHandler := project.NewImagesHandler(
  1645. config,
  1646. factory.GetResultWriter(),
  1647. )
  1648. routes = append(routes, &router.Route{
  1649. Endpoint: imagesEndpoint,
  1650. Handler: imagesHandler,
  1651. Router: r,
  1652. })
  1653. // GET /api/projects/{project_id}/targets -> deployment_target.ListDeploymentTargetHandler
  1654. listDeploymentTargetEndpoint := factory.NewAPIEndpoint(
  1655. &types.APIRequestMetadata{
  1656. Verb: types.APIVerbGet,
  1657. Method: types.HTTPVerbGet,
  1658. Path: &types.Path{
  1659. Parent: basePath,
  1660. RelativePath: fmt.Sprintf("%s/targets", relPath),
  1661. },
  1662. Scopes: []types.PermissionScope{
  1663. types.UserScope,
  1664. types.ProjectScope,
  1665. },
  1666. },
  1667. )
  1668. listDeploymentTargetHandler := deployment_target.NewListDeploymentTargetsHandler(
  1669. config,
  1670. factory.GetDecoderValidator(),
  1671. factory.GetResultWriter(),
  1672. )
  1673. routes = append(routes, &router.Route{
  1674. Endpoint: listDeploymentTargetEndpoint,
  1675. Handler: listDeploymentTargetHandler,
  1676. Router: r,
  1677. })
  1678. // GET /api/projects/{project_id}/targets -> deployment_target.ListDeploymentTargetHandler
  1679. createDeploymentTargetEndpoint := factory.NewAPIEndpoint(
  1680. &types.APIRequestMetadata{
  1681. Verb: types.APIVerbCreate,
  1682. Method: types.HTTPVerbPost,
  1683. Path: &types.Path{
  1684. Parent: basePath,
  1685. RelativePath: fmt.Sprintf("%s/targets", relPath),
  1686. },
  1687. Scopes: []types.PermissionScope{
  1688. types.UserScope,
  1689. types.ProjectScope,
  1690. },
  1691. },
  1692. )
  1693. createDeploymentTargetHandler := deployment_target.NewCreateDeploymentTargetHandler(
  1694. config,
  1695. factory.GetDecoderValidator(),
  1696. factory.GetResultWriter(),
  1697. )
  1698. routes = append(routes, &router.Route{
  1699. Endpoint: createDeploymentTargetEndpoint,
  1700. Handler: createDeploymentTargetHandler,
  1701. Router: r,
  1702. })
  1703. return routes, newPath
  1704. }