project.go 39 KB

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