project.go 46 KB

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