project.go 41 KB

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