project.go 45 KB

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