base.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. package router
  2. import (
  3. "github.com/go-chi/chi"
  4. "github.com/porter-dev/porter/api/server/handlers/gitinstallation"
  5. "github.com/porter-dev/porter/api/server/handlers/metadata"
  6. "github.com/porter-dev/porter/api/server/handlers/release"
  7. "github.com/porter-dev/porter/api/server/handlers/user"
  8. "github.com/porter-dev/porter/api/server/shared"
  9. "github.com/porter-dev/porter/api/server/shared/config"
  10. "github.com/porter-dev/porter/api/types"
  11. )
  12. func NewBaseRegisterer(children ...*Registerer) *Registerer {
  13. return &Registerer{
  14. GetRoutes: GetBaseRoutes,
  15. Children: children,
  16. }
  17. }
  18. func GetBaseRoutes(
  19. r chi.Router,
  20. config *config.Config,
  21. basePath *types.Path,
  22. factory shared.APIEndpointFactory,
  23. children ...*Registerer,
  24. ) []*Route {
  25. routes := make([]*Route, 0)
  26. // GET /api/capabilities -> user.NewUserCreateHandler
  27. getMetadataEndpoint := factory.NewAPIEndpoint(
  28. &types.APIRequestMetadata{
  29. Verb: types.APIVerbGet,
  30. Method: types.HTTPVerbGet,
  31. Path: &types.Path{
  32. Parent: basePath,
  33. RelativePath: "/metadata",
  34. },
  35. },
  36. )
  37. getMetadataHandler := metadata.NewMetadataGetHandler(
  38. config,
  39. factory.GetResultWriter(),
  40. )
  41. routes = append(routes, &Route{
  42. Endpoint: getMetadataEndpoint,
  43. Handler: getMetadataHandler,
  44. Router: r,
  45. })
  46. // GET /api/integrations/cluster -> metadata.NewListClusterIntegrationsHandler
  47. listClusterIntsEndpoint := factory.NewAPIEndpoint(
  48. &types.APIRequestMetadata{
  49. Verb: types.APIVerbGet,
  50. Method: types.HTTPVerbGet,
  51. Path: &types.Path{
  52. Parent: basePath,
  53. RelativePath: "/integrations/cluster",
  54. },
  55. },
  56. )
  57. listClusterIntsHandler := metadata.NewListClusterIntegrationsHandler(
  58. config,
  59. factory.GetResultWriter(),
  60. )
  61. routes = append(routes, &Route{
  62. Endpoint: listClusterIntsEndpoint,
  63. Handler: listClusterIntsHandler,
  64. Router: r,
  65. })
  66. // GET /api/integrations/registry -> metadata.NewListRegistryIntegrationsHandler
  67. listRegistryIntsEndpoint := factory.NewAPIEndpoint(
  68. &types.APIRequestMetadata{
  69. Verb: types.APIVerbGet,
  70. Method: types.HTTPVerbGet,
  71. Path: &types.Path{
  72. Parent: basePath,
  73. RelativePath: "/integrations/registry",
  74. },
  75. },
  76. )
  77. listRegistryIntsHandler := metadata.NewListRegistryIntegrationsHandler(
  78. config,
  79. factory.GetResultWriter(),
  80. )
  81. routes = append(routes, &Route{
  82. Endpoint: listRegistryIntsEndpoint,
  83. Handler: listRegistryIntsHandler,
  84. Router: r,
  85. })
  86. // GET /api/integrations/helm -> metadata.NewListHelmRepoIntegrationsHandler
  87. listHelmRepoIntsEndpoint := factory.NewAPIEndpoint(
  88. &types.APIRequestMetadata{
  89. Verb: types.APIVerbGet,
  90. Method: types.HTTPVerbGet,
  91. Path: &types.Path{
  92. Parent: basePath,
  93. RelativePath: "/integrations/helm",
  94. },
  95. },
  96. )
  97. listHelmRepoIntsHandler := metadata.NewListHelmRepoIntegrationsHandler(
  98. config,
  99. factory.GetResultWriter(),
  100. )
  101. routes = append(routes, &Route{
  102. Endpoint: listHelmRepoIntsEndpoint,
  103. Handler: listHelmRepoIntsHandler,
  104. Router: r,
  105. })
  106. // POST /api/users -> user.NewUserCreateHandler
  107. createUserEndpoint := factory.NewAPIEndpoint(
  108. &types.APIRequestMetadata{
  109. Verb: types.APIVerbCreate,
  110. Method: types.HTTPVerbPost,
  111. Path: &types.Path{
  112. Parent: basePath,
  113. RelativePath: "/users",
  114. },
  115. },
  116. )
  117. createUserHandler := user.NewUserCreateHandler(
  118. config,
  119. factory.GetDecoderValidator(),
  120. factory.GetResultWriter(),
  121. )
  122. routes = append(routes, &Route{
  123. Endpoint: createUserEndpoint,
  124. Handler: createUserHandler,
  125. Router: r,
  126. })
  127. // POST /api/login -> user.NewUserLoginHandler
  128. loginUserEndpoint := factory.NewAPIEndpoint(
  129. &types.APIRequestMetadata{
  130. Verb: types.APIVerbUpdate,
  131. Method: types.HTTPVerbPost,
  132. Path: &types.Path{
  133. Parent: basePath,
  134. RelativePath: "/login",
  135. },
  136. },
  137. )
  138. loginUserHandler := user.NewUserLoginHandler(
  139. config,
  140. factory.GetDecoderValidator(),
  141. factory.GetResultWriter(),
  142. )
  143. routes = append(routes, &Route{
  144. Endpoint: loginUserEndpoint,
  145. Handler: loginUserHandler,
  146. Router: r,
  147. })
  148. // POST /api/cli/login/exchange -> user.NewCLILoginExchangeHandler
  149. cliLoginExchangeEndpoint := factory.NewAPIEndpoint(
  150. &types.APIRequestMetadata{
  151. Verb: types.APIVerbCreate,
  152. Method: types.HTTPVerbPost,
  153. Path: &types.Path{
  154. Parent: basePath,
  155. RelativePath: "/cli/login/exchange",
  156. },
  157. },
  158. )
  159. cliLoginExchangeHandler := user.NewCLILoginExchangeHandler(
  160. config,
  161. factory.GetDecoderValidator(),
  162. factory.GetResultWriter(),
  163. )
  164. routes = append(routes, &Route{
  165. Endpoint: cliLoginExchangeEndpoint,
  166. Handler: cliLoginExchangeHandler,
  167. Router: r,
  168. })
  169. // POST /api/password/reset/initiate -> user.NewUserPasswordInitiateResetHandler
  170. passwordInitiateResetEndpoint := factory.NewAPIEndpoint(
  171. &types.APIRequestMetadata{
  172. Verb: types.APIVerbCreate,
  173. Method: types.HTTPVerbPost,
  174. Path: &types.Path{
  175. Parent: basePath,
  176. RelativePath: "/password/reset/initiate",
  177. },
  178. },
  179. )
  180. passwordInitiateResetHandler := user.NewUserPasswordInitiateResetHandler(
  181. config,
  182. factory.GetDecoderValidator(),
  183. factory.GetResultWriter(),
  184. )
  185. routes = append(routes, &Route{
  186. Endpoint: passwordInitiateResetEndpoint,
  187. Handler: passwordInitiateResetHandler,
  188. Router: r,
  189. })
  190. // POST /api/password/reset/verify -> user.NewUserPasswordVerifyResetHandler
  191. passwordVerifyResetEndpoint := factory.NewAPIEndpoint(
  192. &types.APIRequestMetadata{
  193. Verb: types.APIVerbCreate,
  194. Method: types.HTTPVerbPost,
  195. Path: &types.Path{
  196. Parent: basePath,
  197. RelativePath: "/password/reset/verify",
  198. },
  199. },
  200. )
  201. passwordVerifyResetHandler := user.NewUserPasswordVerifyResetHandler(
  202. config,
  203. factory.GetDecoderValidator(),
  204. factory.GetResultWriter(),
  205. )
  206. routes = append(routes, &Route{
  207. Endpoint: passwordVerifyResetEndpoint,
  208. Handler: passwordVerifyResetHandler,
  209. Router: r,
  210. })
  211. // POST /api/password/reset/finalize -> user.NewUserPasswordFinalizeResetHandler
  212. passwordFinalizeResetEndpoint := factory.NewAPIEndpoint(
  213. &types.APIRequestMetadata{
  214. Verb: types.APIVerbCreate,
  215. Method: types.HTTPVerbPost,
  216. Path: &types.Path{
  217. Parent: basePath,
  218. RelativePath: "/password/reset/finalize",
  219. },
  220. },
  221. )
  222. passwordFinalizeResetHandler := user.NewUserPasswordFinalizeResetHandler(
  223. config,
  224. factory.GetDecoderValidator(),
  225. factory.GetResultWriter(),
  226. )
  227. routes = append(routes, &Route{
  228. Endpoint: passwordFinalizeResetEndpoint,
  229. Handler: passwordFinalizeResetHandler,
  230. Router: r,
  231. })
  232. // POST /api/webhooks/deploy/{token} -> release.NewWebhookHandler
  233. webhookEndpoint := factory.NewAPIEndpoint(
  234. &types.APIRequestMetadata{
  235. Verb: types.APIVerbUpdate,
  236. Method: types.HTTPVerbPost,
  237. Path: &types.Path{
  238. Parent: basePath,
  239. RelativePath: "/webhooks/deploy/{token}",
  240. },
  241. Scopes: []types.PermissionScope{},
  242. },
  243. )
  244. webhookHandler := release.NewWebhookHandler(
  245. config,
  246. factory.GetDecoderValidator(),
  247. factory.GetResultWriter(),
  248. )
  249. routes = append(routes, &Route{
  250. Endpoint: webhookEndpoint,
  251. Handler: webhookHandler,
  252. Router: r,
  253. })
  254. // GET /api/integrations/github-app/oauth -> gitinstallation.NewGithubAppOAuthStartHandler
  255. githubAppOAuthStartEndpoint := factory.NewAPIEndpoint(
  256. &types.APIRequestMetadata{
  257. Verb: types.APIVerbGet,
  258. Method: types.HTTPVerbGet,
  259. Path: &types.Path{
  260. Parent: basePath,
  261. RelativePath: "/integrations/github-app/oauth",
  262. },
  263. Scopes: []types.PermissionScope{},
  264. },
  265. )
  266. githubAppOAuthStartHandler := gitinstallation.NewGithubAppOAuthStartHandler(
  267. config,
  268. )
  269. routes = append(routes, &Route{
  270. Endpoint: githubAppOAuthStartEndpoint,
  271. Handler: githubAppOAuthStartHandler,
  272. Router: r,
  273. })
  274. // GET /api/integrations/github-app/install
  275. githubAppInstallEndpoint := factory.NewAPIEndpoint(
  276. &types.APIRequestMetadata{
  277. Verb: types.APIVerbGet,
  278. Method: types.HTTPVerbGet,
  279. Path: &types.Path{
  280. Parent: basePath,
  281. RelativePath: "/integrations/github-app/install",
  282. },
  283. Scopes: []types.PermissionScope{},
  284. },
  285. )
  286. githubAppInstallHandler := gitinstallation.NewGithubAppInstallHandler(
  287. config,
  288. )
  289. routes = append(routes, &Route{
  290. Endpoint: githubAppInstallEndpoint,
  291. Handler: githubAppInstallHandler,
  292. Router: r,
  293. })
  294. // POST /api/integrations/github-app/webhook
  295. githubAppWebhookEndpoint := factory.NewAPIEndpoint(
  296. &types.APIRequestMetadata{
  297. Verb: types.APIVerbCreate,
  298. Method: types.HTTPVerbPost,
  299. Path: &types.Path{
  300. Parent: basePath,
  301. RelativePath: "/integrations/github-app/webhook",
  302. },
  303. Scopes: []types.PermissionScope{},
  304. },
  305. )
  306. githubAppWebhookHandler := gitinstallation.NewGithubAppWebhookHandler(
  307. config,
  308. factory.GetDecoderValidator(),
  309. factory.GetResultWriter(),
  310. )
  311. routes = append(routes, &Route{
  312. Endpoint: githubAppWebhookEndpoint,
  313. Handler: githubAppWebhookHandler,
  314. Router: r,
  315. })
  316. return routes
  317. }