Skip to content

Commit

Permalink
Fake ProviderIDs (#2790)
Browse files Browse the repository at this point in the history
* get rid of interceptor and move logic to storageprovider

Signed-off-by: jkoberg <[email protected]>

* use configured mountID instead of requested one

Signed-off-by: jkoberg <[email protected]>

* use requested providerID for Stat calls

Signed-off-by: jkoberg <[email protected]>

* storageid unwrap for sharesstorageprovider

Signed-off-by: jkoberg <[email protected]>

* storageid unwrap for publicstorageprovider

Signed-off-by: jkoberg <[email protected]>

* fallback to providerid if empty

Signed-off-by: jkoberg <[email protected]>

* add mountid config for storage providers

Signed-off-by: jkoberg <[email protected]>

* add storageid unwrap functionality

Signed-off-by: jkoberg <[email protected]>

* changelog

Signed-off-by: jkoberg <[email protected]>

* fix listing trash

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>

* cut providerid from opaqueid

Signed-off-by: jkoberg <[email protected]>

* fix import cycle in resourceid unit tests

Signed-off-by: jkoberg <[email protected]>

* fix restore recycle item

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>

* use feature core

Signed-off-by: jkoberg <[email protected]>

* add missing share_with_user_type in share data

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>

* prevent panic

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>

* bump core commit id

Signed-off-by: jkoberg <[email protected]>

* use feature core

Signed-off-by: jkoberg <[email protected]>

Co-authored-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
kobergj and butonic authored Apr 28, 2022
1 parent 0164880 commit 753492b
Show file tree
Hide file tree
Showing 16 changed files with 444 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .drone.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# The test runner source for API tests
CORE_COMMITID=b262ada63569e241f9cee451c23f267512fd48b2
CORE_BRANCH=master
CORE_COMMITID=69d8f1e0027d5763ef7d011aaff2df33beff16d
CORE_BRANCH=EscapeDollarOcisEdition
6 changes: 6 additions & 0 deletions changelog/unreleased/fake-providerids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: fake providerids so API stays stable after beta

To support the stativ registry, we need to accept providerids
This fakes the ids so the API can stay stable

https://github.com/cs3org/reva/pull/2790
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
rtrace "github.com/cs3org/reva/v2/pkg/trace"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/cs3org/reva/v2/pkg/utils/resourceid"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -102,6 +103,10 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {
}

