project.go 45 KB

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