2
0

project.go 48 KB

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