func (s *service) SetArbitraryMetadata(ctx context.Context, req *provider.SetArbitraryMetadataRequest) (*provider.SetArbitraryMetadataResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

ref, _, _, st, err := s.translatePublicRefToCS3Ref(ctx, req.Ref)
switch {
case err != nil:
Expand All @@ -120,6 +125,10 @@ func (s *service) UnsetArbitraryMetadata(ctx context.Context, req *provider.Unse

// SetLock puts a lock on the given reference
func (s *service) SetLock(ctx context.Context, req *provider.SetLockRequest) (*provider.SetLockResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

ref, _, _, st, err := s.translatePublicRefToCS3Ref(ctx, req.Ref)
switch {
case err != nil:
Expand All @@ -134,6 +143,10 @@ func (s *service) SetLock(ctx context.Context, req *provider.SetLockRequest) (*p

// GetLock returns an existing lock on the given reference
func (s *service) GetLock(ctx context.Context, req *provider.GetLockRequest) (*provider.GetLockResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

ref, _, _, st, err := s.translatePublicRefToCS3Ref(ctx, req.Ref)
switch {
case err != nil:
Expand All @@ -148,6 +161,10 @@ func (s *service) GetLock(ctx context.Context, req *provider.GetLockRequest) (*p

// RefreshLock refreshes an existing lock on the given reference
func (s *service) RefreshLock(ctx context.Context, req *provider.RefreshLockRequest) (*provider.RefreshLockResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

ref, _, _, st, err := s.translatePublicRefToCS3Ref(ctx, req.Ref)
switch {
case err != nil:
Expand All @@ -162,6 +179,10 @@ func (s *service) RefreshLock(ctx context.Context, req *provider.RefreshLockRequ

// Unlock removes an existing lock from the given reference
func (s *service) Unlock(ctx context.Context, req *provider.UnlockRequest) (*provider.UnlockResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

ref, _, _, st, err := s.translatePublicRefToCS3Ref(ctx, req.Ref)
switch {
case err != nil:
Expand All @@ -175,6 +196,10 @@ func (s *service) Unlock(ctx context.Context, req *provider.UnlockRequest) (*pro
}

func (s *service) InitiateFileDownload(ctx context.Context, req *provider.InitiateFileDownloadRequest) (*provider.InitiateFileDownloadResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

statReq := &provider.StatRequest{Ref: req.Ref}
statRes, err := s.Stat(ctx, statReq)
if err != nil {
Expand Down Expand Up @@ -297,6 +322,10 @@ func (s *service) initiateFileDownload(ctx context.Context, req *provider.Initia
}

func (s *service) InitiateFileUpload(ctx context.Context, req *provider.InitiateFileUploadRequest) (*provider.InitiateFileUploadResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

cs3Ref, _, ls, st, err := s.translatePublicRefToCS3Ref(ctx, req.Ref)
switch {
case err != nil:
Expand Down Expand Up @@ -380,6 +409,14 @@ func (s *service) CreateStorageSpace(ctx context.Context, req *provider.CreateSt
// so id based requests can find the correct storage provider. These spaces
// have their root set to the shared resource.
func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSpacesRequest) (*provider.ListStorageSpacesResponse, error) {
for i, f := range req.Filters {
if f.Type == provider.ListStorageSpacesRequest_Filter_TYPE_ID {
id, _ := resourceid.StorageIDUnwrap(f.GetId().GetOpaqueId())
req.Filters[i].Term = &provider.ListStorageSpacesRequest_Filter_Id{Id: &provider.StorageSpaceId{OpaqueId: id}}
break
}
}

spaceTypes := map[string]struct{}{}
var exists = struct{}{}
appendTypes := []string{}
Expand Down Expand Up @@ -511,6 +548,10 @@ func (s *service) DeleteStorageSpace(ctx context.Context, req *provider.DeleteSt
}

func (s *service) CreateContainer(ctx context.Context, req *provider.CreateContainerRequest) (*provider.CreateContainerResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

ctx, span := rtrace.Provider.Tracer("publicstorageprovider").Start(ctx, "CreateContainer")
defer span.End()

Expand Down Expand Up @@ -551,6 +592,10 @@ func (s *service) CreateContainer(ctx context.Context, req *provider.CreateConta
}

func (s *service) TouchFile(ctx context.Context, req *provider.TouchFileRequest) (*provider.TouchFileResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

ref, _, _, st, err := s.translatePublicRefToCS3Ref(ctx, req.Ref)
switch {
case err != nil:
Expand All @@ -564,6 +609,10 @@ func (s *service) TouchFile(ctx context.Context, req *provider.TouchFileRequest)
}

func (s *service) Delete(ctx context.Context, req *provider.DeleteRequest) (*provider.DeleteResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

ctx, span := rtrace.Provider.Tracer("publicstorageprovider").Start(ctx, "Delete")
defer span.End()

Expand Down Expand Up @@ -604,6 +653,13 @@ func (s *service) Delete(ctx context.Context, req *provider.DeleteRequest) (*pro
}

func (s *service) Move(ctx context.Context, req *provider.MoveRequest) (*provider.MoveResponse, error) {
if req.Source.GetResourceId() != nil {
req.Source.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Source.ResourceId.StorageId)
}
if req.Destination.GetResourceId() != nil {
req.Destination.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Destination.ResourceId.StorageId)
}

ctx, span := rtrace.Provider.Tracer("publicstorageprovider").Start(ctx, "Move")
defer span.End()

Expand Down Expand Up @@ -667,6 +723,10 @@ func (s *service) Move(ctx context.Context, req *provider.MoveRequest) (*provide
}

func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provider.StatResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

ctx, span := rtrace.Provider.Tracer("publicstorageprovider").Start(ctx, "Stat")
defer span.End()

Expand Down Expand Up @@ -764,6 +824,9 @@ func (s *service) ListContainerStream(req *provider.ListContainerStreamRequest,
}

func (s *service) ListContainer(ctx context.Context, req *provider.ListContainerRequest) (*provider.ListContainerResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

share, ok := extractLinkFromScope(ctx)
if !ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strings"

"github.com/cs3org/reva/v2/pkg/share"
"github.com/cs3org/reva/v2/pkg/utils/resourceid"
"google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
gstatus "google.golang.org/grpc/status"
Expand Down Expand Up @@ -105,6 +106,10 @@ func New(gateway gateway.GatewayAPIClient, c collaboration.CollaborationAPIClien
}

func (s *service) SetArbitraryMetadata(ctx context.Context, req *provider.SetArbitraryMetadataRequest) (*provider.SetArbitraryMetadataResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

receivedShare, rpcStatus, err := s.resolveReference(ctx, req.Ref)
appctx.GetLogger(ctx).Debug().
Interface("ref", req.Ref).
Expand All @@ -129,6 +134,10 @@ func (s *service) SetArbitraryMetadata(ctx context.Context, req *provider.SetArb
}

func (s *service) UnsetArbitraryMetadata(ctx context.Context, req *provider.UnsetArbitraryMetadataRequest) (*provider.UnsetArbitraryMetadataResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

receivedShare, rpcStatus, err := s.resolveReference(ctx, req.Ref)
appctx.GetLogger(ctx).Debug().
Interface("ref", req.Ref).
Expand All @@ -153,6 +162,10 @@ func (s *service) UnsetArbitraryMetadata(ctx context.Context, req *provider.Unse
}

func (s *service) InitiateFileDownload(ctx context.Context, req *provider.InitiateFileDownloadRequest) (*provider.InitiateFileDownloadResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

receivedShare, rpcStatus, err := s.resolveReference(ctx, req.Ref)
appctx.GetLogger(ctx).Debug().
Interface("ref", req.Ref).
Expand Down Expand Up @@ -205,6 +218,10 @@ func (s *service) InitiateFileDownload(ctx context.Context, req *provider.Initia
}

func (s *service) InitiateFileUpload(ctx context.Context, req *provider.InitiateFileUploadRequest) (*provider.InitiateFileUploadResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

receivedShare, rpcStatus, err := s.resolveReference(ctx, req.Ref)
appctx.GetLogger(ctx).Debug().
Interface("ref", req.Ref).
Expand Down Expand Up @@ -289,6 +306,14 @@ func (s *service) CreateStorageSpace(ctx context.Context, req *provider.CreateSt
// should be found.

func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSpacesRequest) (*provider.ListStorageSpacesResponse, error) {
for i, f := range req.Filters {
if f.Type == provider.ListStorageSpacesRequest_Filter_TYPE_ID {
id, _ := resourceid.StorageIDUnwrap(f.GetId().GetOpaqueId())
req.Filters[i].Term = &provider.ListStorageSpacesRequest_Filter_Id{Id: &provider.StorageSpaceId{OpaqueId: id}}
break
}
}

spaceTypes := map[string]struct{}{}
var exists = struct{}{}
var fetchShares bool
Expand Down Expand Up @@ -473,6 +498,10 @@ func (s *service) DeleteStorageSpace(ctx context.Context, req *provider.DeleteSt
}

func (s *service) CreateContainer(ctx context.Context, req *provider.CreateContainerRequest) (*provider.CreateContainerResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

receivedShare, rpcStatus, err := s.resolveReference(ctx, req.Ref)
appctx.GetLogger(ctx).Debug().
Interface("ref", req.Ref).
Expand All @@ -496,6 +525,10 @@ func (s *service) CreateContainer(ctx context.Context, req *provider.CreateConta
}

func (s *service) Delete(ctx context.Context, req *provider.DeleteRequest) (*provider.DeleteResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

receivedShare, rpcStatus, err := s.resolveReference(ctx, req.Ref)
appctx.GetLogger(ctx).Debug().
Interface("ref", req.Ref).
Expand Down Expand Up @@ -533,6 +566,12 @@ func (s *service) Delete(ctx context.Context, req *provider.DeleteRequest) (*pro
}

func (s *service) Move(ctx context.Context, req *provider.MoveRequest) (*provider.MoveResponse, error) {
if req.Source.GetResourceId() != nil {
req.Source.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Source.ResourceId.StorageId)
}
if req.Destination.GetResourceId() != nil {
req.Destination.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Destination.ResourceId.StorageId)
}

appctx.GetLogger(ctx).Debug().
Interface("source", req.Source).
Expand Down Expand Up @@ -631,6 +670,10 @@ func (s *service) Unlock(ctx context.Context, req *provider.UnlockRequest) (*pro
}

func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provider.StatResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

if isVirtualRoot(req.Ref.ResourceId) && (req.Ref.Path == "" || req.Ref.Path == ".") {
receivedShares, shareMd, err := s.fetchShares(ctx)
if err != nil {
Expand Down Expand Up @@ -712,6 +755,10 @@ func isVirtualRoot(id *provider.ResourceId) bool {
})
}
func (s *service) ListContainer(ctx context.Context, req *provider.ListContainerRequest) (*provider.ListContainerResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

if isVirtualRoot(req.Ref.ResourceId) {
// The root is empty, it is filled by mountpoints
return &provider.ListContainerResponse{
Expand Down Expand Up @@ -744,6 +791,10 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer
})
}
func (s *service) ListFileVersions(ctx context.Context, req *provider.ListFileVersionsRequest) (*provider.ListFileVersionsResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

receivedShare, rpcStatus, err := s.resolveReference(ctx, req.Ref)
appctx.GetLogger(ctx).Debug().
Interface("ref", req.Ref).
Expand All @@ -768,6 +819,10 @@ func (s *service) ListFileVersions(ctx context.Context, req *provider.ListFileVe
}

func (s *service) RestoreFileVersion(ctx context.Context, req *provider.RestoreFileVersionRequest) (*provider.RestoreFileVersionResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

receivedShare, rpcStatus, err := s.resolveReference(ctx, req.Ref)
appctx.GetLogger(ctx).Debug().
Interface("ref", req.Ref).
Expand Down Expand Up @@ -841,6 +896,10 @@ func (s *service) TouchFile(ctx context.Context, req *provider.TouchFileRequest)

// GetQuota returns 0 free quota. It is virtual ... the shares may have a different quota ...
func (s *service) GetQuota(ctx context.Context, req *provider.GetQuotaRequest) (*provider.GetQuotaResponse, error) {
if req.Ref.GetResourceId() != nil {
req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId)
}

// FIXME use req.Ref to get real quota
return &provider.GetQuotaResponse{
Status: status.NewOK(ctx),
Expand Down
Loading

0 comments on commit 753492b

Please sign in to comment.