project.go 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573
  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/project/{project_id}/billing/redirect -> billing.NewRedirectBillingHandler
  254. redirectBillingEndpoint := factory.NewAPIEndpoint(
  255. &types.APIRequestMetadata{
  256. Verb: types.APIVerbGet,
  257. Method: types.HTTPVerbGet,
  258. Path: &types.Path{
  259. Parent: basePath,
  260. RelativePath: relPath + "/billing/redirect",
  261. },
  262. Scopes: []types.PermissionScope{
  263. types.UserScope,
  264. types.ProjectScope,
  265. },
  266. },
  267. )
  268. redirectBillingHandler := billing.NewRedirectBillingHandler(
  269. config,
  270. factory.GetResultWriter(),
  271. )
  272. routes = append(routes, &router.Route{
  273. Endpoint: redirectBillingEndpoint,
  274. Handler: redirectBillingHandler,
  275. Router: r,
  276. })
  277. // GET /api/projects/{project_id}/billing -> project.NewProjectGetBillingHandler
  278. getBillingEndpoint := factory.NewAPIEndpoint(
  279. &types.APIRequestMetadata{
  280. Verb: types.APIVerbGet,
  281. Method: types.HTTPVerbGet,
  282. Path: &types.Path{
  283. Parent: basePath,
  284. RelativePath: relPath + "/billing",
  285. },
  286. Scopes: []types.PermissionScope{
  287. types.UserScope,
  288. types.ProjectScope,
  289. },
  290. },
  291. )
  292. getBillingHandler := project.NewProjectGetBillingHandler(
  293. config,
  294. factory.GetResultWriter(),
  295. )
  296. routes = append(routes, &router.Route{
  297. Endpoint: getBillingEndpoint,
  298. Handler: getBillingHandler,
  299. Router: r,
  300. })
  301. // GET /api/billing_webhook -> billing.NewBillingWebhookHandler
  302. getBillingWebhookEndpoint := factory.NewAPIEndpoint(
  303. &types.APIRequestMetadata{
  304. Verb: types.APIVerbCreate,
  305. Method: types.HTTPVerbPost,
  306. Path: &types.Path{
  307. Parent: basePath,
  308. RelativePath: "/billing_webhook",
  309. },
  310. Scopes: []types.PermissionScope{},
  311. },
  312. )
  313. getBillingWebhookHandler := billing.NewBillingWebhookHandler(
  314. config,
  315. factory.GetDecoderValidator(),
  316. )
  317. routes = append(routes, &router.Route{
  318. Endpoint: getBillingWebhookEndpoint,
  319. Handler: getBillingWebhookHandler,
  320. Router: r,
  321. })
  322. // GET /api/projects/{project_id}/clusters -> cluster.NewClusterListHandler
  323. listClusterEndpoint := factory.NewAPIEndpoint(
  324. &types.APIRequestMetadata{
  325. Verb: types.APIVerbList,
  326. Method: types.HTTPVerbGet,
  327. Path: &types.Path{
  328. Parent: basePath,
  329. RelativePath: relPath + "/clusters",
  330. },
  331. Scopes: []types.PermissionScope{
  332. types.UserScope,
  333. types.ProjectScope,
  334. },
  335. },
  336. )
  337. listClusterHandler := cluster.NewClusterListHandler(
  338. config,
  339. factory.GetResultWriter(),
  340. )
  341. routes = append(routes, &router.Route{
  342. Endpoint: listClusterEndpoint,
  343. Handler: listClusterHandler,
  344. Router: r,
  345. })
  346. // GET /api/projects/{project_id}/gitrepos -> gitinstallation.NewGitRepoListHandler
  347. listGitReposEndpoint := factory.NewAPIEndpoint(
  348. &types.APIRequestMetadata{
  349. Verb: types.APIVerbList,
  350. Method: types.HTTPVerbGet,
  351. Path: &types.Path{
  352. Parent: basePath,
  353. RelativePath: relPath + "/gitrepos",
  354. },
  355. Scopes: []types.PermissionScope{
  356. types.UserScope,
  357. types.ProjectScope,
  358. },
  359. },
  360. )
  361. listGitReposHandler := gitinstallation.NewGitRepoListHandler(
  362. config,
  363. factory.GetResultWriter(),
  364. )
  365. routes = append(routes, &router.Route{
  366. Endpoint: listGitReposEndpoint,
  367. Handler: listGitReposHandler,
  368. Router: r,
  369. })
  370. // GET /api/projects/{project_id}/collaborators -> project.NewCollaboratorsListHandler
  371. listCollaboratorsEndpoint := factory.NewAPIEndpoint(
  372. &types.APIRequestMetadata{
  373. Verb: types.APIVerbList,
  374. Method: types.HTTPVerbGet,
  375. Path: &types.Path{
  376. Parent: basePath,
  377. RelativePath: relPath + "/collaborators",
  378. },
  379. Scopes: []types.PermissionScope{
  380. types.UserScope,
  381. types.ProjectScope,
  382. },
  383. },
  384. )
  385. listCollaboratorsHandler := project.NewCollaboratorsListHandler(
  386. config,
  387. factory.GetResultWriter(),
  388. )
  389. routes = append(routes, &router.Route{
  390. Endpoint: listCollaboratorsEndpoint,
  391. Handler: listCollaboratorsHandler,
  392. Router: r,
  393. })
  394. // GET /api/projects/{project_id}/roles -> project.NewRolesListHandler
  395. listRolesEndpoint := factory.NewAPIEndpoint(
  396. &types.APIRequestMetadata{
  397. Verb: types.APIVerbList,
  398. Method: types.HTTPVerbGet,
  399. Path: &types.Path{
  400. Parent: basePath,
  401. RelativePath: relPath + "/roles",
  402. },
  403. Scopes: []types.PermissionScope{
  404. types.UserScope,
  405. types.ProjectScope,
  406. },
  407. },
  408. )
  409. listRolesHandler := project.NewRolesListHandler(
  410. config,
  411. factory.GetResultWriter(),
  412. )
  413. routes = append(routes, &router.Route{
  414. Endpoint: listRolesEndpoint,
  415. Handler: listRolesHandler,
  416. Router: r,
  417. })
  418. // GET /api/projects/{project_id}/datastores -> datastore.NewListAllDatastoresForProjectHandler
  419. listDatastoresEndpoint := factory.NewAPIEndpoint(
  420. &types.APIRequestMetadata{
  421. Verb: types.APIVerbList,
  422. Method: types.HTTPVerbGet,
  423. Path: &types.Path{
  424. Parent: basePath,
  425. RelativePath: relPath + "/datastores",
  426. },
  427. Scopes: []types.PermissionScope{
  428. types.UserScope,
  429. types.ProjectScope,
  430. },
  431. },
  432. )
  433. listDatastoresHandler := datastore.NewListDatastoresHandler(
  434. config,
  435. factory.GetDecoderValidator(),
  436. factory.GetResultWriter(),
  437. )
  438. routes = append(routes, &router.Route{
  439. Endpoint: listDatastoresEndpoint,
  440. Handler: listDatastoresHandler,
  441. Router: r,
  442. })
  443. // GET /api/projects/{project_id}/datastores -> datastore.NewGetDatastoreHandler
  444. getDatastoreEndpoint := factory.NewAPIEndpoint(
  445. &types.APIRequestMetadata{
  446. Verb: types.APIVerbList,
  447. Method: types.HTTPVerbGet,
  448. Path: &types.Path{
  449. Parent: basePath,
  450. RelativePath: fmt.Sprintf("%s/datastores/{%s}", relPath, types.URLParamDatastoreName),
  451. },
  452. Scopes: []types.PermissionScope{
  453. types.UserScope,
  454. types.ProjectScope,
  455. },
  456. },
  457. )
  458. getDatastoreHandler := datastore.NewGetDatastoreHandler(
  459. config,
  460. factory.GetDecoderValidator(),
  461. factory.GetResultWriter(),
  462. )
  463. routes = append(routes, &router.Route{
  464. Endpoint: getDatastoreEndpoint,
  465. Handler: getDatastoreHandler,
  466. Router: r,
  467. })
  468. // POST /api/projects/{project_id}/datastores/{datastore_name}/create-proxy -> cluster.NewCreateDatastoreProxyHandler
  469. createDatastoreProxyEndpoint := factory.NewAPIEndpoint(
  470. &types.APIRequestMetadata{
  471. Verb: types.APIVerbUpdate,
  472. Method: types.HTTPVerbPost,
  473. Path: &types.Path{
  474. Parent: basePath,
  475. RelativePath: fmt.Sprintf("%s/datastores/{%s}/create-proxy", relPath, types.URLParamDatastoreName),
  476. },
  477. Scopes: []types.PermissionScope{
  478. types.UserScope,
  479. types.ProjectScope,
  480. },
  481. },
  482. )
  483. createDatastoreProxyHandler := datastore.NewCreateDatastoreProxyHandler(
  484. config,
  485. factory.GetDecoderValidator(),
  486. factory.GetResultWriter(),
  487. )
  488. routes = append(routes, &router.Route{
  489. Endpoint: createDatastoreProxyEndpoint,
  490. Handler: createDatastoreProxyHandler,
  491. Router: r,
  492. })
  493. // DELETE /api/projects/{project_id}/datastores/{datastore_name} -> cloud_provider.NewDeleteDatastoreHandler
  494. deleteDatastoreEndpoint := factory.NewAPIEndpoint(
  495. &types.APIRequestMetadata{
  496. Verb: types.APIVerbDelete,
  497. Method: types.HTTPVerbDelete,
  498. Path: &types.Path{
  499. Parent: basePath,
  500. RelativePath: fmt.Sprintf("%s/datastores/{%s}", relPath, types.URLParamDatastoreName),
  501. },
  502. Scopes: []types.PermissionScope{
  503. types.UserScope,
  504. types.ProjectScope,
  505. },
  506. },
  507. )
  508. deleteDatastoreHandler := datastore.NewDeleteDatastoreHandler(
  509. config,
  510. factory.GetDecoderValidator(),
  511. factory.GetResultWriter(),
  512. )
  513. routes = append(routes, &router.Route{
  514. Endpoint: deleteDatastoreEndpoint,
  515. Handler: deleteDatastoreHandler,
  516. Router: r,
  517. })
  518. // POST /api/projects/{project_id}/roles -> project.NewRoleUpdateHandler
  519. updateRoleEndpoint := factory.NewAPIEndpoint(
  520. &types.APIRequestMetadata{
  521. Verb: types.APIVerbUpdate,
  522. Method: types.HTTPVerbPost,
  523. Path: &types.Path{
  524. Parent: basePath,
  525. RelativePath: relPath + "/roles",
  526. },
  527. Scopes: []types.PermissionScope{
  528. types.UserScope,
  529. types.ProjectScope,
  530. },
  531. },
  532. )
  533. updateRoleHandler := project.NewRoleUpdateHandler(
  534. config,
  535. factory.GetDecoderValidator(),
  536. factory.GetResultWriter(),
  537. )
  538. routes = append(routes, &router.Route{
  539. Endpoint: updateRoleEndpoint,
  540. Handler: updateRoleHandler,
  541. Router: r,
  542. })
  543. // DELETE /api/projects/{project_id}/roles -> project.NewRoleDeleteHandler
  544. deleteRoleEndpoint := factory.NewAPIEndpoint(
  545. &types.APIRequestMetadata{
  546. Verb: types.APIVerbDelete,
  547. Method: types.HTTPVerbDelete,
  548. Path: &types.Path{
  549. Parent: basePath,
  550. RelativePath: relPath + "/roles",
  551. },
  552. Scopes: []types.PermissionScope{
  553. types.UserScope,
  554. types.ProjectScope,
  555. },
  556. },
  557. )
  558. deleteRoleHandler := project.NewRoleDeleteHandler(
  559. config,
  560. factory.GetDecoderValidator(),
  561. factory.GetResultWriter(),
  562. )
  563. routes = append(routes, &router.Route{
  564. Endpoint: deleteRoleEndpoint,
  565. Handler: deleteRoleHandler,
  566. Router: r,
  567. })
  568. // GET /api/projects/{project_id}/registries -> registry.NewRegistryListHandler
  569. listRegistriesEndpoint := factory.NewAPIEndpoint(
  570. &types.APIRequestMetadata{
  571. Verb: types.APIVerbList,
  572. Method: types.HTTPVerbGet,
  573. Path: &types.Path{
  574. Parent: basePath,
  575. RelativePath: relPath + "/registries",
  576. },
  577. Scopes: []types.PermissionScope{
  578. types.UserScope,
  579. types.ProjectScope,
  580. },
  581. },
  582. )
  583. listRegistriesHandler := registry.NewRegistryListHandler(
  584. config,
  585. factory.GetResultWriter(),
  586. )
  587. routes = append(routes, &router.Route{
  588. Endpoint: listRegistriesEndpoint,
  589. Handler: listRegistriesHandler,
  590. Router: r,
  591. })
  592. // POST /api/projects/{project_id}/registries -> registry.NewRegistryCreateHandler
  593. createRegistryEndpoint := factory.NewAPIEndpoint(
  594. &types.APIRequestMetadata{
  595. Verb: types.APIVerbCreate,
  596. Method: types.HTTPVerbPost,
  597. Path: &types.Path{
  598. Parent: basePath,
  599. RelativePath: relPath + "/registries",
  600. },
  601. Scopes: []types.PermissionScope{
  602. types.UserScope,
  603. types.ProjectScope,
  604. },
  605. },
  606. )
  607. createRegistryHandler := registry.NewRegistryCreateHandler(
  608. config,
  609. factory.GetDecoderValidator(),
  610. factory.GetResultWriter(),
  611. )
  612. routes = append(routes, &router.Route{
  613. Endpoint: createRegistryEndpoint,
  614. Handler: createRegistryHandler,
  615. Router: r,
  616. })
  617. // GET /api/projects/{project_id}/registries/ecr/token -> registry.NewRegistryGetECRTokenHandler
  618. getECRTokenEndpoint := factory.NewAPIEndpoint(
  619. &types.APIRequestMetadata{
  620. Verb: types.APIVerbGet,
  621. Method: types.HTTPVerbGet,
  622. Path: &types.Path{
  623. Parent: basePath,
  624. RelativePath: relPath + "/registries/ecr/token",
  625. },
  626. Scopes: []types.PermissionScope{
  627. types.UserScope,
  628. types.ProjectScope,
  629. },
  630. },
  631. )
  632. getECRTokenHandler := registry.NewRegistryGetECRTokenHandler(
  633. config,
  634. factory.GetDecoderValidator(),
  635. factory.GetResultWriter(),
  636. )
  637. routes = append(routes, &router.Route{
  638. Endpoint: getECRTokenEndpoint,
  639. Handler: getECRTokenHandler,
  640. Router: r,
  641. })
  642. // GET /api/projects/{project_id}/registries/docr/token -> registry.NewRegistryGetDOCRTokenHandler
  643. getDOCRTokenEndpoint := factory.NewAPIEndpoint(
  644. &types.APIRequestMetadata{
  645. Verb: types.APIVerbGet,
  646. Method: types.HTTPVerbGet,
  647. Path: &types.Path{
  648. Parent: basePath,
  649. RelativePath: relPath + "/registries/docr/token",
  650. },
  651. Scopes: []types.PermissionScope{
  652. types.UserScope,
  653. types.ProjectScope,
  654. },
  655. },
  656. )
  657. getDOCRTokenHandler := registry.NewRegistryGetDOCRTokenHandler(
  658. config,
  659. factory.GetDecoderValidator(),
  660. factory.GetResultWriter(),
  661. )
  662. routes = append(routes, &router.Route{
  663. Endpoint: getDOCRTokenEndpoint,
  664. Handler: getDOCRTokenHandler,
  665. Router: r,
  666. })
  667. // GET /api/projects/{project_id}/registries/gcr/token -> registry.NewRegistryGetGCRTokenHandler
  668. getGCRTokenEndpoint := factory.NewAPIEndpoint(
  669. &types.APIRequestMetadata{
  670. Verb: types.APIVerbGet,
  671. Method: types.HTTPVerbGet,
  672. Path: &types.Path{
  673. Parent: basePath,
  674. RelativePath: relPath + "/registries/gcr/token",
  675. },
  676. Scopes: []types.PermissionScope{
  677. types.UserScope,
  678. types.ProjectScope,
  679. },
  680. },
  681. )
  682. getGCRTokenHandler := registry.NewRegistryGetGCRTokenHandler(
  683. config,
  684. factory.GetDecoderValidator(),
  685. factory.GetResultWriter(),
  686. )
  687. routes = append(routes, &router.Route{
  688. Endpoint: getGCRTokenEndpoint,
  689. Handler: getGCRTokenHandler,
  690. Router: r,
  691. })
  692. // GET /api/projects/{project_id}/registries/gar/token -> registry.NewRegistryGetGARTokenHandler
  693. getGARTokenEndpoint := factory.NewAPIEndpoint(
  694. &types.APIRequestMetadata{
  695. Verb: types.APIVerbGet,
  696. Method: types.HTTPVerbGet,
  697. Path: &types.Path{
  698. Parent: basePath,
  699. RelativePath: relPath + "/registries/gar/token",
  700. },
  701. Scopes: []types.PermissionScope{
  702. types.UserScope,
  703. types.ProjectScope,
  704. },
  705. },
  706. )
  707. getGARTokenHandler := registry.NewRegistryGetGARTokenHandler(
  708. config,
  709. factory.GetDecoderValidator(),
  710. factory.GetResultWriter(),
  711. )
  712. routes = append(routes, &router.Route{
  713. Endpoint: getGARTokenEndpoint,
  714. Handler: getGARTokenHandler,
  715. Router: r,
  716. })
  717. // GET /api/projects/{project_id}/registries/acr/token -> registry.NewRegistryGetACRTokenHandler
  718. getACRTokenEndpoint := factory.NewAPIEndpoint(
  719. &types.APIRequestMetadata{
  720. Verb: types.APIVerbGet,
  721. Method: types.HTTPVerbGet,
  722. Path: &types.Path{
  723. Parent: basePath,
  724. RelativePath: relPath + "/registries/acr/token",
  725. },
  726. Scopes: []types.PermissionScope{
  727. types.UserScope,
  728. types.ProjectScope,
  729. },
  730. },
  731. )
  732. getACRTokenHandler := registry.NewRegistryGetACRTokenHandler(
  733. config,
  734. factory.GetDecoderValidator(),
  735. factory.GetResultWriter(),
  736. )
  737. routes = append(routes, &router.Route{
  738. Endpoint: getACRTokenEndpoint,
  739. Handler: getACRTokenHandler,
  740. Router: r,
  741. })
  742. // GET /api/projects/{project_id}/registries/dockerhub/token -> registry.NewRegistryGetDockerhubTokenHandler
  743. getDockerhubTokenEndpoint := factory.NewAPIEndpoint(
  744. &types.APIRequestMetadata{
  745. Verb: types.APIVerbGet,
  746. Method: types.HTTPVerbGet,
  747. Path: &types.Path{
  748. Parent: basePath,
  749. RelativePath: relPath + "/registries/dockerhub/token",
  750. },
  751. Scopes: []types.PermissionScope{
  752. types.UserScope,
  753. types.ProjectScope,
  754. },
  755. },
  756. )
  757. getDockerhubTokenHandler := registry.NewRegistryGetDockerhubTokenHandler(
  758. config,
  759. factory.GetDecoderValidator(),
  760. factory.GetResultWriter(),
  761. )
  762. routes = append(routes, &router.Route{
  763. Endpoint: getDockerhubTokenEndpoint,
  764. Handler: getDockerhubTokenHandler,
  765. Router: r,
  766. })
  767. // POST /api/projects/{project_id}/infras -> infra.NewInfraCreateHandler
  768. createInfraEndpoint := factory.NewAPIEndpoint(
  769. &types.APIRequestMetadata{
  770. Verb: types.APIVerbCreate,
  771. Method: types.HTTPVerbPost,
  772. Path: &types.Path{
  773. Parent: basePath,
  774. RelativePath: relPath + "/infras",
  775. },
  776. Scopes: []types.PermissionScope{
  777. types.UserScope,
  778. types.ProjectScope,
  779. },
  780. },
  781. )
  782. createInfraHandler := infra.NewInfraCreateHandler(
  783. config,
  784. factory.GetDecoderValidator(),
  785. factory.GetResultWriter(),
  786. )
  787. routes = append(routes, &router.Route{
  788. Endpoint: createInfraEndpoint,
  789. Handler: createInfraHandler,
  790. Router: r,
  791. })
  792. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  793. getTemplatesEndpoint := factory.NewAPIEndpoint(
  794. &types.APIRequestMetadata{
  795. Verb: types.APIVerbGet,
  796. Method: types.HTTPVerbGet,
  797. Path: &types.Path{
  798. Parent: basePath,
  799. RelativePath: relPath + "/infras/templates",
  800. },
  801. Scopes: []types.PermissionScope{
  802. types.UserScope,
  803. types.ProjectScope,
  804. },
  805. },
  806. )
  807. getTemplatesHandler := infra.NewInfraListTemplateHandler(
  808. config,
  809. factory.GetResultWriter(),
  810. )
  811. routes = append(routes, &router.Route{
  812. Endpoint: getTemplatesEndpoint,
  813. Handler: getTemplatesHandler,
  814. Router: r,
  815. })
  816. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  817. getTemplateEndpoint := factory.NewAPIEndpoint(
  818. &types.APIRequestMetadata{
  819. Verb: types.APIVerbGet,
  820. Method: types.HTTPVerbGet,
  821. Path: &types.Path{
  822. Parent: basePath,
  823. RelativePath: fmt.Sprintf("%s/infras/templates/{%s}/{%s}", relPath, types.URLParamTemplateName, types.URLParamTemplateVersion),
  824. },
  825. Scopes: []types.PermissionScope{
  826. types.UserScope,
  827. types.ProjectScope,
  828. },
  829. },
  830. )
  831. getTemplateHandler := infra.NewInfraGetTemplateHandler(
  832. config,
  833. factory.GetResultWriter(),
  834. )
  835. routes = append(routes, &router.Route{
  836. Endpoint: getTemplateEndpoint,
  837. Handler: getTemplateHandler,
  838. Router: r,
  839. })
  840. // // POST /api/projects/{project_id}/provision/ecr -> provision.NewProvisionECRHandler
  841. // provisionECREndpoint := factory.NewAPIEndpoint(
  842. // &types.APIRequestMetadata{
  843. // Verb: types.APIVerbCreate,
  844. // Method: types.HTTPVerbPost,
  845. // Path: &types.Path{
  846. // Parent: basePath,
  847. // RelativePath: relPath + "/provision/ecr",
  848. // },
  849. // Scopes: []types.PermissionScope{
  850. // types.UserScope,
  851. // types.ProjectScope,
  852. // },
  853. // },
  854. // )
  855. // provisionECRHandler := provision.NewProvisionECRHandler(
  856. // config,
  857. // factory.GetDecoderValidator(),
  858. // factory.GetResultWriter(),
  859. // )
  860. // routes = append(routes, &router.Route{
  861. // Endpoint: provisionECREndpoint,
  862. // Handler: provisionECRHandler,
  863. // Router: r,
  864. // })
  865. // // POST /api/projects/{project_id}/provision/eks -> provision.NewProvisionEKSHandler
  866. // provisionEKSEndpoint := factory.NewAPIEndpoint(
  867. // &types.APIRequestMetadata{
  868. // Verb: types.APIVerbCreate,
  869. // Method: types.HTTPVerbPost,
  870. // Path: &types.Path{
  871. // Parent: basePath,
  872. // RelativePath: relPath + "/provision/eks",
  873. // },
  874. // Scopes: []types.PermissionScope{
  875. // types.UserScope,
  876. // types.ProjectScope,
  877. // },
  878. // CheckUsage: true,
  879. // UsageMetric: types.Clusters,
  880. // },
  881. // )
  882. // provisionEKSHandler := provision.NewProvisionEKSHandler(
  883. // config,
  884. // factory.GetDecoderValidator(),
  885. // factory.GetResultWriter(),
  886. // )
  887. // routes = append(routes, &router.Route{
  888. // Endpoint: provisionEKSEndpoint,
  889. // Handler: provisionEKSHandler,
  890. // Router: r,
  891. // })
  892. // // POST /api/projects/{project_id}/provision/docr -> provision.NewProvisionDOCRHandler
  893. // provisionDOCREndpoint := factory.NewAPIEndpoint(
  894. // &types.APIRequestMetadata{
  895. // Verb: types.APIVerbCreate,
  896. // Method: types.HTTPVerbPost,
  897. // Path: &types.Path{
  898. // Parent: basePath,
  899. // RelativePath: relPath + "/provision/docr",
  900. // },
  901. // Scopes: []types.PermissionScope{
  902. // types.UserScope,
  903. // types.ProjectScope,
  904. // },
  905. // },
  906. // )
  907. // provisionDOCRHandler := provision.NewProvisionDOCRHandler(
  908. // config,
  909. // factory.GetDecoderValidator(),
  910. // factory.GetResultWriter(),
  911. // )
  912. // routes = append(routes, &router.Route{
  913. // Endpoint: provisionDOCREndpoint,
  914. // Handler: provisionDOCRHandler,
  915. // Router: r,
  916. // })
  917. // // POST /api/projects/{project_id}/provision/doks -> provision.NewProvisionDOKSHandler
  918. // provisionDOKSEndpoint := factory.NewAPIEndpoint(
  919. // &types.APIRequestMetadata{
  920. // Verb: types.APIVerbCreate,
  921. // Method: types.HTTPVerbPost,
  922. // Path: &types.Path{
  923. // Parent: basePath,
  924. // RelativePath: relPath + "/provision/doks",
  925. // },
  926. // Scopes: []types.PermissionScope{
  927. // types.UserScope,
  928. // types.ProjectScope,
  929. // },
  930. // CheckUsage: true,
  931. // UsageMetric: types.Clusters,
  932. // },
  933. // )
  934. // provisionDOKSHandler := provision.NewProvisionDOKSHandler(
  935. // config,
  936. // factory.GetDecoderValidator(),
  937. // factory.GetResultWriter(),
  938. // )
  939. // routes = append(routes, &router.Route{
  940. // Endpoint: provisionDOKSEndpoint,
  941. // Handler: provisionDOKSHandler,
  942. // Router: r,
  943. // })
  944. // // POST /api/projects/{project_id}/provision/gcr -> provision.NewProvisionGCRHandler
  945. // provisionGCREndpoint := factory.NewAPIEndpoint(
  946. // &types.APIRequestMetadata{
  947. // Verb: types.APIVerbCreate,
  948. // Method: types.HTTPVerbPost,
  949. // Path: &types.Path{
  950. // Parent: basePath,
  951. // RelativePath: relPath + "/provision/gcr",
  952. // },
  953. // Scopes: []types.PermissionScope{
  954. // types.UserScope,
  955. // types.ProjectScope,
  956. // },
  957. // },
  958. // )
  959. // provisionGCRHandler := provision.NewProvisionGCRHandler(
  960. // config,
  961. // factory.GetDecoderValidator(),
  962. // factory.GetResultWriter(),
  963. // )
  964. // routes = append(routes, &router.Route{
  965. // Endpoint: provisionGCREndpoint,
  966. // Handler: provisionGCRHandler,
  967. // Router: r,
  968. // })
  969. // // POST /api/projects/{project_id}/provision/gke -> provision.NewProvisionGKEHandler
  970. // provisionGKEEndpoint := factory.NewAPIEndpoint(
  971. // &types.APIRequestMetadata{
  972. // Verb: types.APIVerbCreate,
  973. // Method: types.HTTPVerbPost,
  974. // Path: &types.Path{
  975. // Parent: basePath,
  976. // RelativePath: relPath + "/provision/gke",
  977. // },
  978. // Scopes: []types.PermissionScope{
  979. // types.UserScope,
  980. // types.ProjectScope,
  981. // },
  982. // CheckUsage: true,
  983. // UsageMetric: types.Clusters,
  984. // },
  985. // )
  986. // provisionGKEHandler := provision.NewProvisionGKEHandler(
  987. // config,
  988. // factory.GetDecoderValidator(),
  989. // factory.GetResultWriter(),
  990. // )
  991. // routes = append(routes, &router.Route{
  992. // Endpoint: provisionGKEEndpoint,
  993. // Handler: provisionGKEHandler,
  994. // Router: r,
  995. // })
  996. // POST /api/projects/{project_id}/policy -> policy.NewPolicyCreateHandler
  997. policyCreateEndpoint := factory.NewAPIEndpoint(
  998. &types.APIRequestMetadata{
  999. Verb: types.APIVerbCreate,
  1000. Method: types.HTTPVerbPost,
  1001. Path: &types.Path{
  1002. Parent: basePath,
  1003. RelativePath: relPath + "/policy",
  1004. },
  1005. Scopes: []types.PermissionScope{
  1006. types.UserScope,
  1007. types.ProjectScope,
  1008. types.SettingsScope,
  1009. },
  1010. },
  1011. )
  1012. policyCreateHandler := policy.NewPolicyCreateHandler(
  1013. config,
  1014. factory.GetDecoderValidator(),
  1015. factory.GetResultWriter(),
  1016. )
  1017. routes = append(routes, &router.Route{
  1018. Endpoint: policyCreateEndpoint,
  1019. Handler: policyCreateHandler,
  1020. Router: r,
  1021. })
  1022. // GET /api/projects/{project_id}/policies -> policy.NewPolicyListHandler
  1023. policyListEndpoint := factory.NewAPIEndpoint(
  1024. &types.APIRequestMetadata{
  1025. Verb: types.APIVerbList,
  1026. Method: types.HTTPVerbGet,
  1027. Path: &types.Path{
  1028. Parent: basePath,
  1029. RelativePath: relPath + "/policies",
  1030. },
  1031. Scopes: []types.PermissionScope{
  1032. types.UserScope,
  1033. types.ProjectScope,
  1034. types.SettingsScope,
  1035. },
  1036. },
  1037. )
  1038. policyListHandler := policy.NewPolicyListHandler(
  1039. config,
  1040. factory.GetDecoderValidator(),
  1041. factory.GetResultWriter(),
  1042. )
  1043. routes = append(routes, &router.Route{
  1044. Endpoint: policyListEndpoint,
  1045. Handler: policyListHandler,
  1046. Router: r,
  1047. })
  1048. // GET /api/projects/{project_id}/policy/{policy_id} -> policy.NewPolicyGetHandler
  1049. policyGetEndpoint := factory.NewAPIEndpoint(
  1050. &types.APIRequestMetadata{
  1051. Verb: types.APIVerbGet,
  1052. Method: types.HTTPVerbGet,
  1053. Path: &types.Path{
  1054. Parent: basePath,
  1055. RelativePath: fmt.Sprintf("%s/policy/{%s}", relPath, types.URLParamPolicyID),
  1056. },
  1057. Scopes: []types.PermissionScope{
  1058. types.UserScope,
  1059. types.ProjectScope,
  1060. types.SettingsScope,
  1061. },
  1062. },
  1063. )
  1064. policyGetHandler := policy.NewPolicyGetHandler(
  1065. config,
  1066. factory.GetDecoderValidator(),
  1067. factory.GetResultWriter(),
  1068. )
  1069. routes = append(routes, &router.Route{
  1070. Endpoint: policyGetEndpoint,
  1071. Handler: policyGetHandler,
  1072. Router: r,
  1073. })
  1074. // POST /api/projects/{project_id}/api_token -> api_token.NewAPITokenCreateHandler
  1075. apiTokenCreateEndpoint := factory.NewAPIEndpoint(
  1076. &types.APIRequestMetadata{
  1077. Verb: types.APIVerbCreate,
  1078. Method: types.HTTPVerbPost,
  1079. Path: &types.Path{
  1080. Parent: basePath,
  1081. RelativePath: relPath + "/api_token",
  1082. },
  1083. Scopes: []types.PermissionScope{
  1084. types.UserScope,
  1085. types.ProjectScope,
  1086. types.SettingsScope,
  1087. },
  1088. },
  1089. )
  1090. apiTokenCreateHandler := api_token.NewAPITokenCreateHandler(
  1091. config,
  1092. factory.GetDecoderValidator(),
  1093. factory.GetResultWriter(),
  1094. )
  1095. routes = append(routes, &router.Route{
  1096. Endpoint: apiTokenCreateEndpoint,
  1097. Handler: apiTokenCreateHandler,
  1098. Router: r,
  1099. })
  1100. // GET /api/projects/{project_id}/api_token -> api_token.NewAPITokenListHandler
  1101. apiTokenListEndpoint := factory.NewAPIEndpoint(
  1102. &types.APIRequestMetadata{
  1103. Verb: types.APIVerbList,
  1104. Method: types.HTTPVerbGet,
  1105. Path: &types.Path{
  1106. Parent: basePath,
  1107. RelativePath: fmt.Sprintf("%s/api_token", relPath),
  1108. },
  1109. Scopes: []types.PermissionScope{
  1110. types.UserScope,
  1111. types.ProjectScope,
  1112. types.SettingsScope,
  1113. },
  1114. },
  1115. )
  1116. apiTokenListHandler := api_token.NewAPITokenListHandler(
  1117. config,
  1118. factory.GetDecoderValidator(),
  1119. factory.GetResultWriter(),
  1120. )
  1121. routes = append(routes, &router.Route{
  1122. Endpoint: apiTokenListEndpoint,
  1123. Handler: apiTokenListHandler,
  1124. Router: r,
  1125. })
  1126. // GET /api/projects/{project_id}/api_token/{api_token_id} -> api_token.NewAPITokenGetHandler
  1127. apiTokenGetEndpoint := factory.NewAPIEndpoint(
  1128. &types.APIRequestMetadata{
  1129. Verb: types.APIVerbGet,
  1130. Method: types.HTTPVerbGet,
  1131. Path: &types.Path{
  1132. Parent: basePath,
  1133. RelativePath: fmt.Sprintf("%s/api_token/{%s}", relPath, types.URLParamTokenID),
  1134. },
  1135. Scopes: []types.PermissionScope{
  1136. types.UserScope,
  1137. types.ProjectScope,
  1138. types.SettingsScope,
  1139. },
  1140. },
  1141. )
  1142. apiTokenGetHandler := api_token.NewAPITokenGetHandler(
  1143. config,
  1144. factory.GetDecoderValidator(),
  1145. factory.GetResultWriter(),
  1146. )
  1147. routes = append(routes, &router.Route{
  1148. Endpoint: apiTokenGetEndpoint,
  1149. Handler: apiTokenGetHandler,
  1150. Router: r,
  1151. })
  1152. // POST /api/projects/{project_id}/api_token/{api_token_id}/revoke -> api_token.NewAPITokenRevokeHandler
  1153. apiTokenRevokeEndpoint := factory.NewAPIEndpoint(
  1154. &types.APIRequestMetadata{
  1155. Verb: types.APIVerbUpdate,
  1156. Method: types.HTTPVerbPost,
  1157. Path: &types.Path{
  1158. Parent: basePath,
  1159. RelativePath: fmt.Sprintf("%s/api_token/{%s}/revoke", relPath, types.URLParamTokenID),
  1160. },
  1161. Scopes: []types.PermissionScope{
  1162. types.UserScope,
  1163. types.ProjectScope,
  1164. types.SettingsScope,
  1165. },
  1166. },
  1167. )
  1168. apiTokenRevokeHandler := api_token.NewAPITokenRevokeHandler(
  1169. config,
  1170. factory.GetDecoderValidator(),
  1171. factory.GetResultWriter(),
  1172. )
  1173. routes = append(routes, &router.Route{
  1174. Endpoint: apiTokenRevokeEndpoint,
  1175. Handler: apiTokenRevokeHandler,
  1176. Router: r,
  1177. })
  1178. // POST /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoCreateHandler
  1179. hrCreateEndpoint := factory.NewAPIEndpoint(
  1180. &types.APIRequestMetadata{
  1181. Verb: types.APIVerbCreate,
  1182. Method: types.HTTPVerbPost,
  1183. Path: &types.Path{
  1184. Parent: basePath,
  1185. RelativePath: relPath + "/helmrepos",
  1186. },
  1187. Scopes: []types.PermissionScope{
  1188. types.UserScope,
  1189. types.ProjectScope,
  1190. },
  1191. },
  1192. )
  1193. hrCreateHandler := helmrepo.NewHelmRepoCreateHandler(
  1194. config,
  1195. factory.GetDecoderValidator(),
  1196. factory.GetResultWriter(),
  1197. )
  1198. routes = append(routes, &router.Route{
  1199. Endpoint: hrCreateEndpoint,
  1200. Handler: hrCreateHandler,
  1201. Router: r,
  1202. })
  1203. // GET /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoListHandler
  1204. hrListEndpoint := factory.NewAPIEndpoint(
  1205. &types.APIRequestMetadata{
  1206. Verb: types.APIVerbList,
  1207. Method: types.HTTPVerbGet,
  1208. Path: &types.Path{
  1209. Parent: basePath,
  1210. RelativePath: relPath + "/helmrepos",
  1211. },
  1212. Scopes: []types.PermissionScope{
  1213. types.UserScope,
  1214. types.ProjectScope,
  1215. },
  1216. },
  1217. )
  1218. hrListHandler := helmrepo.NewHelmRepoListHandler(
  1219. config,
  1220. factory.GetResultWriter(),
  1221. )
  1222. routes = append(routes, &router.Route{
  1223. Endpoint: hrListEndpoint,
  1224. Handler: hrListHandler,
  1225. Router: r,
  1226. })
  1227. // GET /api/projects/{project_id}/tags -> project.NewGetTagsHandler
  1228. getTagsEndpoint := factory.NewAPIEndpoint(
  1229. &types.APIRequestMetadata{
  1230. Verb: types.APIVerbGet,
  1231. Method: types.HTTPVerbGet,
  1232. Path: &types.Path{
  1233. Parent: basePath,
  1234. RelativePath: relPath + "/tags",
  1235. },
  1236. Scopes: []types.PermissionScope{
  1237. types.UserScope,
  1238. types.ProjectScope,
  1239. },
  1240. },
  1241. )
  1242. getTagsHandler := project.NewGetTagsHandler(
  1243. config,
  1244. factory.GetResultWriter(),
  1245. )
  1246. routes = append(routes, &router.Route{
  1247. Endpoint: getTagsEndpoint,
  1248. Handler: getTagsHandler,
  1249. Router: r,
  1250. })
  1251. // POST /api/projects/{project_id}/tags -> project.NewCreateTagHandler
  1252. createTagEndpoint := factory.NewAPIEndpoint(
  1253. &types.APIRequestMetadata{
  1254. Verb: types.APIVerbCreate,
  1255. Method: types.HTTPVerbPost,
  1256. Path: &types.Path{
  1257. Parent: basePath,
  1258. RelativePath: relPath + "/tags",
  1259. },
  1260. Scopes: []types.PermissionScope{
  1261. types.UserScope,
  1262. types.ProjectScope,
  1263. },
  1264. },
  1265. )
  1266. createTagHandler := project.NewCreateTagHandler(
  1267. config,
  1268. factory.GetDecoderValidator(),
  1269. factory.GetResultWriter(),
  1270. )
  1271. routes = append(routes, &router.Route{
  1272. Endpoint: createTagEndpoint,
  1273. Handler: createTagHandler,
  1274. Router: r,
  1275. })
  1276. // POST /api/projects/{project_id}/contract -> apiContract.NewAPIContractUpdateHandler
  1277. updateAPIContractEndpoint := factory.NewAPIEndpoint(
  1278. &types.APIRequestMetadata{
  1279. Verb: types.APIVerbCreate,
  1280. Method: types.HTTPVerbPost,
  1281. Path: &types.Path{
  1282. Parent: basePath,
  1283. RelativePath: relPath + "/contract",
  1284. },
  1285. Scopes: []types.PermissionScope{
  1286. types.UserScope,
  1287. types.ProjectScope,
  1288. },
  1289. },
  1290. )
  1291. updateAPIContractHandler := apiContract.NewAPIContractUpdateHandler(
  1292. config,
  1293. factory.GetDecoderValidator(),
  1294. factory.GetResultWriter(),
  1295. )
  1296. routes = append(routes, &router.Route{
  1297. Endpoint: updateAPIContractEndpoint,
  1298. Handler: updateAPIContractHandler,
  1299. Router: r,
  1300. })
  1301. // GET /api/projects/{project_id}/contracts -> apiContract.NewAPIContractRevisionListHandler
  1302. listAPIContractRevisionsEndpoint := factory.NewAPIEndpoint(
  1303. &types.APIRequestMetadata{
  1304. Verb: types.APIVerbGet,
  1305. Method: types.HTTPVerbGet,
  1306. Path: &types.Path{
  1307. Parent: basePath,
  1308. RelativePath: relPath + "/contracts",
  1309. },
  1310. Scopes: []types.PermissionScope{
  1311. types.UserScope,
  1312. types.ProjectScope,
  1313. },
  1314. },
  1315. )
  1316. listAPIContractRevisionHandler := apiContract.NewAPIContractRevisionListHandler(
  1317. config,
  1318. factory.GetDecoderValidator(),
  1319. factory.GetResultWriter(),
  1320. )
  1321. routes = append(routes, &router.Route{
  1322. Endpoint: listAPIContractRevisionsEndpoint,
  1323. Handler: listAPIContractRevisionHandler,
  1324. Router: r,
  1325. })
  1326. // DELETE /api/projects/{project_id}/contracts/{revision_id} -> apiContract.NewAPIContractUpdateHandler
  1327. deleteAPIContractRevisionsEndpoint := factory.NewAPIEndpoint(
  1328. &types.APIRequestMetadata{
  1329. Verb: types.APIVerbDelete,
  1330. Method: types.HTTPVerbDelete,
  1331. Path: &types.Path{
  1332. Parent: basePath,
  1333. RelativePath: fmt.Sprintf("%s/contracts/{%s}", relPath, types.URLParamAPIContractRevisionID),
  1334. },
  1335. Scopes: []types.PermissionScope{
  1336. types.UserScope,
  1337. types.ProjectScope,
  1338. types.APIContractRevisionScope,
  1339. },
  1340. },
  1341. )
  1342. deleteAPIContractRevisionHandler := apiContract.NewAPIContractRevisionDeleteHandler(
  1343. config,
  1344. factory.GetDecoderValidator(),
  1345. factory.GetResultWriter(),
  1346. )
  1347. routes = append(routes, &router.Route{
  1348. Endpoint: deleteAPIContractRevisionsEndpoint,
  1349. Handler: deleteAPIContractRevisionHandler,
  1350. Router: r,
  1351. })
  1352. // POST /api/projects/{project_id}/rename -> cluster.newRenamProject
  1353. renameProjectEndpoint := factory.NewAPIEndpoint(
  1354. &types.APIRequestMetadata{
  1355. Verb: types.APIVerbCreate,
  1356. Method: types.HTTPVerbPost,
  1357. Path: &types.Path{
  1358. Parent: basePath,
  1359. RelativePath: relPath + "/rename",
  1360. },
  1361. Scopes: []types.PermissionScope{
  1362. types.UserScope,
  1363. types.ProjectScope,
  1364. },
  1365. },
  1366. )
  1367. renameProjectHandler := project.NewRenameProjectHandler(
  1368. config,
  1369. factory.GetDecoderValidator(),
  1370. factory.GetResultWriter(),
  1371. )
  1372. routes = append(routes, &router.Route{
  1373. Endpoint: renameProjectEndpoint,
  1374. Handler: renameProjectHandler,
  1375. Router: r,
  1376. })
  1377. // GET /api/projects/{project_id}/images -> project.ImagesHandler
  1378. imagesEndpoint := factory.NewAPIEndpoint(
  1379. &types.APIRequestMetadata{
  1380. Verb: types.APIVerbList,
  1381. Method: types.HTTPVerbGet,
  1382. Path: &types.Path{
  1383. Parent: basePath,
  1384. RelativePath: relPath + "/images",
  1385. },
  1386. Scopes: []types.PermissionScope{
  1387. types.UserScope,
  1388. types.ProjectScope,
  1389. },
  1390. },
  1391. )
  1392. imagesHandler := project.NewImagesHandler(
  1393. config,
  1394. factory.GetResultWriter(),
  1395. )
  1396. routes = append(routes, &router.Route{
  1397. Endpoint: imagesEndpoint,
  1398. Handler: imagesHandler,
  1399. Router: r,
  1400. })
  1401. return routes, newPath
  1402. }