| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package router
- import (
- "github.com/go-chi/chi"
- "github.com/porter-dev/porter/api/server/handlers/release"
- "github.com/porter-dev/porter/api/server/shared"
- "github.com/porter-dev/porter/api/types"
- )
- func NewReleaseScopedRegisterer(children ...*Registerer) *Registerer {
- return &Registerer{
- GetRoutes: GetReleaseScopedRoutes,
- Children: children,
- }
- }
- func GetReleaseScopedRoutes(
- r chi.Router,
- config *shared.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- children ...*Registerer,
- ) []*Route {
- routes, projPath := getReleaseRoutes(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 getReleaseRoutes(
- r chi.Router,
- config *shared.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- ) ([]*Route, *types.Path) {
- relPath := "/releases/{name}/{version}"
- newPath := &types.Path{
- Parent: basePath,
- RelativePath: relPath,
- }
- routes := make([]*Route, 0)
- // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version} -> release.NewReleaseGetHandler
- 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,
- types.NamespaceScope,
- types.ReleaseScope,
- },
- },
- )
- getHandler := release.NewReleaseGetHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getEndpoint,
- Handler: getHandler,
- Router: r,
- })
- return routes, newPath
- }
|