project.go 48 KB

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