project.go 47 KB

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