project.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  1. package router
  2. import (
  3. "fmt"
  4. "github.com/go-chi/chi"
  5. "github.com/porter-dev/porter/api/server/handlers/api_token"
  6. "github.com/porter-dev/porter/api/server/handlers/billing"
  7. "github.com/porter-dev/porter/api/server/handlers/cluster"
  8. "github.com/porter-dev/porter/api/server/handlers/gitinstallation"
  9. "github.com/porter-dev/porter/api/server/handlers/helmrepo"
  10. "github.com/porter-dev/porter/api/server/handlers/infra"
  11. "github.com/porter-dev/porter/api/server/handlers/policy"
  12. "github.com/porter-dev/porter/api/server/handlers/project"
  13. "github.com/porter-dev/porter/api/server/handlers/registry"
  14. "github.com/porter-dev/porter/api/server/shared"
  15. "github.com/porter-dev/porter/api/server/shared/config"
  16. "github.com/porter-dev/porter/api/types"
  17. )
  18. func NewProjectScopedRegisterer(children ...*Registerer) *Registerer {
  19. return &Registerer{
  20. GetRoutes: GetProjectScopedRoutes,
  21. Children: children,
  22. }
  23. }
  24. func GetProjectScopedRoutes(
  25. r chi.Router,
  26. config *config.Config,
  27. basePath *types.Path,
  28. factory shared.APIEndpointFactory,
  29. children ...*Registerer,
  30. ) []*Route {
  31. routes, projPath := getProjectRoutes(r, config, basePath, factory)
  32. if len(children) > 0 {
  33. r.Route(projPath.RelativePath, func(r chi.Router) {
  34. for _, child := range children {
  35. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  36. routes = append(routes, childRoutes...)
  37. }
  38. })
  39. }
  40. return routes
  41. }
  42. func getProjectRoutes(
  43. r chi.Router,
  44. config *config.Config,
  45. basePath *types.Path,
  46. factory shared.APIEndpointFactory,
  47. ) ([]*Route, *types.Path) {
  48. relPath := "/projects/{project_id}"
  49. newPath := &types.Path{
  50. Parent: basePath,
  51. RelativePath: relPath,
  52. }
  53. routes := make([]*Route, 0)
  54. // GET /api/projects/{project_id} -> project.NewProjectGetHandler
  55. getEndpoint := factory.NewAPIEndpoint(
  56. &types.APIRequestMetadata{
  57. Verb: types.APIVerbGet,
  58. Method: types.HTTPVerbGet,
  59. Path: &types.Path{
  60. Parent: basePath,
  61. RelativePath: relPath,
  62. },
  63. Scopes: []types.PermissionScope{
  64. types.UserScope,
  65. types.ProjectScope,
  66. },
  67. },
  68. )
  69. getHandler := project.NewProjectGetHandler(
  70. config,
  71. factory.GetResultWriter(),
  72. )
  73. routes = append(routes, &Route{
  74. Endpoint: getEndpoint,
  75. Handler: getHandler,
  76. Router: r,
  77. })
  78. // DELETE /api/projects/{project_id} -> project.NewProjectDeleteHandler
  79. deleteEndpoint := factory.NewAPIEndpoint(
  80. &types.APIRequestMetadata{
  81. Verb: types.APIVerbDelete,
  82. Method: types.HTTPVerbDelete,
  83. Path: &types.Path{
  84. Parent: basePath,
  85. RelativePath: relPath,
  86. },
  87. Scopes: []types.PermissionScope{
  88. types.UserScope,
  89. types.ProjectScope,
  90. },
  91. },
  92. )
  93. deleteHandler := project.NewProjectDeleteHandler(
  94. config,
  95. factory.GetResultWriter(),
  96. )
  97. routes = append(routes, &Route{
  98. Endpoint: deleteEndpoint,
  99. Handler: deleteHandler,
  100. Router: r,
  101. })
  102. // GET /api/projects/{project_id}/policy -> project.NewProjectGetPolicyHandler
  103. getPolicyEndpoint := factory.NewAPIEndpoint(
  104. &types.APIRequestMetadata{
  105. Verb: types.APIVerbGet,
  106. Method: types.HTTPVerbGet,
  107. Path: &types.Path{
  108. Parent: basePath,
  109. RelativePath: relPath + "/policy",
  110. },
  111. Scopes: []types.PermissionScope{
  112. types.UserScope,
  113. types.ProjectScope,
  114. },
  115. },
  116. )
  117. getPolicyHandler := project.NewProjectGetPolicyHandler(
  118. config,
  119. factory.GetResultWriter(),
  120. )
  121. routes = append(routes, &Route{
  122. Endpoint: getPolicyEndpoint,
  123. Handler: getPolicyHandler,
  124. Router: r,
  125. })
  126. // GET /api/projects/{project_id}/onboarding -> project.NewProjectGetOnboardingHandler
  127. getOnboardingEndpoint := factory.NewAPIEndpoint(
  128. &types.APIRequestMetadata{
  129. Verb: types.APIVerbGet,
  130. Method: types.HTTPVerbGet,
  131. Path: &types.Path{
  132. Parent: basePath,
  133. RelativePath: relPath + "/onboarding",
  134. },
  135. Scopes: []types.PermissionScope{
  136. types.UserScope,
  137. types.ProjectScope,
  138. },
  139. },
  140. )
  141. getOnboardingHandler := project.NewOnboardingGetHandler(
  142. config,
  143. factory.GetDecoderValidator(),
  144. factory.GetResultWriter(),
  145. )
  146. routes = append(routes, &Route{
  147. Endpoint: getOnboardingEndpoint,
  148. Handler: getOnboardingHandler,
  149. Router: r,
  150. })
  151. // POST /api/projects/{project_id}/onboarding -> project.NewProjectGetOnboardingHandler
  152. updateOnboardingEndpoint := factory.NewAPIEndpoint(
  153. &types.APIRequestMetadata{
  154. Verb: types.APIVerbUpdate,
  155. Method: types.HTTPVerbPost,
  156. Path: &types.Path{
  157. Parent: basePath,
  158. RelativePath: relPath + "/onboarding",
  159. },
  160. Scopes: []types.PermissionScope{
  161. types.UserScope,
  162. types.ProjectScope,
  163. },
  164. },
  165. )
  166. updateOnboardingHandler := project.NewOnboardingUpdateHandler(
  167. config,
  168. factory.GetDecoderValidator(),
  169. factory.GetResultWriter(),
  170. )
  171. routes = append(routes, &Route{
  172. Endpoint: updateOnboardingEndpoint,
  173. Handler: updateOnboardingHandler,
  174. Router: r,
  175. })
  176. // GET /api/projects/{project_id}/usage -> project.NewProjectGetUsageHandler
  177. getUsageEndpoint := factory.NewAPIEndpoint(
  178. &types.APIRequestMetadata{
  179. Verb: types.APIVerbGet,
  180. Method: types.HTTPVerbGet,
  181. Path: &types.Path{
  182. Parent: basePath,
  183. RelativePath: relPath + "/usage",
  184. },
  185. Scopes: []types.PermissionScope{
  186. types.UserScope,
  187. types.ProjectScope,
  188. },
  189. },
  190. )
  191. getUsageHandler := project.NewProjectGetUsageHandler(
  192. config,
  193. factory.GetResultWriter(),
  194. )
  195. routes = append(routes, &Route{
  196. Endpoint: getUsageEndpoint,
  197. Handler: getUsageHandler,
  198. Router: r,
  199. })
  200. // GET /api/projects/{project_id}/billing -> project.NewProjectGetBillingHandler
  201. getBillingEndpoint := factory.NewAPIEndpoint(
  202. &types.APIRequestMetadata{
  203. Verb: types.APIVerbGet,
  204. Method: types.HTTPVerbGet,
  205. Path: &types.Path{
  206. Parent: basePath,
  207. RelativePath: relPath + "/billing",
  208. },
  209. Scopes: []types.PermissionScope{
  210. types.UserScope,
  211. types.ProjectScope,
  212. },
  213. },
  214. )
  215. getBillingHandler := project.NewProjectGetBillingHandler(
  216. config,
  217. factory.GetResultWriter(),
  218. )
  219. routes = append(routes, &Route{
  220. Endpoint: getBillingEndpoint,
  221. Handler: getBillingHandler,
  222. Router: r,
  223. })
  224. // GET /api/projects/{project_id}/billing/token -> billing.NewBillingGetTokenEndpoint
  225. getBillingTokenEndpoint := factory.NewAPIEndpoint(
  226. &types.APIRequestMetadata{
  227. Verb: types.APIVerbGet,
  228. Method: types.HTTPVerbGet,
  229. Path: &types.Path{
  230. Parent: basePath,
  231. RelativePath: relPath + "/billing/token",
  232. },
  233. Scopes: []types.PermissionScope{
  234. types.UserScope,
  235. types.ProjectScope,
  236. types.SettingsScope,
  237. },
  238. },
  239. )
  240. getBillingTokenHandler := billing.NewBillingGetTokenHandler(
  241. config,
  242. factory.GetDecoderValidator(),
  243. factory.GetResultWriter(),
  244. )
  245. routes = append(routes, &Route{
  246. Endpoint: getBillingTokenEndpoint,
  247. Handler: getBillingTokenHandler,
  248. Router: r,
  249. })
  250. // GET /api/billing_webhook -> billing.NewBillingWebhookHandler
  251. getBillingWebhookEndpoint := factory.NewAPIEndpoint(
  252. &types.APIRequestMetadata{
  253. Verb: types.APIVerbCreate,
  254. Method: types.HTTPVerbPost,
  255. Path: &types.Path{
  256. Parent: basePath,
  257. RelativePath: "/billing_webhook",
  258. },
  259. Scopes: []types.PermissionScope{},
  260. },
  261. )
  262. getBillingWebhookHandler := billing.NewBillingWebhookHandler(
  263. config,
  264. factory.GetDecoderValidator(),
  265. )
  266. routes = append(routes, &Route{
  267. Endpoint: getBillingWebhookEndpoint,
  268. Handler: getBillingWebhookHandler,
  269. Router: r,
  270. })
  271. // GET /api/projects/{project_id}/clusters -> cluster.NewClusterListHandler
  272. listClusterEndpoint := factory.NewAPIEndpoint(
  273. &types.APIRequestMetadata{
  274. Verb: types.APIVerbList,
  275. Method: types.HTTPVerbGet,
  276. Path: &types.Path{
  277. Parent: basePath,
  278. RelativePath: relPath + "/clusters",
  279. },
  280. Scopes: []types.PermissionScope{
  281. types.UserScope,
  282. types.ProjectScope,
  283. },
  284. },
  285. )
  286. listClusterHandler := cluster.NewClusterListHandler(
  287. config,
  288. factory.GetResultWriter(),
  289. )
  290. routes = append(routes, &Route{
  291. Endpoint: listClusterEndpoint,
  292. Handler: listClusterHandler,
  293. Router: r,
  294. })
  295. // GET /api/projects/{project_id}/gitrepos -> gitinstallation.NewGitRepoListHandler
  296. listGitReposEndpoint := factory.NewAPIEndpoint(
  297. &types.APIRequestMetadata{
  298. Verb: types.APIVerbList,
  299. Method: types.HTTPVerbGet,
  300. Path: &types.Path{
  301. Parent: basePath,
  302. RelativePath: relPath + "/gitrepos",
  303. },
  304. Scopes: []types.PermissionScope{
  305. types.UserScope,
  306. types.ProjectScope,
  307. },
  308. },
  309. )
  310. listGitReposHandler := gitinstallation.NewGitRepoListHandler(
  311. config,
  312. factory.GetResultWriter(),
  313. )
  314. routes = append(routes, &Route{
  315. Endpoint: listGitReposEndpoint,
  316. Handler: listGitReposHandler,
  317. Router: r,
  318. })
  319. // GET /api/projects/{project_id}/collaborators -> project.NewCollaboratorsListHandler
  320. listCollaboratorsEndpoint := factory.NewAPIEndpoint(
  321. &types.APIRequestMetadata{
  322. Verb: types.APIVerbList,
  323. Method: types.HTTPVerbGet,
  324. Path: &types.Path{
  325. Parent: basePath,
  326. RelativePath: relPath + "/collaborators",
  327. },
  328. Scopes: []types.PermissionScope{
  329. types.UserScope,
  330. types.ProjectScope,
  331. },
  332. },
  333. )
  334. listCollaboratorsHandler := project.NewCollaboratorsListHandler(
  335. config,
  336. factory.GetResultWriter(),
  337. )
  338. routes = append(routes, &Route{
  339. Endpoint: listCollaboratorsEndpoint,
  340. Handler: listCollaboratorsHandler,
  341. Router: r,
  342. })
  343. // GET /api/projects/{project_id}/roles -> project.NewRolesListHandler
  344. listRolesEndpoint := factory.NewAPIEndpoint(
  345. &types.APIRequestMetadata{
  346. Verb: types.APIVerbList,
  347. Method: types.HTTPVerbGet,
  348. Path: &types.Path{
  349. Parent: basePath,
  350. RelativePath: relPath + "/roles",
  351. },
  352. Scopes: []types.PermissionScope{
  353. types.UserScope,
  354. types.ProjectScope,
  355. },
  356. },
  357. )
  358. listRolesHandler := project.NewRolesListHandler(
  359. config,
  360. factory.GetResultWriter(),
  361. )
  362. routes = append(routes, &Route{
  363. Endpoint: listRolesEndpoint,
  364. Handler: listRolesHandler,
  365. Router: r,
  366. })
  367. // POST /api/projects/{project_id}/roles -> project.NewRoleUpdateHandler
  368. updateRoleEndpoint := factory.NewAPIEndpoint(
  369. &types.APIRequestMetadata{
  370. Verb: types.APIVerbUpdate,
  371. Method: types.HTTPVerbPost,
  372. Path: &types.Path{
  373. Parent: basePath,
  374. RelativePath: relPath + "/roles",
  375. },
  376. Scopes: []types.PermissionScope{
  377. types.UserScope,
  378. types.ProjectScope,
  379. },
  380. },
  381. )
  382. updateRoleHandler := project.NewRoleUpdateHandler(
  383. config,
  384. factory.GetDecoderValidator(),
  385. factory.GetResultWriter(),
  386. )
  387. routes = append(routes, &Route{
  388. Endpoint: updateRoleEndpoint,
  389. Handler: updateRoleHandler,
  390. Router: r,
  391. })
  392. // DELETE /api/projects/{project_id}/roles -> project.NewRoleDeleteHandler
  393. deleteRoleEndpoint := factory.NewAPIEndpoint(
  394. &types.APIRequestMetadata{
  395. Verb: types.APIVerbDelete,
  396. Method: types.HTTPVerbDelete,
  397. Path: &types.Path{
  398. Parent: basePath,
  399. RelativePath: relPath + "/roles",
  400. },
  401. Scopes: []types.PermissionScope{
  402. types.UserScope,
  403. types.ProjectScope,
  404. },
  405. },
  406. )
  407. deleteRoleHandler := project.NewRoleDeleteHandler(
  408. config,
  409. factory.GetDecoderValidator(),
  410. factory.GetResultWriter(),
  411. )
  412. routes = append(routes, &Route{
  413. Endpoint: deleteRoleEndpoint,
  414. Handler: deleteRoleHandler,
  415. Router: r,
  416. })
  417. // GET /api/projects/{project_id}/registries -> registry.NewRegistryListHandler
  418. listRegistriesEndpoint := factory.NewAPIEndpoint(
  419. &types.APIRequestMetadata{
  420. Verb: types.APIVerbList,
  421. Method: types.HTTPVerbGet,
  422. Path: &types.Path{
  423. Parent: basePath,
  424. RelativePath: relPath + "/registries",
  425. },
  426. Scopes: []types.PermissionScope{
  427. types.UserScope,
  428. types.ProjectScope,
  429. },
  430. },
  431. )
  432. listRegistriesHandler := registry.NewRegistryListHandler(
  433. config,
  434. factory.GetResultWriter(),
  435. )
  436. routes = append(routes, &Route{
  437. Endpoint: listRegistriesEndpoint,
  438. Handler: listRegistriesHandler,
  439. Router: r,
  440. })
  441. // POST /api/projects/{project_id}/registries -> registry.NewRegistryCreateHandler
  442. createRegistryEndpoint := factory.NewAPIEndpoint(
  443. &types.APIRequestMetadata{
  444. Verb: types.APIVerbCreate,
  445. Method: types.HTTPVerbPost,
  446. Path: &types.Path{
  447. Parent: basePath,
  448. RelativePath: relPath + "/registries",
  449. },
  450. Scopes: []types.PermissionScope{
  451. types.UserScope,
  452. types.ProjectScope,
  453. },
  454. },
  455. )
  456. createRegistryHandler := registry.NewRegistryCreateHandler(
  457. config,
  458. factory.GetDecoderValidator(),
  459. factory.GetResultWriter(),
  460. )
  461. routes = append(routes, &Route{
  462. Endpoint: createRegistryEndpoint,
  463. Handler: createRegistryHandler,
  464. Router: r,
  465. })
  466. // GET /api/projects/{project_id}/registries/ecr/token -> registry.NewRegistryGetECRTokenHandler
  467. getECRTokenEndpoint := factory.NewAPIEndpoint(
  468. &types.APIRequestMetadata{
  469. Verb: types.APIVerbGet,
  470. Method: types.HTTPVerbGet,
  471. Path: &types.Path{
  472. Parent: basePath,
  473. RelativePath: relPath + "/registries/ecr/token",
  474. },
  475. Scopes: []types.PermissionScope{
  476. types.UserScope,
  477. types.ProjectScope,
  478. },
  479. },
  480. )
  481. getECRTokenHandler := registry.NewRegistryGetECRTokenHandler(
  482. config,
  483. factory.GetDecoderValidator(),
  484. factory.GetResultWriter(),
  485. )
  486. routes = append(routes, &Route{
  487. Endpoint: getECRTokenEndpoint,
  488. Handler: getECRTokenHandler,
  489. Router: r,
  490. })
  491. // GET /api/projects/{project_id}/registries/docr/token -> registry.NewRegistryGetDOCRTokenHandler
  492. getDOCRTokenEndpoint := factory.NewAPIEndpoint(
  493. &types.APIRequestMetadata{
  494. Verb: types.APIVerbGet,
  495. Method: types.HTTPVerbGet,
  496. Path: &types.Path{
  497. Parent: basePath,
  498. RelativePath: relPath + "/registries/docr/token",
  499. },
  500. Scopes: []types.PermissionScope{
  501. types.UserScope,
  502. types.ProjectScope,
  503. },
  504. },
  505. )
  506. getDOCRTokenHandler := registry.NewRegistryGetDOCRTokenHandler(
  507. config,
  508. factory.GetDecoderValidator(),
  509. factory.GetResultWriter(),
  510. )
  511. routes = append(routes, &Route{
  512. Endpoint: getDOCRTokenEndpoint,
  513. Handler: getDOCRTokenHandler,
  514. Router: r,
  515. })
  516. // GET /api/projects/{project_id}/registries/gcr/token -> registry.NewRegistryGetGCRTokenHandler
  517. getGCRTokenEndpoint := factory.NewAPIEndpoint(
  518. &types.APIRequestMetadata{
  519. Verb: types.APIVerbGet,
  520. Method: types.HTTPVerbGet,
  521. Path: &types.Path{
  522. Parent: basePath,
  523. RelativePath: relPath + "/registries/gcr/token",
  524. },
  525. Scopes: []types.PermissionScope{
  526. types.UserScope,
  527. types.ProjectScope,
  528. },
  529. },
  530. )
  531. getGCRTokenHandler := registry.NewRegistryGetGCRTokenHandler(
  532. config,
  533. factory.GetDecoderValidator(),
  534. factory.GetResultWriter(),
  535. )
  536. routes = append(routes, &Route{
  537. Endpoint: getGCRTokenEndpoint,
  538. Handler: getGCRTokenHandler,
  539. Router: r,
  540. })
  541. // GET /api/projects/{project_id}/registries/dockerhub/token -> registry.NewRegistryGetDockerhubTokenHandler
  542. getDockerhubTokenEndpoint := factory.NewAPIEndpoint(
  543. &types.APIRequestMetadata{
  544. Verb: types.APIVerbGet,
  545. Method: types.HTTPVerbGet,
  546. Path: &types.Path{
  547. Parent: basePath,
  548. RelativePath: relPath + "/registries/dockerhub/token",
  549. },
  550. Scopes: []types.PermissionScope{
  551. types.UserScope,
  552. types.ProjectScope,
  553. },
  554. },
  555. )
  556. getDockerhubTokenHandler := registry.NewRegistryGetDockerhubTokenHandler(
  557. config,
  558. factory.GetDecoderValidator(),
  559. factory.GetResultWriter(),
  560. )
  561. routes = append(routes, &Route{
  562. Endpoint: getDockerhubTokenEndpoint,
  563. Handler: getDockerhubTokenHandler,
  564. Router: r,
  565. })
  566. // POST /api/projects/{project_id}/infras -> infra.NewInfraCreateHandler
  567. createInfraEndpoint := factory.NewAPIEndpoint(
  568. &types.APIRequestMetadata{
  569. Verb: types.APIVerbCreate,
  570. Method: types.HTTPVerbPost,
  571. Path: &types.Path{
  572. Parent: basePath,
  573. RelativePath: relPath + "/infras",
  574. },
  575. Scopes: []types.PermissionScope{
  576. types.UserScope,
  577. types.ProjectScope,
  578. },
  579. },
  580. )
  581. createInfraHandler := infra.NewInfraCreateHandler(
  582. config,
  583. factory.GetDecoderValidator(),
  584. factory.GetResultWriter(),
  585. )
  586. routes = append(routes, &Route{
  587. Endpoint: createInfraEndpoint,
  588. Handler: createInfraHandler,
  589. Router: r,
  590. })
  591. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  592. getTemplatesEndpoint := factory.NewAPIEndpoint(
  593. &types.APIRequestMetadata{
  594. Verb: types.APIVerbGet,
  595. Method: types.HTTPVerbGet,
  596. Path: &types.Path{
  597. Parent: basePath,
  598. RelativePath: relPath + "/infras/templates",
  599. },
  600. Scopes: []types.PermissionScope{
  601. types.UserScope,
  602. types.ProjectScope,
  603. },
  604. },
  605. )
  606. getTemplatesHandler := infra.NewInfraListTemplateHandler(
  607. config,
  608. factory.GetResultWriter(),
  609. )
  610. routes = append(routes, &Route{
  611. Endpoint: getTemplatesEndpoint,
  612. Handler: getTemplatesHandler,
  613. Router: r,
  614. })
  615. // GET /api/projects/{project_id}/infras/templates -> infra.NewInfraGetHandler
  616. getTemplateEndpoint := factory.NewAPIEndpoint(
  617. &types.APIRequestMetadata{
  618. Verb: types.APIVerbGet,
  619. Method: types.HTTPVerbGet,
  620. Path: &types.Path{
  621. Parent: basePath,
  622. RelativePath: fmt.Sprintf("%s/infras/templates/{%s}/{%s}", relPath, types.URLParamTemplateName, types.URLParamTemplateVersion),
  623. },
  624. Scopes: []types.PermissionScope{
  625. types.UserScope,
  626. types.ProjectScope,
  627. },
  628. },
  629. )
  630. getTemplateHandler := infra.NewInfraGetTemplateHandler(
  631. config,
  632. factory.GetResultWriter(),
  633. )
  634. routes = append(routes, &Route{
  635. Endpoint: getTemplateEndpoint,
  636. Handler: getTemplateHandler,
  637. Router: r,
  638. })
  639. // // POST /api/projects/{project_id}/provision/ecr -> provision.NewProvisionECRHandler
  640. // provisionECREndpoint := factory.NewAPIEndpoint(
  641. // &types.APIRequestMetadata{
  642. // Verb: types.APIVerbCreate,
  643. // Method: types.HTTPVerbPost,
  644. // Path: &types.Path{
  645. // Parent: basePath,
  646. // RelativePath: relPath + "/provision/ecr",
  647. // },
  648. // Scopes: []types.PermissionScope{
  649. // types.UserScope,
  650. // types.ProjectScope,
  651. // },
  652. // },
  653. // )
  654. // provisionECRHandler := provision.NewProvisionECRHandler(
  655. // config,
  656. // factory.GetDecoderValidator(),
  657. // factory.GetResultWriter(),
  658. // )
  659. // routes = append(routes, &Route{
  660. // Endpoint: provisionECREndpoint,
  661. // Handler: provisionECRHandler,
  662. // Router: r,
  663. // })
  664. // // POST /api/projects/{project_id}/provision/eks -> provision.NewProvisionEKSHandler
  665. // provisionEKSEndpoint := factory.NewAPIEndpoint(
  666. // &types.APIRequestMetadata{
  667. // Verb: types.APIVerbCreate,
  668. // Method: types.HTTPVerbPost,
  669. // Path: &types.Path{
  670. // Parent: basePath,
  671. // RelativePath: relPath + "/provision/eks",
  672. // },
  673. // Scopes: []types.PermissionScope{
  674. // types.UserScope,
  675. // types.ProjectScope,
  676. // },
  677. // CheckUsage: true,
  678. // UsageMetric: types.Clusters,
  679. // },
  680. // )
  681. // provisionEKSHandler := provision.NewProvisionEKSHandler(
  682. // config,
  683. // factory.GetDecoderValidator(),
  684. // factory.GetResultWriter(),
  685. // )
  686. // routes = append(routes, &Route{
  687. // Endpoint: provisionEKSEndpoint,
  688. // Handler: provisionEKSHandler,
  689. // Router: r,
  690. // })
  691. // // POST /api/projects/{project_id}/provision/docr -> provision.NewProvisionDOCRHandler
  692. // provisionDOCREndpoint := factory.NewAPIEndpoint(
  693. // &types.APIRequestMetadata{
  694. // Verb: types.APIVerbCreate,
  695. // Method: types.HTTPVerbPost,
  696. // Path: &types.Path{
  697. // Parent: basePath,
  698. // RelativePath: relPath + "/provision/docr",
  699. // },
  700. // Scopes: []types.PermissionScope{
  701. // types.UserScope,
  702. // types.ProjectScope,
  703. // },
  704. // },
  705. // )
  706. // provisionDOCRHandler := provision.NewProvisionDOCRHandler(
  707. // config,
  708. // factory.GetDecoderValidator(),
  709. // factory.GetResultWriter(),
  710. // )
  711. // routes = append(routes, &Route{
  712. // Endpoint: provisionDOCREndpoint,
  713. // Handler: provisionDOCRHandler,
  714. // Router: r,
  715. // })
  716. // // POST /api/projects/{project_id}/provision/doks -> provision.NewProvisionDOKSHandler
  717. // provisionDOKSEndpoint := factory.NewAPIEndpoint(
  718. // &types.APIRequestMetadata{
  719. // Verb: types.APIVerbCreate,
  720. // Method: types.HTTPVerbPost,
  721. // Path: &types.Path{
  722. // Parent: basePath,
  723. // RelativePath: relPath + "/provision/doks",
  724. // },
  725. // Scopes: []types.PermissionScope{
  726. // types.UserScope,
  727. // types.ProjectScope,
  728. // },
  729. // CheckUsage: true,
  730. // UsageMetric: types.Clusters,
  731. // },
  732. // )
  733. // provisionDOKSHandler := provision.NewProvisionDOKSHandler(
  734. // config,
  735. // factory.GetDecoderValidator(),
  736. // factory.GetResultWriter(),
  737. // )
  738. // routes = append(routes, &Route{
  739. // Endpoint: provisionDOKSEndpoint,
  740. // Handler: provisionDOKSHandler,
  741. // Router: r,
  742. // })
  743. // // POST /api/projects/{project_id}/provision/gcr -> provision.NewProvisionGCRHandler
  744. // provisionGCREndpoint := factory.NewAPIEndpoint(
  745. // &types.APIRequestMetadata{
  746. // Verb: types.APIVerbCreate,
  747. // Method: types.HTTPVerbPost,
  748. // Path: &types.Path{
  749. // Parent: basePath,
  750. // RelativePath: relPath + "/provision/gcr",
  751. // },
  752. // Scopes: []types.PermissionScope{
  753. // types.UserScope,
  754. // types.ProjectScope,
  755. // },
  756. // },
  757. // )
  758. // provisionGCRHandler := provision.NewProvisionGCRHandler(
  759. // config,
  760. // factory.GetDecoderValidator(),
  761. // factory.GetResultWriter(),
  762. // )
  763. // routes = append(routes, &Route{
  764. // Endpoint: provisionGCREndpoint,
  765. // Handler: provisionGCRHandler,
  766. // Router: r,
  767. // })
  768. // // POST /api/projects/{project_id}/provision/gke -> provision.NewProvisionGKEHandler
  769. // provisionGKEEndpoint := factory.NewAPIEndpoint(
  770. // &types.APIRequestMetadata{
  771. // Verb: types.APIVerbCreate,
  772. // Method: types.HTTPVerbPost,
  773. // Path: &types.Path{
  774. // Parent: basePath,
  775. // RelativePath: relPath + "/provision/gke",
  776. // },
  777. // Scopes: []types.PermissionScope{
  778. // types.UserScope,
  779. // types.ProjectScope,
  780. // },
  781. // CheckUsage: true,
  782. // UsageMetric: types.Clusters,
  783. // },
  784. // )
  785. // provisionGKEHandler := provision.NewProvisionGKEHandler(
  786. // config,
  787. // factory.GetDecoderValidator(),
  788. // factory.GetResultWriter(),
  789. // )
  790. // routes = append(routes, &Route{
  791. // Endpoint: provisionGKEEndpoint,
  792. // Handler: provisionGKEHandler,
  793. // Router: r,
  794. // })
  795. // POST /api/projects/{project_id}/policy -> policy.NewPolicyCreateHandler
  796. policyCreateEndpoint := factory.NewAPIEndpoint(
  797. &types.APIRequestMetadata{
  798. Verb: types.APIVerbCreate,
  799. Method: types.HTTPVerbPost,
  800. Path: &types.Path{
  801. Parent: basePath,
  802. RelativePath: relPath + "/policy",
  803. },
  804. Scopes: []types.PermissionScope{
  805. types.UserScope,
  806. types.ProjectScope,
  807. types.SettingsScope,
  808. },
  809. },
  810. )
  811. policyCreateHandler := policy.NewPolicyCreateHandler(
  812. config,
  813. factory.GetDecoderValidator(),
  814. factory.GetResultWriter(),
  815. )
  816. routes = append(routes, &Route{
  817. Endpoint: policyCreateEndpoint,
  818. Handler: policyCreateHandler,
  819. Router: r,
  820. })
  821. // GET /api/projects/{project_id}/policies -> policy.NewPolicyListHandler
  822. policyListEndpoint := factory.NewAPIEndpoint(
  823. &types.APIRequestMetadata{
  824. Verb: types.APIVerbList,
  825. Method: types.HTTPVerbGet,
  826. Path: &types.Path{
  827. Parent: basePath,
  828. RelativePath: relPath + "/policies",
  829. },
  830. Scopes: []types.PermissionScope{
  831. types.UserScope,
  832. types.ProjectScope,
  833. types.SettingsScope,
  834. },
  835. },
  836. )
  837. policyListHandler := policy.NewPolicyListHandler(
  838. config,
  839. factory.GetDecoderValidator(),
  840. factory.GetResultWriter(),
  841. )
  842. routes = append(routes, &Route{
  843. Endpoint: policyListEndpoint,
  844. Handler: policyListHandler,
  845. Router: r,
  846. })
  847. // GET /api/projects/{project_id}/policy/{policy_id} -> policy.NewPolicyGetHandler
  848. policyGetEndpoint := factory.NewAPIEndpoint(
  849. &types.APIRequestMetadata{
  850. Verb: types.APIVerbGet,
  851. Method: types.HTTPVerbGet,
  852. Path: &types.Path{
  853. Parent: basePath,
  854. RelativePath: fmt.Sprintf("%s/policy/{%s}", relPath, types.URLParamPolicyID),
  855. },
  856. Scopes: []types.PermissionScope{
  857. types.UserScope,
  858. types.ProjectScope,
  859. types.SettingsScope,
  860. },
  861. },
  862. )
  863. policyGetHandler := policy.NewPolicyGetHandler(
  864. config,
  865. factory.GetDecoderValidator(),
  866. factory.GetResultWriter(),
  867. )
  868. routes = append(routes, &Route{
  869. Endpoint: policyGetEndpoint,
  870. Handler: policyGetHandler,
  871. Router: r,
  872. })
  873. // POST /api/projects/{project_id}/api_token -> api_token.NewAPITokenCreateHandler
  874. apiTokenCreateEndpoint := factory.NewAPIEndpoint(
  875. &types.APIRequestMetadata{
  876. Verb: types.APIVerbCreate,
  877. Method: types.HTTPVerbPost,
  878. Path: &types.Path{
  879. Parent: basePath,
  880. RelativePath: relPath + "/api_token",
  881. },
  882. Scopes: []types.PermissionScope{
  883. types.UserScope,
  884. types.ProjectScope,
  885. types.SettingsScope,
  886. },
  887. },
  888. )
  889. apiTokenCreateHandler := api_token.NewAPITokenCreateHandler(
  890. config,
  891. factory.GetDecoderValidator(),
  892. factory.GetResultWriter(),
  893. )
  894. routes = append(routes, &Route{
  895. Endpoint: apiTokenCreateEndpoint,
  896. Handler: apiTokenCreateHandler,
  897. Router: r,
  898. })
  899. // GET /api/projects/{project_id}/api_token -> api_token.NewAPITokenListHandler
  900. apiTokenListEndpoint := factory.NewAPIEndpoint(
  901. &types.APIRequestMetadata{
  902. Verb: types.APIVerbList,
  903. Method: types.HTTPVerbGet,
  904. Path: &types.Path{
  905. Parent: basePath,
  906. RelativePath: fmt.Sprintf("%s/api_token", relPath),
  907. },
  908. Scopes: []types.PermissionScope{
  909. types.UserScope,
  910. types.ProjectScope,
  911. types.SettingsScope,
  912. },
  913. },
  914. )
  915. apiTokenListHandler := api_token.NewAPITokenListHandler(
  916. config,
  917. factory.GetDecoderValidator(),
  918. factory.GetResultWriter(),
  919. )
  920. routes = append(routes, &Route{
  921. Endpoint: apiTokenListEndpoint,
  922. Handler: apiTokenListHandler,
  923. Router: r,
  924. })
  925. // GET /api/projects/{project_id}/api_token/{api_token_id} -> api_token.NewAPITokenGetHandler
  926. apiTokenGetEndpoint := factory.NewAPIEndpoint(
  927. &types.APIRequestMetadata{
  928. Verb: types.APIVerbGet,
  929. Method: types.HTTPVerbGet,
  930. Path: &types.Path{
  931. Parent: basePath,
  932. RelativePath: fmt.Sprintf("%s/api_token/{%s}", relPath, types.URLParamTokenID),
  933. },
  934. Scopes: []types.PermissionScope{
  935. types.UserScope,
  936. types.ProjectScope,
  937. types.SettingsScope,
  938. },
  939. },
  940. )
  941. apiTokenGetHandler := api_token.NewAPITokenGetHandler(
  942. config,
  943. factory.GetDecoderValidator(),
  944. factory.GetResultWriter(),
  945. )
  946. routes = append(routes, &Route{
  947. Endpoint: apiTokenGetEndpoint,
  948. Handler: apiTokenGetHandler,
  949. Router: r,
  950. })
  951. // POST /api/projects/{project_id}/api_token/{api_token_id}/revoke -> api_token.NewAPITokenRevokeHandler
  952. apiTokenRevokeEndpoint := factory.NewAPIEndpoint(
  953. &types.APIRequestMetadata{
  954. Verb: types.APIVerbUpdate,
  955. Method: types.HTTPVerbPost,
  956. Path: &types.Path{
  957. Parent: basePath,
  958. RelativePath: fmt.Sprintf("%s/api_token/{%s}/revoke", relPath, types.URLParamTokenID),
  959. },
  960. Scopes: []types.PermissionScope{
  961. types.UserScope,
  962. types.ProjectScope,
  963. types.SettingsScope,
  964. },
  965. },
  966. )
  967. apiTokenRevokeHandler := api_token.NewAPITokenRevokeHandler(
  968. config,
  969. factory.GetDecoderValidator(),
  970. factory.GetResultWriter(),
  971. )
  972. routes = append(routes, &Route{
  973. Endpoint: apiTokenRevokeEndpoint,
  974. Handler: apiTokenRevokeHandler,
  975. Router: r,
  976. })
  977. // POST /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoCreateHandler
  978. hrCreateEndpoint := factory.NewAPIEndpoint(
  979. &types.APIRequestMetadata{
  980. Verb: types.APIVerbCreate,
  981. Method: types.HTTPVerbPost,
  982. Path: &types.Path{
  983. Parent: basePath,
  984. RelativePath: relPath + "/helmrepos",
  985. },
  986. Scopes: []types.PermissionScope{
  987. types.UserScope,
  988. types.ProjectScope,
  989. },
  990. },
  991. )
  992. hrCreateHandler := helmrepo.NewHelmRepoCreateHandler(
  993. config,
  994. factory.GetDecoderValidator(),
  995. factory.GetResultWriter(),
  996. )
  997. routes = append(routes, &Route{
  998. Endpoint: hrCreateEndpoint,
  999. Handler: hrCreateHandler,
  1000. Router: r,
  1001. })
  1002. // GET /api/projects/{project_id}/helmrepos -> helmrepo.NewHelmRepoListHandler
  1003. hrListEndpoint := factory.NewAPIEndpoint(
  1004. &types.APIRequestMetadata{
  1005. Verb: types.APIVerbList,
  1006. Method: types.HTTPVerbGet,
  1007. Path: &types.Path{
  1008. Parent: basePath,
  1009. RelativePath: relPath + "/helmrepos",
  1010. },
  1011. Scopes: []types.PermissionScope{
  1012. types.UserScope,
  1013. types.ProjectScope,
  1014. },
  1015. },
  1016. )
  1017. hrListHandler := helmrepo.NewHelmRepoListHandler(
  1018. config,
  1019. factory.GetResultWriter(),
  1020. )
  1021. routes = append(routes, &Route{
  1022. Endpoint: hrListEndpoint,
  1023. Handler: hrListHandler,
  1024. Router: r,
  1025. })
  1026. return routes, newPath
  1027. }