diff --git a/.drone.env b/.drone.env index eeee12919e..f8dfbf4ad6 100644 --- a/.drone.env +++ b/.drone.env @@ -1,3 +1,3 @@ # The test runner source for API tests -CORE_COMMITID=b262ada63569e241f9cee451c23f267512fd48b2 -CORE_BRANCH=master +CORE_COMMITID=69d8f1e0027d5763ef7d011aaff2df33beff16d +CORE_BRANCH=EscapeDollarOcisEdition diff --git a/changelog/unreleased/fake-providerids.md b/changelog/unreleased/fake-providerids.md new file mode 100644 index 0000000000..f26c399d86 --- /dev/null +++ b/changelog/unreleased/fake-providerids.md @@ -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 diff --git a/internal/grpc/services/publicstorageprovider/publicstorageprovider.go b/internal/grpc/services/publicstorageprovider/publicstorageprovider.go index 8dfb62c65b..c7b1596e57 100644 --- a/internal/grpc/services/publicstorageprovider/publicstorageprovider.go +++ b/internal/grpc/services/publicstorageprovider/publicstorageprovider.go @@ -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" @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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 { @@ -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: @@ -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{} @@ -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() @@ -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: @@ -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() @@ -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() @@ -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() @@ -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 { diff --git a/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go b/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go index 87395a6a24..18323a344c 100644 --- a/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go +++ b/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go @@ -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" @@ -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). @@ -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). @@ -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). @@ -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). @@ -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 @@ -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). @@ -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). @@ -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). @@ -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 { @@ -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{ @@ -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). @@ -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). @@ -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), diff --git a/internal/grpc/services/storageprovider/storageprovider.go b/internal/grpc/services/storageprovider/storageprovider.go index d81661273d..8ab295ee48 100644 --- a/internal/grpc/services/storageprovider/storageprovider.go +++ b/internal/grpc/services/storageprovider/storageprovider.go @@ -43,6 +43,7 @@ import ( "github.com/cs3org/reva/v2/pkg/storage/fs/registry" 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" @@ -61,6 +62,7 @@ type config struct { ExposeDataServer bool `mapstructure:"expose_data_server" docs:"false;Whether to expose data server."` // if true the client will be able to upload/download directly to it AvailableXS map[string]uint32 `mapstructure:"available_checksums" docs:"nil;List of available checksums."` CustomMimeTypesJSON string `mapstructure:"custom_mimetypes_json" docs:"nil;An optional mapping file with the list of supported custom file extensions and corresponding mime types."` + MountID string `mapstructure:"mount_id"` } func (c *config) init() { @@ -202,6 +204,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) + } + ctx = ctxpkg.ContextSetLockID(ctx, req.LockId) err := s.storage.SetArbitraryMetadata(ctx, req.Ref, req.ArbitraryMetadata) @@ -212,6 +218,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) + } + ctx = ctxpkg.ContextSetLockID(ctx, req.LockId) err := s.storage.UnsetArbitraryMetadata(ctx, req.Ref, req.ArbitraryMetadataKeys) @@ -223,6 +233,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) + } + err := s.storage.SetLock(ctx, req.Ref, req.Lock) return &provider.SetLockResponse{ @@ -232,6 +246,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) + } + lock, err := s.storage.GetLock(ctx, req.Ref) return &provider.GetLockResponse{ @@ -242,6 +260,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) + } + err := s.storage.RefreshLock(ctx, req.Ref, req.Lock) return &provider.RefreshLockResponse{ @@ -251,6 +273,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) + } + err := s.storage.Unlock(ctx, req.Ref, req.Lock) return &provider.UnlockResponse{ @@ -259,6 +285,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) + } + // TODO(labkode): maybe add some checks before download starts? eg. check permissions? // TODO(labkode): maybe add short-lived token? // We now simply point the client to the data server. @@ -289,6 +319,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) + } + // TODO(labkode): same considerations as download log := appctx.GetLogger(ctx) if req.Ref.GetPath() == "/" { @@ -404,6 +438,10 @@ func (s *service) InitiateFileUpload(ctx context.Context, req *provider.Initiate } func (s *service) GetPath(ctx context.Context, req *provider.GetPathRequest) (*provider.GetPathResponse, error) { + if req.GetResourceId() != nil { + req.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.ResourceId.StorageId) + } + // TODO(labkode): check that the storage ID is the same as the storage provider id. fn, err := s.storage.GetPathByID(ctx, req.ResourceId) if err != nil { @@ -472,6 +510,14 @@ func (s *service) CreateStorageSpace(ctx context.Context, req *provider.CreateSt } 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 + } + } + log := appctx.GetLogger(ctx) spaces, err := s.storage.ListStorageSpaces(ctx, req.Filters) @@ -497,10 +543,13 @@ func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStora }, nil } - for i := range spaces { - if spaces[i].Id == nil || spaces[i].Id.OpaqueId == "" { - log.Error().Str("service", "storageprovider").Str("driver", s.conf.Driver).Interface("space", spaces[i]).Msg("space is missing space id and root id") + for _, sp := range spaces { + if sp.Id == nil || sp.Id.OpaqueId == "" { + log.Error().Str("service", "storageprovider").Str("driver", s.conf.Driver).Interface("space", sp).Msg("space is missing space id and root id") + continue } + sp.Id.OpaqueId = resourceid.StorageIDWrap(sp.Id.GetOpaqueId(), s.conf.MountID) + sp.Root.StorageId = resourceid.StorageIDWrap(sp.Root.GetStorageId(), s.conf.MountID) } return &provider.ListStorageSpacesResponse{ @@ -510,6 +559,11 @@ func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStora } func (s *service) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) { + if req.GetStorageSpace().GetId() != nil { + req.StorageSpace.Id.OpaqueId, _ = resourceid.StorageIDUnwrap(req.StorageSpace.Id.OpaqueId) + req.StorageSpace.Root.StorageId, _ = resourceid.StorageIDUnwrap(req.StorageSpace.Root.StorageId) + } + res, err := s.storage.UpdateStorageSpace(ctx, req) if err != nil { appctx.GetLogger(ctx). @@ -519,10 +573,15 @@ func (s *service) UpdateStorageSpace(ctx context.Context, req *provider.UpdateSt Msg("failed to update storage space") return nil, err } + res.StorageSpace.Id.OpaqueId = resourceid.StorageIDWrap(res.StorageSpace.Id.GetOpaqueId(), s.conf.MountID) return res, nil } func (s *service) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorageSpaceRequest) (*provider.DeleteStorageSpaceResponse, error) { + if req.GetId() != nil { + req.Id.OpaqueId, _ = resourceid.StorageIDUnwrap(req.Id.OpaqueId) + } + if err := s.storage.DeleteStorageSpace(ctx, req); err != nil { var st *rpc.Status switch err.(type) { @@ -553,6 +612,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) + } + // FIXME these should be part of the CreateContainerRequest object if req.Opaque != nil { if e, ok := req.Opaque.Map["lockid"]; ok && e.Decoder == "plain" { @@ -568,6 +631,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) + } + // FIXME these should be part of the TouchFileRequest object if req.Opaque != nil { if e, ok := req.Opaque.Map["lockid"]; ok && e.Decoder == "plain" { @@ -583,6 +650,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) + } + if req.Ref.GetPath() == "/" { return &provider.DeleteResponse{ Status: status.NewInternal(ctx, "can't delete mount path"), @@ -608,6 +679,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 = ctxpkg.ContextSetLockID(ctx, req.LockId) err := s.storage.Move(ctx, req.Source, req.Destination) @@ -618,6 +696,11 @@ func (s *service) Move(ctx context.Context, req *provider.MoveRequest) (*provide } func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provider.StatResponse, error) { + var providerID string + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, providerID = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + ctx, span := rtrace.Provider.Tracer("reva").Start(ctx, "stat") defer span.End() @@ -627,14 +710,27 @@ func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provide }) md, err := s.storage.GetMD(ctx, req.Ref, req.ArbitraryMetadataKeys) + if err != nil { + return &provider.StatResponse{ + Status: status.NewStatusFromErrType(ctx, "stat", err), + }, nil + } + if providerID == "" { + providerID = s.conf.MountID + } + md.Id.StorageId = resourceid.StorageIDWrap(md.Id.GetStorageId(), providerID) return &provider.StatResponse{ - Status: status.NewStatusFromErrType(ctx, "stat", err), + Status: status.NewOK(ctx), Info: md, }, nil } func (s *service) ListContainerStream(req *provider.ListContainerStreamRequest, ss provider.ProviderAPI_ListContainerStreamServer) error { + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + ctx := ss.Context() log := appctx.GetLogger(ctx) @@ -679,16 +775,30 @@ func (s *service) ListContainerStream(req *provider.ListContainerStreamRequest, } func (s *service) ListContainer(ctx context.Context, req *provider.ListContainerRequest) (*provider.ListContainerResponse, error) { - mds, err := s.storage.ListFolder(ctx, req.Ref, req.ArbitraryMetadataKeys) + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + mds, err := s.storage.ListFolder(ctx, req.Ref, req.ArbitraryMetadataKeys) res := &provider.ListContainerResponse{ Status: status.NewStatusFromErrType(ctx, "list container", err), Infos: mds, } + if err != nil { + return res, nil + } + + for _, i := range res.Infos { + i.Id.StorageId = resourceid.StorageIDWrap(i.Id.GetStorageId(), s.conf.MountID) + } return res, nil } 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) + } + revs, err := s.storage.ListRevisions(ctx, req.Ref) sort.Sort(descendingMtime(revs)) @@ -700,6 +810,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) + } + ctx = ctxpkg.ContextSetLockID(ctx, req.LockId) err := s.storage.RestoreRevision(ctx, req.Ref, req.Key) @@ -710,6 +824,10 @@ func (s *service) RestoreFileVersion(ctx context.Context, req *provider.RestoreF } func (s *service) ListRecycleStream(req *provider.ListRecycleStreamRequest, ss provider.ProviderAPI_ListRecycleStreamServer) error { + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + ctx := ss.Context() log := appctx.GetLogger(ctx) @@ -756,6 +874,10 @@ func (s *service) ListRecycleStream(req *provider.ListRecycleStreamRequest, ss p } func (s *service) ListRecycle(ctx context.Context, req *provider.ListRecycleRequest) (*provider.ListRecycleResponse, error) { + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + key, itemPath := router.ShiftPath(req.Key) items, err := s.storage.ListRecycle(ctx, req.Ref, key, itemPath) if err != nil { @@ -780,6 +902,11 @@ func (s *service) ListRecycle(ctx context.Context, req *provider.ListRecycleRequ }, nil } + for _, i := range items { + if i.Ref != nil && i.Ref.ResourceId != nil { + i.Ref.ResourceId.StorageId = resourceid.StorageIDWrap(i.Ref.GetResourceId().GetStorageId(), s.conf.MountID) + } + } res := &provider.ListRecycleResponse{ Status: status.NewOK(ctx), RecycleItems: items, @@ -788,6 +915,13 @@ func (s *service) ListRecycle(ctx context.Context, req *provider.ListRecycleRequ } func (s *service) RestoreRecycleItem(ctx context.Context, req *provider.RestoreRecycleItemRequest) (*provider.RestoreRecycleItemResponse, error) { + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + if req.RestoreRef.GetResourceId() != nil { + req.RestoreRef.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.RestoreRef.ResourceId.StorageId) + } + ctx = ctxpkg.ContextSetLockID(ctx, req.LockId) // TODO(labkode): CRITICAL: fill recycle info with storage provider. @@ -801,6 +935,10 @@ func (s *service) RestoreRecycleItem(ctx context.Context, req *provider.RestoreR } func (s *service) PurgeRecycle(ctx context.Context, req *provider.PurgeRecycleRequest) (*provider.PurgeRecycleResponse, error) { + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + // FIXME these should be part of the PurgeRecycleRequest object if req.Opaque != nil { if e, ok := req.Opaque.Map["lockid"]; ok && e.Decoder == "plain" { @@ -846,6 +984,10 @@ func (s *service) PurgeRecycle(ctx context.Context, req *provider.PurgeRecycleRe } func (s *service) ListGrants(ctx context.Context, req *provider.ListGrantsRequest) (*provider.ListGrantsResponse, error) { + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + grants, err := s.storage.ListGrants(ctx, req.Ref) if err != nil { var st *rpc.Status @@ -876,6 +1018,10 @@ func (s *service) ListGrants(ctx context.Context, req *provider.ListGrantsReques } func (s *service) DenyGrant(ctx context.Context, req *provider.DenyGrantRequest) (*provider.DenyGrantResponse, error) { + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + // check grantee type is valid if req.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_INVALID { return &provider.DenyGrantResponse{ @@ -917,6 +1063,10 @@ func (s *service) DenyGrant(ctx context.Context, req *provider.DenyGrantRequest) } func (s *service) AddGrant(ctx context.Context, req *provider.AddGrantRequest) (*provider.AddGrantResponse, error) { + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + ctx = ctxpkg.ContextSetLockID(ctx, req.LockId) // TODO: update CS3 APIs @@ -943,6 +1093,10 @@ func (s *service) AddGrant(ctx context.Context, req *provider.AddGrantRequest) ( } func (s *service) UpdateGrant(ctx context.Context, req *provider.UpdateGrantRequest) (*provider.UpdateGrantResponse, error) { + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + // FIXME these should be part of the UpdateGrantRequest object if req.Opaque != nil { if e, ok := req.Opaque.Map["lockid"]; ok && e.Decoder == "plain" { @@ -965,6 +1119,10 @@ func (s *service) UpdateGrant(ctx context.Context, req *provider.UpdateGrantRequ } func (s *service) RemoveGrant(ctx context.Context, req *provider.RemoveGrantRequest) (*provider.RemoveGrantResponse, error) { + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + ctx = ctxpkg.ContextSetLockID(ctx, req.LockId) // check targetType is valid @@ -982,6 +1140,10 @@ func (s *service) RemoveGrant(ctx context.Context, req *provider.RemoveGrantRequ } func (s *service) CreateReference(ctx context.Context, req *provider.CreateReferenceRequest) (*provider.CreateReferenceResponse, error) { + if req.Ref.GetResourceId() != nil { + req.Ref.ResourceId.StorageId, _ = resourceid.StorageIDUnwrap(req.Ref.ResourceId.StorageId) + } + log := appctx.GetLogger(ctx) // parse uri is valid @@ -1025,6 +1187,10 @@ func (s *service) CreateSymlink(ctx context.Context, req *provider.CreateSymlink } 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) + } + total, used, remaining, err := s.storage.GetQuota(ctx, req.Ref) if err != nil { var st *rpc.Status diff --git a/internal/http/services/owncloud/ocs/conversions/main.go b/internal/http/services/owncloud/ocs/conversions/main.go index 9abf695cec..ef087fdf53 100644 --- a/internal/http/services/owncloud/ocs/conversions/main.go +++ b/internal/http/services/owncloud/ocs/conversions/main.go @@ -54,6 +54,12 @@ const ( // ShareTypeSpaceMembership represents an action regarding space members ShareTypeSpaceMembership ShareType = 7 + + // ShareWithUserTypeUser represents a normal user + ShareWithUserTypeUser ShareWithUserType = 0 + + // ShareWithUserTypeGuest represents a guest user + ShareWithUserTypeGuest ShareWithUserType = 1 ) // ResourceType indicates the OCS type of the resource @@ -78,6 +84,9 @@ func (rt ResourceType) String() (s string) { // ShareType denotes a type of share type ShareType int +// ShareWithUserType denotes a type of user +type ShareWithUserType int + // ShareData represents https://doc.owncloud.com/server/developer_manual/core/ocs-share-api.html#response-attributes-1 type ShareData struct { // TODO int? @@ -130,6 +139,10 @@ type ShareData struct { // - a UID (user id) if the share is shared with a user. // - a password for public links ShareWith string `json:"share_with,omitempty" xml:"share_with,omitempty"` + // The type of user + // - 0 = normal user + // - 1 = guest account + ShareWithUserType ShareWithUserType `json:"share_with_user_type" xml:"share_with_user_type"` // The display name of the share recipient ShareWithDisplayname string `json:"share_with_displayname,omitempty" xml:"share_with_displayname,omitempty"` // Additional info to identify the share recipient, eg. the email or username @@ -206,6 +219,11 @@ func CS3Share2ShareData(ctx context.Context, share *collaboration.Share) (*Share if share.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_USER { sd.ShareType = ShareTypeUser sd.ShareWith = LocalUserIDToString(share.Grantee.GetUserId()) + if share.GetGrantee().GetUserId().GetType() == userpb.UserType_USER_TYPE_LIGHTWEIGHT { + sd.ShareWithUserType = ShareWithUserTypeGuest + } else { + sd.ShareWithUserType = ShareWithUserTypeUser + } } else if share.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_GROUP { sd.ShareType = ShareTypeGroup sd.ShareWith = LocalGroupIDToString(share.Grantee.GetGroupId()) diff --git a/pkg/utils/resourceid/owncloud.go b/pkg/utils/resourceid/owncloud.go index c6041f902c..d566f1c8b3 100644 --- a/pkg/utils/resourceid/owncloud.go +++ b/pkg/utils/resourceid/owncloud.go @@ -27,44 +27,63 @@ import ( ) const ( - idDelimiter string = "!" + _idDelimiter string = "!" + _providerDelimiter string = "$" ) +// StorageIDUnwrap unwraps the 'encoded' into the storageID and the storageProviderID +func StorageIDUnwrap(s string) (sid string, spid string) { + spid, sid, err := unwrap(s, _providerDelimiter) + if err != nil { + // assume it's only a storageid + return s, "" + } + return sid, spid +} + // OwnCloudResourceIDUnwrap returns the wrapped resource id // by OwnCloudResourceIDWrap and returns nil if not possible func OwnCloudResourceIDUnwrap(rid string) *provider.ResourceId { - id, err := unwrap(rid) + sid, oid, err := unwrap(rid, _idDelimiter) if err != nil { return nil } - return id + return &provider.ResourceId{ + StorageId: sid, + OpaqueId: oid, + } } -func unwrap(rid string) (*provider.ResourceId, error) { - parts := strings.SplitN(rid, idDelimiter, 2) +func unwrap(rid string, delimiter string) (string, string, error) { + parts := strings.SplitN(rid, delimiter, 2) if len(parts) != 2 { - return nil, errors.New("could not find two parts with given delimiter") + return "", "", errors.New("could not find two parts with given delimiter") } if !utf8.ValidString(parts[0]) || !utf8.ValidString(parts[1]) { - return nil, errors.New("invalid utf8 string found") + return "", "", errors.New("invalid utf8 string found") } - return &provider.ResourceId{ - StorageId: parts[0], - OpaqueId: parts[1], - }, nil + return parts[0], parts[1], nil } // OwnCloudResourceIDWrap wraps a resource id into a xml safe string // which can then be passed to the outside world func OwnCloudResourceIDWrap(r *provider.ResourceId) string { - return wrap(r.StorageId, r.OpaqueId) + return wrap(r.StorageId, r.OpaqueId, _idDelimiter) } -// The storageID and OpaqueID need to be separated by a delimiter -// this delimiter should be Url safe -// we use a reserved character -func wrap(sid string, oid string) string { - return sid + idDelimiter + oid +// StorageIDWrap wraps a storageid and storageproviderid into a xml safe string +// which can then be passed to the outside world +func StorageIDWrap(sid string, spid string) string { + return wrap(spid, sid, _providerDelimiter) +} + +// returns second argument in case the first is empty (without adding the delimiter) +// the delimiter should be Url safe (we use a reserved character) +func wrap(first string, second string, delimiter string) string { + if first == "" { + return second + } + return first + delimiter + second } diff --git a/pkg/utils/resourceid/owncloud_test.go b/pkg/utils/resourceid/owncloud_test.go index e87e4bea4f..775ccd314c 100644 --- a/pkg/utils/resourceid/owncloud_test.go +++ b/pkg/utils/resourceid/owncloud_test.go @@ -21,18 +21,17 @@ import ( "testing" providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" - "github.com/cs3org/reva/v2/pkg/utils" ) func BenchmarkWrap(b *testing.B) { for i := 0; i < b.N; i++ { - _ = wrap("storageid", "opaqueid") + _ = wrap("storageid", "opaqueid", "!") } } func TestWrap(t *testing.T) { - expected := "storageid" + idDelimiter + "opaqueid" - wrapped := wrap("storageid", "opaqueid") + expected := "storageid!opaqueid" + wrapped := wrap("storageid", "opaqueid", "!") if wrapped != expected { t.Errorf("wrapped id doesn't have the expected format: got %s expected %s", wrapped, expected) @@ -40,7 +39,7 @@ func TestWrap(t *testing.T) { } func TestWrapResourceID(t *testing.T) { - expected := "storageid" + idDelimiter + "opaqueid" + expected := "storageid" + _idDelimiter + "opaqueid" wrapped := OwnCloudResourceIDWrap(&providerv1beta1.ResourceId{StorageId: "storageid", OpaqueId: "opaqueid"}) if wrapped != expected { @@ -48,21 +47,47 @@ func TestWrapResourceID(t *testing.T) { } } +func TestWrapStorageID(t *testing.T) { + expected := "providerid" + _providerDelimiter + "storageid" + wrapped := StorageIDWrap("storageid", "providerid") + + if wrapped != expected { + t.Errorf("wrapped id doesn't have the expected format: got %s expected %s", wrapped, expected) + } +} + +func TestUnwrap(t *testing.T) { + expected := []string{"storageid", "opaqueid"} + sid, oid, err := unwrap("storageid!opaqueid", "!") + if err != nil { + t.Errorf("unwrap returned an error: %v", err) + } + + if sid != expected[0] || oid != expected[1] { + t.Errorf("wrapped id doesn't have the expected format: got (%s, %s) expected %s", sid, oid, expected) + } +} + func BenchmarkUnwrap(b *testing.B) { + delimiter := "!" for i := 0; i < b.N; i++ { - _, _ = unwrap("storageid" + idDelimiter + "opaqueid") + _, _, _ = unwrap("storageid"+delimiter+"opaqueid", delimiter) } } -func TestUnwrap(t *testing.T) { +func TestUnwrapResourceID(t *testing.T) { tests := []struct { input string expected *providerv1beta1.ResourceId }{ { - "storageid" + idDelimiter + "opaqueid", + "storageid" + _idDelimiter + "opaqueid", &providerv1beta1.ResourceId{StorageId: "storageid", OpaqueId: "opaqueid"}, }, + { + "providerid" + _providerDelimiter + "storageid" + _idDelimiter + "opaqueid", + &providerv1beta1.ResourceId{StorageId: "providerid$storageid", OpaqueId: "opaqueid"}, + }, { "", nil, @@ -75,13 +100,54 @@ func TestUnwrap(t *testing.T) { for _, tt := range tests { rid := OwnCloudResourceIDUnwrap(tt.input) - - if tt.expected == nil { + switch { + case tt.expected == nil: if rid != nil { t.Errorf("Expected unwrap to return nil, got %v", rid) } - } else if !utils.ResourceIDEqual(rid, tt.expected) { - t.Error("StorageID or OpaqueID doesn't match") + case rid == nil: + t.Errorf("ResourceID should not be nil. Expected %v", tt.expected) + case rid.StorageId != tt.expected.StorageId: + t.Errorf("StorageIDs don't match. Expected %v, got %v", tt.expected, rid) + case rid.OpaqueId != tt.expected.OpaqueId: + t.Errorf("StorageIDs don't match. Expected %v, got %v", tt.expected, rid) + } + } + +} + +func TestUnwrapStorageID(t *testing.T) { + tests := []struct { + input string + expected []string + }{ + { + "providerid" + _providerDelimiter + "storageid", + []string{"storageid", "providerid"}, + }, + { + "", + nil, + }, + { + "storageid", + []string{"storageid", ""}, + }, + } + + for _, tt := range tests { + sid, spid := StorageIDUnwrap(tt.input) + switch { + case tt.expected == nil: + if sid != "" || spid != "" { + t.Errorf("Expected unwrap to return nil, got '%s' '%s'", sid, spid) + } + case len(tt.expected) != 2: + t.Error("testcase won't work with len(expected) != 2. Avoiding panic") + case sid != tt.expected[0]: + t.Errorf("StorageID doesn't match, expected '%s' got '%s'", tt.expected[0], sid) + case spid != tt.expected[1]: + t.Errorf("ProviderID doesn't match, expected '%s' got '%s'", tt.expected[1], spid) } } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 4e31bd9c17..1a8266ed99 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -38,6 +38,7 @@ import ( types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/v2/pkg/registry" "github.com/cs3org/reva/v2/pkg/registry/memory" + "github.com/cs3org/reva/v2/pkg/utils/resourceid" "github.com/golang/protobuf/proto" "google.golang.org/protobuf/encoding/protojson" ) @@ -334,7 +335,8 @@ func SplitStorageSpaceID(ssid string) (storageid, nodeid string, err error) { } parts := strings.SplitN(ssid, spaceIDDelimiter, 2) if len(parts) == 1 { - return parts[0], parts[0], nil + p, _ := resourceid.StorageIDUnwrap(parts[0]) + return parts[0], p, nil } return parts[0], parts[1], nil } diff --git a/tests/oc-integration-tests/drone/storage-publiclink.toml b/tests/oc-integration-tests/drone/storage-publiclink.toml index 4cb5fc8e54..6786bca653 100644 --- a/tests/oc-integration-tests/drone/storage-publiclink.toml +++ b/tests/oc-integration-tests/drone/storage-publiclink.toml @@ -12,4 +12,5 @@ address = "0.0.0.0:13000" # we have a locally running dataprovider [grpc.services.publicstorageprovider] gateway_addr = "0.0.0.0:19000" +mount_id = "7993447f-687f-490d-875c-ac95e89a62a4" diff --git a/tests/oc-integration-tests/drone/storage-shares.toml b/tests/oc-integration-tests/drone/storage-shares.toml index 76a5438ab3..49351fe30e 100644 --- a/tests/oc-integration-tests/drone/storage-shares.toml +++ b/tests/oc-integration-tests/drone/storage-shares.toml @@ -10,3 +10,4 @@ address = "0.0.0.0:14000" # we have a locally running dataprovider [grpc.services.sharesstorageprovider] usershareprovidersvc = "localhost:17000" +mount_id = "a0ca6a90-a365-4782-871e-d44447bbc668" diff --git a/tests/oc-integration-tests/drone/storage-users-ocis.toml b/tests/oc-integration-tests/drone/storage-users-ocis.toml index 490b431cfc..0fc1662230 100644 --- a/tests/oc-integration-tests/drone/storage-users-ocis.toml +++ b/tests/oc-integration-tests/drone/storage-users-ocis.toml @@ -18,6 +18,7 @@ driver = "ocis" expose_data_server = true data_server_url = "http://revad-services:11001/data" gateway_addr = "0.0.0.0:19000" +mount_id = "1284d238-aa92-42ce-bdc4-0b0000009157" [grpc.services.storageprovider.drivers.ocis] root = "/drone/src/tmp/reva/data" diff --git a/tests/oc-integration-tests/drone/storage-users-s3ng.toml b/tests/oc-integration-tests/drone/storage-users-s3ng.toml index 88b707ae45..e68e61deef 100644 --- a/tests/oc-integration-tests/drone/storage-users-s3ng.toml +++ b/tests/oc-integration-tests/drone/storage-users-s3ng.toml @@ -16,6 +16,7 @@ address = "0.0.0.0:11000" driver = "s3ng" expose_data_server = true data_server_url = "http://revad-services:11001/data" +mount_id = "1284d238-aa92-42ce-bdc4-0b0000009157" [grpc.services.storageprovider.drivers.s3ng] root = "/drone/src/tmp/reva/data" diff --git a/tests/oc-integration-tests/local/storage-publiclink.toml b/tests/oc-integration-tests/local/storage-publiclink.toml index 31f95afcfb..c8a4312f23 100644 --- a/tests/oc-integration-tests/local/storage-publiclink.toml +++ b/tests/oc-integration-tests/local/storage-publiclink.toml @@ -16,3 +16,4 @@ address = "0.0.0.0:13000" # we have a locally running dataprovider [grpc.services.publicstorageprovider] gateway_addr = "0.0.0.0:19000" +mount_id = "7993447f-687f-490d-875c-ac95e89a62a4" diff --git a/tests/oc-integration-tests/local/storage-shares.toml b/tests/oc-integration-tests/local/storage-shares.toml index 947c0b5740..f4cb857570 100644 --- a/tests/oc-integration-tests/local/storage-shares.toml +++ b/tests/oc-integration-tests/local/storage-shares.toml @@ -13,4 +13,5 @@ address = "0.0.0.0:14000" # This is a storage provider that grants direct access to the wrapped storage # we have a locally running dataprovider [grpc.services.sharesstorageprovider] -usershareprovidersvc = "0.0.0.0:17000" \ No newline at end of file +usershareprovidersvc = "0.0.0.0:17000" +mount_id = "a0ca6a90-a365-4782-871e-d44447bbc668" diff --git a/tests/oc-integration-tests/local/storage-users.toml b/tests/oc-integration-tests/local/storage-users.toml index a270504b28..9d08cd5465 100644 --- a/tests/oc-integration-tests/local/storage-users.toml +++ b/tests/oc-integration-tests/local/storage-users.toml @@ -21,6 +21,7 @@ address = "0.0.0.0:11000" driver = "ocis" expose_data_server = true data_server_url = "http://localhost:11001/data" +mount_id = "1284d238-aa92-42ce-bdc4-0b0000009157" [grpc.services.storageprovider.drivers.ocis] root = "/var/tmp/reva/data"