| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package router
- import (
- "github.com/go-chi/chi"
- "github.com/porter-dev/porter/api/server/authz"
- "github.com/porter-dev/porter/api/server/handlers/project"
- "github.com/porter-dev/porter/api/server/shared"
- "github.com/porter-dev/porter/api/types"
- )
- func RegisterProjectScopedRoutes(
- r chi.Router,
- config *shared.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- ) chi.Router {
- // Create a new "project-scoped" factory which will create a new project-scoped request
- // after authorization. Each subsequent http.Handler can lookup the project in context.
- projFactory := authz.NewProjectScopedFactory(config.Repo.Project(), config)
- // attach middleware to router
- r.Use(projFactory.NewProjectScoped)
- registerProjectEndpoints(r, config, basePath, factory)
- return r
- }
- func registerProjectEndpoints(
- r chi.Router,
- config *shared.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- ) {
- routes := make([]*Route, 0)
- projectPath := &types.Path{
- Parent: basePath,
- RelativePath: "/projects",
- }
- createEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbCreate,
- Method: types.HTTPVerbPost,
- Path: &types.Path{
- Parent: projectPath,
- RelativePath: "",
- },
- },
- )
- createHandler := project.NewProjectCreateHandler(config, createEndpoint)
- routes = append(routes, &Route{
- Endpoint: createEndpoint,
- Handler: createHandler,
- })
- registerRoutes(r, routes)
- }
|