diff --git a/.drone.env b/.drone.env index 0c2d4a50210..f9010ed6f20 100644 --- a/.drone.env +++ b/.drone.env @@ -1,4 +1,4 @@ # The test runner source for API tests -APITESTS_COMMITID=9c3511d2b08de25b16be3d309d0a7710b6848747 +APITESTS_COMMITID=5efc3c51a17e5c71a366436afeb52528ed49c7da APITESTS_BRANCH=master APITESTS_REPO_GIT_URL=https://github.com/owncloud/ocis.git diff --git a/changelog/unreleased/noversions.md b/changelog/unreleased/noversions.md new file mode 100644 index 00000000000..21d35e891d8 --- /dev/null +++ b/changelog/unreleased/noversions.md @@ -0,0 +1,6 @@ +Enhancement: Disable versions on a storage provider + +Added a GRPC interceptor that disable the versions +on a storage provider. + +https://github.com/cs3org/reva/pull/4164 \ No newline at end of file diff --git a/internal/grpc/interceptors/loader/loader.go b/internal/grpc/interceptors/loader/loader.go index 8b995af76f1..5beab8b35cb 100644 --- a/internal/grpc/interceptors/loader/loader.go +++ b/internal/grpc/interceptors/loader/loader.go @@ -21,6 +21,7 @@ package loader import ( // Load core GRPC services. _ "github.com/cs3org/reva/internal/grpc/interceptors/eventsmiddleware" + _ "github.com/cs3org/reva/internal/grpc/interceptors/noversions" _ "github.com/cs3org/reva/internal/grpc/interceptors/readonly" // Add your own service here. ) diff --git a/internal/grpc/interceptors/noversions/noversions.go b/internal/grpc/interceptors/noversions/noversions.go new file mode 100644 index 00000000000..20b6ae7f01e --- /dev/null +++ b/internal/grpc/interceptors/noversions/noversions.go @@ -0,0 +1,73 @@ +// Copyright 2018-2023 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +package noversions + +import ( + "context" + + provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + "github.com/cs3org/reva/pkg/rgrpc" + rstatus "github.com/cs3org/reva/pkg/rgrpc/status" + "google.golang.org/grpc" +) + +const ( + defaultPriority = 200 +) + +func init() { + rgrpc.RegisterUnaryInterceptor("noversions", NewUnary) +} + +// NewUnary returns a new unary interceptor +// that checks grpc calls and blocks write requests. +func NewUnary(_ map[string]interface{}) (grpc.UnaryServerInterceptor, int, error) { + return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { + switch req.(type) { + case *provider.ListContainerRequest: + resp, err := handler(ctx, req) + if listResp, ok := resp.(*provider.ListContainerResponse); ok && listResp.Infos != nil { + for _, info := range listResp.Infos { + if info.PermissionSet != nil { + info.PermissionSet.ListFileVersions = false + info.PermissionSet.RestoreFileVersion = false + } + } + } + return resp, err + case *provider.StatRequest: + resp, err := handler(ctx, req) + if statResp, ok := resp.(*provider.StatResponse); ok && statResp.Info != nil && statResp.Info.PermissionSet != nil { + statResp.Info.PermissionSet.ListFileVersions = false + statResp.Info.PermissionSet.RestoreFileVersion = false + } + return resp, err + case *provider.ListFileVersionsRequest: + return &provider.ListFileVersionsResponse{ + Status: rstatus.NewPermissionDenied(ctx, nil, "permission denied: tried to list file versions on a no versions storage"), + }, nil + case *provider.RestoreFileVersionRequest: + return &provider.RestoreFileVersionResponse{ + Status: rstatus.NewPermissionDenied(ctx, nil, "permission denied: tried to restore file version on a no versions storage"), + }, nil + default: + return handler(ctx, req) + } + }, defaultPriority, nil +} diff --git a/tests/ocis b/tests/ocis index 9c3511d2b08..5efc3c51a17 160000 --- a/tests/ocis +++ b/tests/ocis @@ -1 +1 @@ -Subproject commit 9c3511d2b08de25b16be3d309d0a7710b6848747 +Subproject commit 5efc3c51a17e5c71a366436afeb52528ed49c7da