project.go 39 KB

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