project.go 50 KB

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