2
0

project.go 46 KB

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