project.go 49 KB

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