oauth_callback.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package router
  2. import (
  3. "github.com/go-chi/chi/v5"
  4. "github.com/porter-dev/porter/api/server/handlers/oauth_callback"
  5. "github.com/porter-dev/porter/api/server/shared"
  6. "github.com/porter-dev/porter/api/server/shared/config"
  7. "github.com/porter-dev/porter/api/server/shared/router"
  8. "github.com/porter-dev/porter/api/types"
  9. )
  10. func NewOAuthCallbackRegisterer(children ...*router.Registerer) *router.Registerer {
  11. return &router.Registerer{
  12. GetRoutes: GetOAuthCallbackRoutes,
  13. Children: children,
  14. }
  15. }
  16. func GetOAuthCallbackRoutes(
  17. r chi.Router,
  18. config *config.Config,
  19. basePath *types.Path,
  20. factory shared.APIEndpointFactory,
  21. children ...*router.Registerer,
  22. ) []*router.Route {
  23. relPath := "/oauth"
  24. routes := make([]*router.Route, 0)
  25. // GET /api/oauth/slack/callback -> oauth_callback.NewOAuthCallbackSlackHandler
  26. slackEndpoint := factory.NewAPIEndpoint(
  27. &types.APIRequestMetadata{
  28. Verb: types.APIVerbGet,
  29. Method: types.HTTPVerbGet,
  30. Path: &types.Path{
  31. Parent: basePath,
  32. RelativePath: relPath + "/slack/callback",
  33. },
  34. },
  35. )
  36. slackHandler := oauth_callback.NewOAuthCallbackSlackHandler(
  37. config,
  38. factory.GetDecoderValidator(),
  39. factory.GetResultWriter(),
  40. )
  41. routes = append(routes, &router.Route{
  42. Endpoint: slackEndpoint,
  43. Handler: slackHandler,
  44. Router: r,
  45. })
  46. // GET /api/oauth/upstash/callback -> oauth_callback.NewOAuthCallbackUpstashHandler
  47. upstashEndpoint := factory.NewAPIEndpoint(
  48. &types.APIRequestMetadata{
  49. Verb: types.APIVerbGet,
  50. Method: types.HTTPVerbGet,
  51. Path: &types.Path{
  52. Parent: basePath,
  53. RelativePath: relPath + "/upstash/callback",
  54. },
  55. },
  56. )
  57. upstashHandler := oauth_callback.NewOAuthCallbackUpstashHandler(
  58. config,
  59. factory.GetDecoderValidator(),
  60. factory.GetResultWriter(),
  61. )
  62. routes = append(routes, &router.Route{
  63. Endpoint: upstashEndpoint,
  64. Handler: upstashHandler,
  65. Router: r,
  66. })
  67. // GET /api/oauth/digitalocean/callback -> oauth_callback.NewOAuthCallbackDOHandler
  68. doEndpoint := factory.NewAPIEndpoint(
  69. &types.APIRequestMetadata{
  70. Verb: types.APIVerbGet,
  71. Method: types.HTTPVerbGet,
  72. Path: &types.Path{
  73. Parent: basePath,
  74. RelativePath: relPath + "/digitalocean/callback",
  75. },
  76. },
  77. )
  78. doHandler := oauth_callback.NewOAuthCallbackDOHandler(
  79. config,
  80. factory.GetDecoderValidator(),
  81. factory.GetResultWriter(),
  82. )
  83. routes = append(routes, &router.Route{
  84. Endpoint: doEndpoint,
  85. Handler: doHandler,
  86. Router: r,
  87. })
  88. // GET /api/oauth/gitlab/callback -> oauth_callback.NewOAuthCallbackGitlabHandler
  89. gitlabEndpoint := factory.NewAPIEndpoint(
  90. &types.APIRequestMetadata{
  91. Verb: types.APIVerbGet,
  92. Method: types.HTTPVerbGet,
  93. Path: &types.Path{
  94. Parent: basePath,
  95. RelativePath: relPath + "/gitlab/callback",
  96. },
  97. },
  98. )
  99. gitlabHandler := oauth_callback.NewOAuthCallbackGitlabHandler(
  100. config,
  101. factory.GetDecoderValidator(),
  102. factory.GetResultWriter(),
  103. )
  104. routes = append(routes, &router.Route{
  105. Endpoint: gitlabEndpoint,
  106. Handler: gitlabHandler,
  107. Router: r,
  108. })
  109. return routes
  110. }