project.go 43 KB

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