|
|
@@ -0,0 +1,83 @@
|
|
|
+package router
|
|
|
+
|
|
|
+import (
|
|
|
+ "github.com/go-chi/chi"
|
|
|
+ project_integration "github.com/porter-dev/porter/api/server/handlers/project_integrations"
|
|
|
+ "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 NewProjectIntegrationScopedRegisterer(children ...*Registerer) *Registerer {
|
|
|
+ return &Registerer{
|
|
|
+ GetRoutes: GetProjectIntegrationScopedRoutes,
|
|
|
+ Children: children,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func GetProjectIntegrationScopedRoutes(
|
|
|
+ r chi.Router,
|
|
|
+ config *config.Config,
|
|
|
+ basePath *types.Path,
|
|
|
+ factory shared.APIEndpointFactory,
|
|
|
+ children ...*Registerer,
|
|
|
+) []*Route {
|
|
|
+ routes, projPath := getProjectIntegrationRoutes(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 getProjectIntegrationRoutes(
|
|
|
+ r chi.Router,
|
|
|
+ config *config.Config,
|
|
|
+ basePath *types.Path,
|
|
|
+ factory shared.APIEndpointFactory,
|
|
|
+) ([]*Route, *types.Path) {
|
|
|
+ relPath := "/integrations"
|
|
|
+
|
|
|
+ newPath := &types.Path{
|
|
|
+ Parent: basePath,
|
|
|
+ RelativePath: relPath,
|
|
|
+ }
|
|
|
+
|
|
|
+ routes := make([]*Route, 0)
|
|
|
+
|
|
|
+ // GET /api/projects/{project_id}/integrations/oauth -> project_integrations.NewListOAuth
|
|
|
+ listOAuthEndpoint := factory.NewAPIEndpoint(
|
|
|
+ &types.APIRequestMetadata{
|
|
|
+ Verb: types.APIVerbGet,
|
|
|
+ Method: types.HTTPVerbGet,
|
|
|
+ Path: &types.Path{
|
|
|
+ Parent: basePath,
|
|
|
+ RelativePath: relPath + "/oauth",
|
|
|
+ },
|
|
|
+ Scopes: []types.PermissionScope{
|
|
|
+ types.UserScope,
|
|
|
+ types.ProjectScope,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ )
|
|
|
+
|
|
|
+ listOAuthHandler := project_integration.NewListOAuthHandler(
|
|
|
+ config,
|
|
|
+ factory.GetResultWriter(),
|
|
|
+ )
|
|
|
+
|
|
|
+ routes = append(routes, &Route{
|
|
|
+ Endpoint: listOAuthEndpoint,
|
|
|
+ Handler: listOAuthHandler,
|
|
|
+ Router: r,
|
|
|
+ })
|
|
|
+
|
|
|
+ return routes, newPath
|
|
|
+}
|