| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package router
- import (
- "github.com/go-chi/chi"
- "github.com/porter-dev/porter/api/server/handlers/oauth_callback"
- "github.com/porter-dev/porter/api/server/shared"
- "github.com/porter-dev/porter/api/server/shared/config"
- "github.com/porter-dev/porter/api/server/shared/router"
- "github.com/porter-dev/porter/api/types"
- )
- func NewOAuthCallbackRegisterer(children ...*router.Registerer) *router.Registerer {
- return &router.Registerer{
- GetRoutes: GetOAuthCallbackRoutes,
- Children: children,
- }
- }
- func GetOAuthCallbackRoutes(
- r chi.Router,
- config *config.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- children ...*router.Registerer,
- ) []*router.Route {
- relPath := "/oauth"
- routes := make([]*router.Route, 0)
- // GET /api/oauth/slack/callback -> oauth_callback.NewOAuthCallbackSlackHandler
- slackEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/slack/callback",
- },
- },
- )
- slackHandler := oauth_callback.NewOAuthCallbackSlackHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: slackEndpoint,
- Handler: slackHandler,
- Router: r,
- })
- // GET /api/oauth/digitalocean/callback -> oauth_callback.NewOAuthCallbackDOHandler
- doEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/digitalocean/callback",
- },
- },
- )
- doHandler := oauth_callback.NewOAuthCallbackDOHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: doEndpoint,
- Handler: doHandler,
- Router: r,
- })
- // GET /api/oauth/gitlab/callback -> oauth_callback.NewOAuthCallbackGitlabHandler
- gitlabEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/gitlab/callback",
- },
- },
- )
- gitlabHandler := oauth_callback.NewOAuthCallbackGitlabHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: gitlabEndpoint,
- Handler: gitlabHandler,
- Router: r,
- })
- return routes
- }
|