project.go 45 KB

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