project.go 42 KB

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