project.go 49 KB

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