| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- 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/server/shared/config"
- "github.com/porter-dev/porter/api/types"
- )
- func NewReleaseScopedRegisterer(children ...*Registerer) *Registerer {
- return &Registerer{
- GetRoutes: GetReleaseScopedRoutes,
- Children: children,
- }
- }
- func GetReleaseScopedRoutes(
- r chi.Router,
- config *config.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 *config.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,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/controllers -> release.NewGetControllersHandler
- getControllersEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/controllers",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- types.NamespaceScope,
- types.ReleaseScope,
- },
- },
- )
- getControllersHandler := release.NewGetControllersHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getControllersEndpoint,
- Handler: getControllersHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/components -> release.NewGetComponentsHandler
- getComponentsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/components",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- types.NamespaceScope,
- types.ReleaseScope,
- },
- },
- )
- getComponentsHandler := release.NewGetComponentsHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getComponentsEndpoint,
- Handler: getComponentsHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/history -> release.NewGetHistoryHandler
- getHistoryEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: "/releases/{name}/history",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- types.NamespaceScope,
- },
- },
- )
- getHistoryHandler := release.NewGetReleaseHistoryHandler(
- config,
- factory.GetDecoderValidator(),
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getHistoryEndpoint,
- Handler: getHistoryHandler,
- Router: r,
- })
- // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/pods/all -> release.NewGetAllPodsHandler
- getAllPodsEndpoint := factory.NewAPIEndpoint(
- &types.APIRequestMetadata{
- Verb: types.APIVerbGet,
- Method: types.HTTPVerbGet,
- Path: &types.Path{
- Parent: basePath,
- RelativePath: relPath + "/pods/all",
- },
- Scopes: []types.PermissionScope{
- types.UserScope,
- types.ProjectScope,
- types.ClusterScope,
- types.NamespaceScope,
- types.ReleaseScope,
- },
- },
- )
- getAllPodsHandler := release.NewGetAllPodsHandler(
- config,
- factory.GetResultWriter(),
- )
- routes = append(routes, &Route{
- Endpoint: getAllPodsEndpoint,
- Handler: getAllPodsHandler,
- Router: r,
- })
- return routes, newPath
- }
|