| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package router
- import (
- "github.com/go-chi/chi"
- "github.com/porter-dev/porter/api/server/handlers/project_oauth"
- "github.com/porter-dev/porter/api/server/shared"
- "github.com/porter-dev/porter/api/server/shared/config"
- "github.com/porter-dev/porter/api/types"
- )
- func NewProjectOAuthScopedRegisterer(children ...*Registerer) *Registerer {
- return &Registerer{
- GetRoutes: GetProjectOAuthScopedRoutes,
- Children: children,
- }
- }
- func GetProjectOAuthScopedRoutes(
- r chi.Router,
- config *config.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- children ...*Registerer,
- ) []*Route {
- routes, projPath := getProjectOAuthRoutes(r, config, basePath, factory)
- if len(children) > 0 {
- r.Route(projPath.RelativePath, func(r chi.Router) {
- for _, child := range children {
- childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
- routes = append(routes, childRoutes...)
- }
- })
- }
- return routes
- }
- func getProjectOAuthRoutes(
- r chi.Router,
- config *config.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- ) ([]*Route, *types.Path) {
- relPath := "/oauth"
- newPath := &types.Path{
- Parent: basePath,
- RelativePath: relPath,
- }
- routes := make([]*Route, 0)
- // GET /api/projects/{project_id}/oauth/slack -> project_integration.NewProjectOAuthSlackHandler
- slackEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/slack",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- },
- },
- )
- slackHandler := project_oauth.NewProjectOAuthSlackHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: slackEndpoint,
- Handler: slackHandler,
- Router: r,
- })
- return routes, newPath
- }
|