|
|
@@ -1,114 +0,0 @@
|
|
|
-package router
|
|
|
-
|
|
|
-import (
|
|
|
- "github.com/go-chi/chi"
|
|
|
- "github.com/porter-dev/porter/api/server/handlers/porter_app"
|
|
|
- "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 NewPorterAppScopedRegisterer(children ...*router.Registerer) *router.Registerer {
|
|
|
- return &router.Registerer{
|
|
|
- GetRoutes: GetPorterAppScopedRoutes,
|
|
|
- Children: children,
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func GetPorterAppScopedRoutes(
|
|
|
- r chi.Router,
|
|
|
- config *config.Config,
|
|
|
- basePath *types.Path,
|
|
|
- factory shared.APIEndpointFactory,
|
|
|
- children ...*router.Registerer,
|
|
|
-) []*router.Route {
|
|
|
- routes, porterAppPath := getPorterAppRoutes(r, config, basePath, factory)
|
|
|
-
|
|
|
- if len(children) > 0 {
|
|
|
- r.Route(porterAppPath.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 getPorterAppRoutes(
|
|
|
- r chi.Router,
|
|
|
- config *config.Config,
|
|
|
- basePath *types.Path,
|
|
|
- factory shared.APIEndpointFactory,
|
|
|
-) ([]*router.Route, *types.Path) {
|
|
|
- relPath := "/porter_apps/{name}"
|
|
|
-
|
|
|
- newPath := &types.Path{
|
|
|
- Parent: basePath,
|
|
|
- RelativePath: relPath,
|
|
|
- }
|
|
|
-
|
|
|
- routes := make([]*router.Route, 0)
|
|
|
-
|
|
|
- // GET /api/projects/{project_id}/clusters/{cluster_id}/porter_apps/{name} -> porter_app.NewPorterAppGetHandler
|
|
|
- getEndpoint := factory.NewAPIEndpoint(
|
|
|
- &types.APIRequestMetadata{
|
|
|
- Verb: types.APIVerbGet,
|
|
|
- Method: types.HTTPVerbGet,
|
|
|
- Path: &types.Path{
|
|
|
- Parent: basePath,
|
|
|
- RelativePath: relPath,
|
|
|
- },
|
|
|
- Scopes: []types.PermissionScope{
|
|
|
- types.UserScope,
|
|
|
- types.ProjectScope,
|
|
|
- types.ClusterScope,
|
|
|
- },
|
|
|
- },
|
|
|
- )
|
|
|
-
|
|
|
- getHandler := porter_app.NewPorterAppGetHandler(
|
|
|
- config,
|
|
|
- factory.GetResultWriter(),
|
|
|
- )
|
|
|
-
|
|
|
- routes = append(routes, &router.Route{
|
|
|
- Endpoint: getEndpoint,
|
|
|
- Handler: getHandler,
|
|
|
- Router: r,
|
|
|
- })
|
|
|
-
|
|
|
- // POST /api/projects/{project_id}/clusters/{cluster_id}/porter_apps -> porter_app.NewCreatePorterAppHandler
|
|
|
- createPorterAppEndpoint := factory.NewAPIEndpoint(
|
|
|
- &types.APIRequestMetadata{
|
|
|
- Verb: types.APIVerbCreate,
|
|
|
- Method: types.HTTPVerbPost,
|
|
|
- Path: &types.Path{
|
|
|
- Parent: basePath,
|
|
|
- RelativePath: relPath,
|
|
|
- },
|
|
|
- Scopes: []types.PermissionScope{
|
|
|
- types.UserScope,
|
|
|
- types.ProjectScope,
|
|
|
- types.ClusterScope,
|
|
|
- },
|
|
|
- },
|
|
|
- )
|
|
|
-
|
|
|
- createPorterAppHandler := porter_app.NewCreatePorterAppHandler(
|
|
|
- config,
|
|
|
- factory.GetDecoderValidator(),
|
|
|
- factory.GetResultWriter(),
|
|
|
- )
|
|
|
-
|
|
|
- routes = append(routes, &router.Route{
|
|
|
- Endpoint: createPorterAppEndpoint,
|
|
|
- Handler: createPorterAppHandler,
|
|
|
- Router: r,
|
|
|
- })
|
|
|
-
|
|
|
- return routes, newPath
|
|
|
-}
|