| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546 |
- package router
- import (
- "fmt"
- "github.com/go-chi/chi"
- "github.com/porter-dev/porter/api/server/handlers/credentials"
- "github.com/porter-dev/porter/api/server/handlers/gitinstallation"
- "github.com/porter-dev/porter/api/server/handlers/healthcheck"
- "github.com/porter-dev/porter/api/server/handlers/metadata"
- "github.com/porter-dev/porter/api/server/handlers/release"
- "github.com/porter-dev/porter/api/server/handlers/user"
- "github.com/porter-dev/porter/api/server/handlers/webhook"
- "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 NewBaseRegisterer(children ...*router.Registerer) *router.Registerer {
- return &router.Registerer{
- GetRoutes: GetBaseRoutes,
- Children: children,
- }
- }
- func GetBaseRoutes(
- r chi.Router,
- config *config.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- children ...*router.Registerer,
- ) []*router.Route {
- routes := make([]*router.Route, 0)
- // GET /api/readyz -> healthcheck.NewReadyzHandler
- getReadyzEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/readyz",
- },
- Quiet: true,
- },
- )
- getReadyzHandler := healthcheck.NewReadyzHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: getReadyzEndpoint,
- Handler: getReadyzHandler,
- Router: r,
- })
- // GET /api/livez -> healthcheck.NewLivezHandler
- getLivezEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/livez",
- },
- Quiet: true,
- },
- )
- getLivezHandler := healthcheck.NewLivezHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: getLivezEndpoint,
- Handler: getLivezHandler,
- Router: r,
- })
- // GET /api/metadata -> metadata.NewMetadataGetHandler
- getMetadataEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/metadata",
- },
- },
- )
- getMetadataHandler := metadata.NewMetadataGetHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: getMetadataEndpoint,
- Handler: getMetadataHandler,
- Router: r,
- })
- // GET /api/integrations/cluster -> metadata.NewListClusterIntegrationsHandler
- listClusterIntsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/integrations/cluster",
- },
- },
- )
- listClusterIntsHandler := metadata.NewListClusterIntegrationsHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: listClusterIntsEndpoint,
- Handler: listClusterIntsHandler,
- Router: r,
- })
- // GET /api/integrations/registry -> metadata.NewListRegistryIntegrationsHandler
- listRegistryIntsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/integrations/registry",
- },
- },
- )
- listRegistryIntsHandler := metadata.NewListRegistryIntegrationsHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: listRegistryIntsEndpoint,
- Handler: listRegistryIntsHandler,
- Router: r,
- })
- // GET /api/integrations/helm -> metadata.NewListHelmRepoIntegrationsHandler
- listHelmRepoIntsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/integrations/helm",
- },
- },
- )
- listHelmRepoIntsHandler := metadata.NewListHelmRepoIntegrationsHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: listHelmRepoIntsEndpoint,
- Handler: listHelmRepoIntsHandler,
- Router: r,
- })
- // POST /api/users -> user.NewUserCreateHandler
- createUserEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/users",
- },
- },
- )
- createUserHandler := user.NewUserCreateHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: createUserEndpoint,
- Handler: createUserHandler,
- Router: r,
- })
- // POST /api/login -> user.NewUserLoginHandler
- loginUserEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbUpdate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/login",
- },
- },
- )
- loginUserHandler := user.NewUserLoginHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: loginUserEndpoint,
- Handler: loginUserHandler,
- Router: r,
- })
- // POST /api/cli/login/exchange -> user.NewCLILoginExchangeHandler
- cliLoginExchangeEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/cli/login/exchange",
- },
- },
- )
- cliLoginExchangeHandler := user.NewCLILoginExchangeHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: cliLoginExchangeEndpoint,
- Handler: cliLoginExchangeHandler,
- Router: r,
- })
- // POST /api/password/reset/initiate -> user.NewUserPasswordInitiateResetHandler
- passwordInitiateResetEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/password/reset/initiate",
- },
- },
- )
- passwordInitiateResetHandler := user.NewUserPasswordInitiateResetHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: passwordInitiateResetEndpoint,
- Handler: passwordInitiateResetHandler,
- Router: r,
- })
- // POST /api/password/reset/verify -> user.NewUserPasswordVerifyResetHandler
- passwordVerifyResetEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/password/reset/verify",
- },
- },
- )
- passwordVerifyResetHandler := user.NewUserPasswordVerifyResetHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: passwordVerifyResetEndpoint,
- Handler: passwordVerifyResetHandler,
- Router: r,
- })
- // POST /api/password/reset/finalize -> user.NewUserPasswordFinalizeResetHandler
- passwordFinalizeResetEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/password/reset/finalize",
- },
- },
- )
- passwordFinalizeResetHandler := user.NewUserPasswordFinalizeResetHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: passwordFinalizeResetEndpoint,
- Handler: passwordFinalizeResetHandler,
- Router: r,
- })
- // POST /api/webhooks/deploy/{token} -> release.NewWebhookHandler
- webhookEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbUpdate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/webhooks/deploy/{token}",
- },
- Scopes: []types.PermissionScope{},
- },
- )
- webhookHandler := release.NewWebhookHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: webhookEndpoint,
- Handler: webhookHandler,
- Router: r,
- })
- // GET /api/integrations/github-app/install
- githubAppInstallEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/integrations/github-app/install",
- },
- Scopes: []types.PermissionScope{},
- },
- )
- githubAppInstallHandler := gitinstallation.NewGithubAppInstallHandler(
- config,
- )
- routes = append(routes, &router.Route{
- Endpoint: githubAppInstallEndpoint,
- Handler: githubAppInstallHandler,
- Router: r,
- })
- // POST /api/integrations/github-app/webhook
- githubAppWebhookEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/integrations/github-app/webhook",
- },
- Scopes: []types.PermissionScope{},
- },
- )
- githubAppWebhookHandler := gitinstallation.NewGithubAppWebhookHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: githubAppWebhookEndpoint,
- Handler: githubAppWebhookHandler,
- Router: r,
- })
- // GET /api/oauth/login/github
- githubLoginStartEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/oauth/login/github",
- },
- Scopes: []types.PermissionScope{},
- },
- )
- githubLoginStartHandler := user.NewUserOAuthGithubHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: githubLoginStartEndpoint,
- Handler: githubLoginStartHandler,
- Router: r,
- })
- // GET /api/oauth/github/callback
- githubLoginCallbackEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/oauth/github/callback",
- },
- Scopes: []types.PermissionScope{},
- },
- )
- githubLoginCallbackHandler := user.NewUserOAuthGithubCallbackHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: githubLoginCallbackEndpoint,
- Handler: githubLoginCallbackHandler,
- Router: r,
- })
- // GET /api/oauth/login/google
- googleLoginStartEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/oauth/login/google",
- },
- Scopes: []types.PermissionScope{},
- },
- )
- googleLoginStartHandler := user.NewUserOAuthGoogleHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: googleLoginStartEndpoint,
- Handler: googleLoginStartHandler,
- Router: r,
- })
- // GET /api/oauth/google/callback
- googleLoginCallbackEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/oauth/google/callback",
- },
- Scopes: []types.PermissionScope{},
- },
- )
- googleLoginCallbackHandler := user.NewUserOAuthGoogleCallbackHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: googleLoginCallbackEndpoint,
- Handler: googleLoginCallbackHandler,
- Router: r,
- })
- // GET /api/internal/credentials
- getCredentialsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/internal/credentials",
- },
- Scopes: []types.PermissionScope{},
- },
- )
- getCredentialsHandler := credentials.NewGetCredentialsHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: getCredentialsEndpoint,
- Handler: getCredentialsHandler,
- Router: r,
- })
- if config.ServerConf.GithubIncomingWebhookSecret != "" {
- // POST /api/github/incoming_webhook/{webhook_id} -> webhook.NewGithubIncomingWebhook
- githubIncomingWebhookEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: fmt.Sprintf("/github/incoming_webhook/{%s}", types.URLParamIncomingWebhookID),
- },
- Scopes: []types.PermissionScope{},
- },
- )
- githubIncomingWebhookHandler := webhook.NewGithubIncomingWebhookHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &router.Route{
- Endpoint: githubIncomingWebhookEndpoint,
- Handler: githubIncomingWebhookHandler,
- Router: r,
- })
- }
- return routes
- }
|