project.go 42 KB

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