From 2f28fbf2c3987e032545609f7104cf678b0cfeef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 20 May 2021 22:27:03 +0000 Subject: [PATCH 01/11] switch references MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer fix nil pointers, lint Signed-off-by: Jörn Friedrich Dreyer fix versions Signed-off-by: Jörn Friedrich Dreyer always initialize Ref Signed-off-by: Jörn Friedrich Dreyer fix publicshare Signed-off-by: Jörn Friedrich Dreyer fix lint Signed-off-by: Jörn Friedrich Dreyer 'fix' paths Signed-off-by: Jörn Friedrich Dreyer add changelog Signed-off-by: Jörn Friedrich Dreyer ResourceInfo.Ref -> ResourceInfo.Path Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/change-references.md | 8 + cmd/reva/app-tokens-create.go | 8 +- cmd/reva/download.go | 10 +- cmd/reva/ls.go | 4 +- cmd/reva/mkdir.go | 4 +- cmd/reva/mv.go | 8 +- cmd/reva/ocm-share-create.go | 4 +- cmd/reva/ocm-share-list.go | 4 +- cmd/reva/open-file-in-app-provider.go | 4 +- cmd/reva/open-in-app.go | 2 +- cmd/reva/public-share-create.go | 4 +- cmd/reva/public-share-list.go | 4 +- cmd/reva/recycle-list.go | 6 +- cmd/reva/recycle-purge.go | 8 +- cmd/reva/recycle-restore.go | 6 +- cmd/reva/rm.go | 4 +- cmd/reva/share-create.go | 5 +- cmd/reva/share-list.go | 4 +- cmd/reva/stat.go | 4 +- cmd/reva/transfer-create.go | 6 +- cmd/reva/upload.go | 14 +- go.mod | 1 + go.sum | 4 +- internal/grpc/interceptors/auth/auth.go | 8 +- .../grpc/services/appprovider/appprovider.go | 2 +- internal/grpc/services/gateway/appprovider.go | 12 +- .../grpc/services/gateway/ocmshareprovider.go | 10 +- .../grpc/services/gateway/storageprovider.go | 250 ++++-------------- .../services/gateway/usershareprovider.go | 46 ++-- internal/grpc/services/ocmcore/ocmcore.go | 4 +- .../publicstorageprovider.go | 30 +-- .../storageprovider/storageprovider.go | 35 +-- internal/http/services/owncloud/ocdav/copy.go | 28 +- internal/http/services/owncloud/ocdav/dav.go | 4 +- .../http/services/owncloud/ocdav/delete.go | 4 +- internal/http/services/owncloud/ocdav/get.go | 8 +- internal/http/services/owncloud/ocdav/head.go | 4 +- .../http/services/owncloud/ocdav/mkcol.go | 4 +- internal/http/services/owncloud/ocdav/move.go | 20 +- .../http/services/owncloud/ocdav/ocdav.go | 10 +- .../http/services/owncloud/ocdav/propfind.go | 8 +- .../http/services/owncloud/ocdav/proppatch.go | 12 +- internal/http/services/owncloud/ocdav/put.go | 12 +- .../http/services/owncloud/ocdav/trashbin.go | 42 +-- internal/http/services/owncloud/ocdav/tus.go | 8 +- .../http/services/owncloud/ocdav/versions.go | 23 +- .../handlers/apps/sharing/shares/public.go | 8 +- .../handlers/apps/sharing/shares/shares.go | 38 +-- .../ocs/handlers/cloud/users/users.go | 8 +- pkg/app/app.go | 2 +- pkg/app/provider/demo/demo.go | 4 +- pkg/auth/scope/publicshare.go | 9 +- pkg/auth/scope/resourceinfo.go | 6 +- pkg/auth/scope/user.go | 6 +- pkg/cbox/publicshare/sql/sql.go | 4 +- pkg/cbox/share/sql/sql.go | 12 +- pkg/cbox/utils/conversions.go | 4 +- pkg/ocm/share/manager/json/json.go | 6 +- pkg/ocm/share/share.go | 2 +- pkg/publicshare/manager/json/json.go | 2 +- pkg/publicshare/manager/memory/memory.go | 3 +- pkg/rhttp/datatx/manager/simple/simple.go | 2 +- pkg/rhttp/datatx/utils/download/download.go | 2 +- pkg/sdk/action/download.go | 8 +- pkg/sdk/action/enumfiles.go | 4 +- pkg/sdk/action/fileops.go | 20 +- pkg/sdk/action/upload.go | 6 +- pkg/share/cache/cbox/cbox.go | 12 +- pkg/storage/fs/owncloud/owncloud.go | 49 ++-- pkg/storage/fs/s3/s3.go | 20 +- pkg/storage/migrate/metadata.go | 4 +- pkg/storage/migrate/shares.go | 6 +- pkg/storage/registry/static/static.go | 48 ++-- pkg/storage/registry/static/static_test.go | 36 +-- pkg/storage/storage.go | 4 +- .../utils/decomposedfs/decomposedfs.go | 4 +- .../decomposedfs_concurrency_test.go | 16 +- .../utils/decomposedfs/decomposedfs_test.go | 6 +- pkg/storage/utils/decomposedfs/grants_test.go | 6 +- pkg/storage/utils/decomposedfs/lookup.go | 12 +- pkg/storage/utils/decomposedfs/mocks/Tree.go | 6 +- pkg/storage/utils/decomposedfs/node/node.go | 2 +- pkg/storage/utils/decomposedfs/recycle.go | 9 +- pkg/storage/utils/decomposedfs/tree/tree.go | 2 +- pkg/storage/utils/decomposedfs/upload_test.go | 6 +- pkg/storage/utils/eosfs/eosfs.go | 35 +-- pkg/storage/utils/localfs/localfs.go | 30 +-- pkg/token/manager/demo/demo_test.go | 6 +- pkg/utils/utils.go | 4 +- .../integration/grpc/storageprovider_test.go | 53 ++-- 90 files changed, 391 insertions(+), 851 deletions(-) create mode 100644 changelog/unreleased/change-references.md diff --git a/changelog/unreleased/change-references.md b/changelog/unreleased/change-references.md new file mode 100644 index 0000000000..cbfdf0f0c4 --- /dev/null +++ b/changelog/unreleased/change-references.md @@ -0,0 +1,8 @@ +Change: Different type of references + +We unified the `Reference_Id` end `Reference_Path` types to a combined `Reference` that contains both: +- id based properties that can identify a node using a `storage_id` and `node_id` +- a `path` property that can be used to represent absolute paths as well as paths relative to the id based properties. +While this is a breaking change it allows more flexible passing of references. + +https://github.com/cs3org/reva/pull/1721 \ No newline at end of file diff --git a/cmd/reva/app-tokens-create.go b/cmd/reva/app-tokens-create.go index f23295f5e7..9b5a0d46f7 100644 --- a/cmd/reva/app-tokens-create.go +++ b/cmd/reva/app-tokens-create.go @@ -213,13 +213,7 @@ func getPathScope(ctx context.Context, client gateway.GatewayAPIClient, path, pe return nil, err } - statResponse, err := client.Stat(ctx, &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: path, - }, - }, - }) + statResponse, err := client.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: path}}) if err != nil { return nil, err diff --git a/cmd/reva/download.go b/cmd/reva/download.go index 53b38a098b..7dcb383a2c 100644 --- a/cmd/reva/download.go +++ b/cmd/reva/download.go @@ -55,9 +55,7 @@ func downloadCommand() *command { return err } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: remote}, - } + ref := &provider.Reference{Path: remote} req1 := &provider.StatRequest{Ref: ref} ctx := getAuthContext() res1, err := client.Stat(ctx, req1) @@ -71,11 +69,7 @@ func downloadCommand() *command { info := res1.Info req2 := &provider.InitiateFileDownloadRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: remote, - }, - }, + Ref: &provider.Reference{Path: remote}, } res, err := client.InitiateFileDownload(ctx, req2) if err != nil { diff --git a/cmd/reva/ls.go b/cmd/reva/ls.go index fa93fd9517..d2201058ae 100644 --- a/cmd/reva/ls.go +++ b/cmd/reva/ls.go @@ -51,9 +51,7 @@ func lsCommand() *command { return err } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - } + ref := &provider.Reference{Path: fn} req := &provider.ListContainerRequest{Ref: ref} ctx := getAuthContext() diff --git a/cmd/reva/mkdir.go b/cmd/reva/mkdir.go index d98b474319..c81e7560d6 100644 --- a/cmd/reva/mkdir.go +++ b/cmd/reva/mkdir.go @@ -43,9 +43,7 @@ func mkdirCommand() *command { return err } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - } + ref := &provider.Reference{Path: fn} req := &provider.CreateContainerRequest{Ref: ref} res, err := client.CreateContainer(ctx, req) if err != nil { diff --git a/cmd/reva/mv.go b/cmd/reva/mv.go index bacb13aeb6..72a9bd09ef 100644 --- a/cmd/reva/mv.go +++ b/cmd/reva/mv.go @@ -44,12 +44,8 @@ func moveCommand() *command { return err } - sourceRef := &provider.Reference{ - Spec: &provider.Reference_Path{Path: src}, - } - targetRef := &provider.Reference{ - Spec: &provider.Reference_Path{Path: dst}, - } + sourceRef := &provider.Reference{Path: src} + targetRef := &provider.Reference{Path: dst} req := &provider.MoveRequest{Source: sourceRef, Destination: targetRef} res, err := client.Move(ctx, req) if err != nil { diff --git a/cmd/reva/ocm-share-create.go b/cmd/reva/ocm-share-create.go index aa83d57857..3ec838fef8 100644 --- a/cmd/reva/ocm-share-create.go +++ b/cmd/reva/ocm-share-create.go @@ -87,9 +87,7 @@ func ocmShareCreateCommand() *command { return formatError(remoteUserRes.Status) } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - } + ref := &provider.Reference{Path: fn} req := &provider.StatRequest{Ref: ref} res, err := client.Stat(ctx, req) if err != nil { diff --git a/cmd/reva/ocm-share-list.go b/cmd/reva/ocm-share-list.go index 06b8836c9b..17b0ff4106 100644 --- a/cmd/reva/ocm-share-list.go +++ b/cmd/reva/ocm-share-list.go @@ -56,9 +56,9 @@ func ocmShareListCommand() *command { if len(tokens) != 2 { return fmt.Errorf("resource id invalid") } - id := &provider.ResourceId{ + id := &provider.Reference{ StorageId: tokens[0], - OpaqueId: tokens[1], + NodeId: tokens[1], } shareRequest.Filters = []*ocm.ListOCMSharesRequest_Filter{ &ocm.ListOCMSharesRequest_Filter{ diff --git a/cmd/reva/open-file-in-app-provider.go b/cmd/reva/open-file-in-app-provider.go index 7be45c9dcf..aee37ea492 100644 --- a/cmd/reva/open-file-in-app-provider.go +++ b/cmd/reva/open-file-in-app-provider.go @@ -59,9 +59,7 @@ func openFileInAppProviderCommand() *command { return err } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: path}, - } + ref := &provider.Reference{Path: path} opaqueObj := &typespb.Opaque{ Map: map[string]*typespb.OpaqueEntry{}, diff --git a/cmd/reva/open-in-app.go b/cmd/reva/open-in-app.go index 46451bc20d..7a6712dd39 100644 --- a/cmd/reva/open-in-app.go +++ b/cmd/reva/open-in-app.go @@ -62,7 +62,7 @@ func openInAppCommand() *command { } ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: path}, + Path: path, } opaqueObj := &typespb.Opaque{ diff --git a/cmd/reva/public-share-create.go b/cmd/reva/public-share-create.go index b50af172a5..f22eac189b 100644 --- a/cmd/reva/public-share-create.go +++ b/cmd/reva/public-share-create.go @@ -53,9 +53,7 @@ func publicShareCreateCommand() *command { return err } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - } + ref := &provider.Reference{Path: fn} req := &provider.StatRequest{Ref: ref} res, err := client.Stat(ctx, req) diff --git a/cmd/reva/public-share-list.go b/cmd/reva/public-share-list.go index b8dbf322ce..1bbd4d35be 100644 --- a/cmd/reva/public-share-list.go +++ b/cmd/reva/public-share-list.go @@ -56,9 +56,9 @@ func publicShareListCommand() *command { if len(tokens) != 2 { return fmt.Errorf("resource id invalid") } - id := &provider.ResourceId{ + id := &provider.Reference{ StorageId: tokens[0], - OpaqueId: tokens[1], + NodeId: tokens[1], } shareRequest.Filters = []*link.ListPublicSharesRequest_Filter{ &link.ListPublicSharesRequest_Filter{ diff --git a/cmd/reva/recycle-list.go b/cmd/reva/recycle-list.go index 649ae48dc2..7830ca61e6 100644 --- a/cmd/reva/recycle-list.go +++ b/cmd/reva/recycle-list.go @@ -46,11 +46,7 @@ func recycleListCommand() *command { } req := &gateway.ListRecycleRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: getHomeRes.Path, - }, - }, + Ref: getHomeRes.Ref, } res, err := client.ListRecycle(ctx, req) if err != nil { diff --git a/cmd/reva/recycle-purge.go b/cmd/reva/recycle-purge.go index d33e43553f..c9f793edad 100644 --- a/cmd/reva/recycle-purge.go +++ b/cmd/reva/recycle-purge.go @@ -44,13 +44,7 @@ func recyclePurgeCommand() *command { return err } - req := &gateway.PurgeRecycleRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: getHomeRes.Path, - }, - }, - } + req := &gateway.PurgeRecycleRequest{Ref: getHomeRes.Ref} res, err := client.PurgeRecycle(ctx, req) if err != nil { diff --git a/cmd/reva/recycle-restore.go b/cmd/reva/recycle-restore.go index 5915b21387..1b62778c49 100644 --- a/cmd/reva/recycle-restore.go +++ b/cmd/reva/recycle-restore.go @@ -51,11 +51,7 @@ func recycleRestoreCommand() *command { } req := &provider.RestoreRecycleItemRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: getHomeRes.Path, - }, - }, + Ref: getHomeRes.Ref, Key: key, } diff --git a/cmd/reva/rm.go b/cmd/reva/rm.go index b596e745d0..d992564528 100644 --- a/cmd/reva/rm.go +++ b/cmd/reva/rm.go @@ -42,9 +42,7 @@ func rmCommand() *command { return err } - ref := &storageproviderv1beta1pb.Reference{ - Spec: &storageproviderv1beta1pb.Reference_Path{Path: fn}, - } + ref := &storageproviderv1beta1pb.Reference{Path: fn} req := &storageproviderv1beta1pb.DeleteRequest{Ref: ref} res, err := client.Delete(ctx, req) if err != nil { diff --git a/cmd/reva/share-create.go b/cmd/reva/share-create.go index 77194f07ab..1513569cef 100644 --- a/cmd/reva/share-create.go +++ b/cmd/reva/share-create.go @@ -63,10 +63,7 @@ func shareCreateCommand() *command { return err } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - } - + ref := &provider.Reference{Path: fn} req := &provider.StatRequest{Ref: ref} res, err := client.Stat(ctx, req) if err != nil { diff --git a/cmd/reva/share-list.go b/cmd/reva/share-list.go index 73b005d0cd..3b869c685f 100644 --- a/cmd/reva/share-list.go +++ b/cmd/reva/share-list.go @@ -56,9 +56,9 @@ func shareListCommand() *command { if len(tokens) != 2 { return fmt.Errorf("resource id invalid") } - id := &provider.ResourceId{ + id := &provider.Reference{ StorageId: tokens[0], - OpaqueId: tokens[1], + NodeId: tokens[1], } shareRequest.Filters = []*collaboration.ListSharesRequest_Filter{ &collaboration.ListSharesRequest_Filter{ diff --git a/cmd/reva/stat.go b/cmd/reva/stat.go index 29147038cd..c84cba9a0f 100644 --- a/cmd/reva/stat.go +++ b/cmd/reva/stat.go @@ -44,9 +44,7 @@ func statCommand() *command { return err } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - } + ref := &provider.Reference{Path: fn} req := &provider.StatRequest{Ref: ref} res, err := client.Stat(ctx, req) if err != nil { diff --git a/cmd/reva/transfer-create.go b/cmd/reva/transfer-create.go index 308c1b5438..f72d49c336 100644 --- a/cmd/reva/transfer-create.go +++ b/cmd/reva/transfer-create.go @@ -78,11 +78,7 @@ func transferCreateCommand() *command { // verify resource stats statReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: fn, - }, - }, + Ref: &provider.Reference{Path: fn}, } statRes, err := client.Stat(ctx, statReq) if err != nil { diff --git a/cmd/reva/upload.go b/cmd/reva/upload.go index 56ca5d8db4..335de6ac9f 100644 --- a/cmd/reva/upload.go +++ b/cmd/reva/upload.go @@ -92,11 +92,7 @@ func uploadCommand() *command { } req := &provider.InitiateFileUploadRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: target, - }, - }, + Ref: &provider.Reference{Path: target}, Opaque: &typespb.Opaque{ Map: map[string]*typespb.OpaqueEntry{ "Upload-Length": { @@ -212,11 +208,7 @@ func uploadCommand() *command { } req2 := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: target, - }, - }, + Ref: &provider.Reference{Path: target}, } res2, err := gwc.Stat(ctx, req2) if err != nil { @@ -229,7 +221,7 @@ func uploadCommand() *command { info := res2.Info - fmt.Printf("File uploaded: %s:%s %d %s\n", info.Id.StorageId, info.Id.OpaqueId, info.Size, info.Path) + fmt.Printf("File uploaded: %s:%s %d %s\n", info.Id.StorageId, info.Id.NodeId, info.Size, info.Path) return nil } diff --git a/go.mod b/go.mod index 77630d6f96..1dfd80438d 100644 --- a/go.mod +++ b/go.mod @@ -61,6 +61,7 @@ require ( go 1.16 replace ( + github.com/cs3org/go-cs3apis => github.com/butonic/go-cs3apis v0.0.0-20210608111428-0b2c079174c9 github.com/eventials/go-tus => github.com/andrewmostello/go-tus v0.0.0-20200314041820-904a9904af9a github.com/oleiade/reflections => github.com/oleiade/reflections v1.0.1 google.golang.org/grpc => google.golang.org/grpc v1.26.0 // temporary downgrade diff --git a/go.sum b/go.sum index 5392d0bbcf..899cdf7ec5 100644 --- a/go.sum +++ b/go.sum @@ -103,6 +103,8 @@ github.com/bmatcuk/doublestar/v2 v2.0.3/go.mod h1:QMmcs3H2AUQICWhfzLXz+IYln8lRQm github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40 h1:y4B3+GPxKlrigF1ha5FFErxK+sr6sWxQovRMzwMhejo= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= +github.com/butonic/go-cs3apis v0.0.0-20210608111428-0b2c079174c9 h1:q2UFrmiIZwdFOislnGjUWlyqIpttjBRIB6K3QOUmZkY= +github.com/butonic/go-cs3apis v0.0.0-20210608111428-0b2c079174c9/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/c-bata/go-prompt v0.2.5 h1:3zg6PecEywxNn0xiqcXHD96fkbxghD+gdB2tbsYfl+Y= github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= @@ -151,8 +153,6 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8= github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= -github.com/cs3org/go-cs3apis v0.0.0-20210527092509-2b828e94ed4c h1:EaKDtDswzfWUr70xoN63sPLZyvdinkmXrjqc5AFhVZE= -github.com/cs3org/go-cs3apis v0.0.0-20210527092509-2b828e94ed4c/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/cucumber/godog v0.8.1/go.mod h1:vSh3r/lM+psC1BPXvdkSEuNjmXfpVqrMGYAElF6hxnA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/internal/grpc/interceptors/auth/auth.go b/internal/grpc/interceptors/auth/auth.go index a611023c56..54b8a24dd9 100644 --- a/internal/grpc/interceptors/auth/auth.go +++ b/internal/grpc/interceptors/auth/auth.go @@ -261,11 +261,7 @@ func dismantleToken(ctx context.Context, tkn string, req interface{}, mgr token. // Since the public share is obtained from the scope, the current token // has access to it. - statReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Id{Id: share.ResourceId}, - }, - } + statReq := &provider.StatRequest{Ref: share.ResourceId} statResponse, err := client.Stat(ctx, statReq) if err != nil || statResponse.Status.Code != rpc.Code_CODE_OK { @@ -280,7 +276,7 @@ func dismantleToken(ctx context.Context, tkn string, req interface{}, mgr token. } } - return nil, err + return nil, errtypes.PermissionDenied("access token has invalid scope") } func extractRef(req interface{}) (*provider.Reference, bool) { diff --git a/internal/grpc/services/appprovider/appprovider.go b/internal/grpc/services/appprovider/appprovider.go index b7545f7927..09cd9486ff 100644 --- a/internal/grpc/services/appprovider/appprovider.go +++ b/internal/grpc/services/appprovider/appprovider.go @@ -165,7 +165,7 @@ func (s *service) OpenInApp(ctx context.Context, req *providerpb.OpenInAppReques } q := httpReq.URL.Query() - q.Add("fileid", req.ResourceInfo.GetId().OpaqueId) + q.Add("fileid", req.ResourceInfo.GetId().NodeId) q.Add("endpoint", req.ResourceInfo.GetId().StorageId) q.Add("viewmode", req.ViewMode.String()) // TODO the folder URL should be resolved as e.g. `'https://cernbox.cern.ch/index.php/apps/files/?dir=' + filepath.Dir(req.Ref.GetPath())` diff --git a/internal/grpc/services/gateway/appprovider.go b/internal/grpc/services/gateway/appprovider.go index 74297b4b9c..f7921c9520 100644 --- a/internal/grpc/services/gateway/appprovider.go +++ b/internal/grpc/services/gateway/appprovider.go @@ -67,11 +67,7 @@ func (s *svc) OpenInApp(ctx context.Context, req *gateway.OpenInAppRequest) (*pr } statRes, err := s.stat(ctx, &storageprovider.StatRequest{ - Ref: &storageprovider.Reference{ - Spec: &storageprovider.Reference_Path{ - Path: resName, - }, - }, + Ref: &storageprovider.Reference{Path: resName}, }) if err != nil { return &providerpb.OpenInAppResponse{ @@ -136,11 +132,7 @@ func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gate return nil, err } - ref := &storageprovider.Reference{ - Spec: &storageprovider.Reference_Path{ - Path: ep.filePath, - }, - } + ref := &storageprovider.Reference{Path: ep.filePath} appProviderReq := &gateway.OpenInAppRequest{ Ref: ref, ViewMode: vm, diff --git a/internal/grpc/services/gateway/ocmshareprovider.go b/internal/grpc/services/gateway/ocmshareprovider.go index 872009d9c1..67b7d2fd31 100644 --- a/internal/grpc/services/gateway/ocmshareprovider.go +++ b/internal/grpc/services/gateway/ocmshareprovider.go @@ -318,9 +318,7 @@ func (s *svc) createOCMReference(ctx context.Context, share *ocm.Share) (*rpc.St if share.ShareType == ocm.Share_SHARE_TYPE_TRANSFER { createTransferDir, err := s.CreateContainer(ctx, &provider.CreateContainerRequest{ Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: path.Join(homeRes.Path, s.c.DataTransfersFolder), - }, + Path: path.Join(homeRes.Ref.Path, s.c.DataTransfersFolder), }, }) if err != nil { @@ -331,21 +329,21 @@ func (s *svc) createOCMReference(ctx context.Context, share *ocm.Share) (*rpc.St return status.NewInternal(ctx, err, "error creating transfers directory"), nil } - refPath = path.Join(homeRes.Path, s.c.DataTransfersFolder, path.Base(share.Name)) + refPath = path.Join(homeRes.Ref.Path, s.c.DataTransfersFolder, path.Base(share.Name)) targetURI = fmt.Sprintf("datatx://%s@%s?name=%s", token, share.Creator.Idp, share.Name) } else { // reference path is the home path + some name on the corresponding // mesh provider (/home/MyShares/x) // It is the responsibility of the gateway to resolve these references and merge the response back // from the main request. - refPath = path.Join(homeRes.Path, s.c.ShareFolder, path.Base(share.Name)) + refPath = path.Join(homeRes.Ref.Path, s.c.ShareFolder, path.Base(share.Name)) // webdav is the scheme, token@host the opaque part and the share name the query of the URL. targetURI = fmt.Sprintf("webdav://%s@%s?name=%s", token, share.Creator.Idp, share.Name) } log.Info().Msg("mount path will be:" + refPath) createRefReq := &provider.CreateReferenceRequest{ - Path: refPath, + Ref: &provider.Reference{Path: refPath}, TargetUri: targetURI, } diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index 90a5a04272..c2d688dd77 100644 --- a/internal/grpc/services/gateway/storageprovider.go +++ b/internal/grpc/services/gateway/storageprovider.go @@ -122,8 +122,8 @@ func (s *svc) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSp id = f.GetId() } } - c, err := s.findByID(ctx, &provider.ResourceId{ - OpaqueId: id.OpaqueId, + c, err := s.find(ctx, &provider.Reference{ + StorageId: id.OpaqueId, // FIXME REFERENCE the StorageSpaceId is a storageid + a nodeid }) if err != nil { return &provider.ListStorageSpacesResponse{ @@ -144,7 +144,7 @@ func (s *svc) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSp func (s *svc) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) { log := appctx.GetLogger(ctx) // TODO: needs to be fixed - c, err := s.findByID(ctx, req.StorageSpace.Root) + c, err := s.find(ctx, req.StorageSpace.Root) if err != nil { return &provider.UpdateStorageSpaceResponse{ Status: status.NewStatusFromErrType(ctx, "error finding ID", err), @@ -164,8 +164,8 @@ func (s *svc) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorag func (s *svc) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorageSpaceRequest) (*provider.DeleteStorageSpaceResponse, error) { log := appctx.GetLogger(ctx) // TODO: needs to be fixed - c, err := s.findByID(ctx, &provider.ResourceId{ - OpaqueId: req.Id.OpaqueId, + c, err := s.find(ctx, &provider.Reference{ + StorageId: req.Id.OpaqueId, // FIXME REFERENCE the StorageSpaceId is a storageid + a nodeid }) if err != nil { return &provider.DeleteStorageSpaceResponse{ @@ -185,7 +185,7 @@ func (s *svc) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorag func (s *svc) GetHome(ctx context.Context, _ *provider.GetHomeRequest) (*provider.GetHomeResponse, error) { home := s.getHome(ctx) - homeRes := &provider.GetHomeResponse{Path: home, Status: status.NewOK(ctx)} + homeRes := &provider.GetHomeResponse{Ref: &provider.Reference{Path: home}, Status: status.NewOK(ctx)} return homeRes, nil } @@ -282,12 +282,8 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi // if it is a file allow download if ri.Type == provider.ResourceType_RESOURCE_TYPE_FILE { log.Debug().Str("path", p).Interface("ri", ri).Msg("path points to share name file") - req.Ref = &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: ri.Path, - }, - } - log.Debug().Msg("download path: " + ri.Path) + req.Ref.Path = ri.Path + log.Debug().Str("storage", ri.Id.StorageId).Str("node", ri.Id.NodeId).Str("path", req.Ref.Path).Msg("download") return s.initiateFileDownload(ctx, req) } @@ -304,11 +300,7 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi shareName, shareChild := s.splitShare(ctx, p) statReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: shareName, - }, - }, + Ref: &provider.Reference{Path: shareName}, } statRes, err := s.stat(ctx, statReq) if err != nil { @@ -352,13 +344,8 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi } // append child to target - target := path.Join(ri.Path, shareChild) - req.Ref = &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: target, - }, - } - log.Debug().Msg("download path: " + target) + req.Ref.Path = path.Join(ri.Path, shareChild) + log.Debug().Str("storage", ri.Id.StorageId).Str("node", ri.Id.NodeId).Str("path", req.Ref.Path).Msg("download") return s.initiateFileDownload(ctx, req) } @@ -494,12 +481,8 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile // if it is a file allow upload if ri.Type == provider.ResourceType_RESOURCE_TYPE_FILE { log.Debug().Str("path", p).Interface("ri", ri).Msg("path points to share name file") - req.Ref = &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: ri.Path, - }, - } - log.Debug().Msg("upload path: " + ri.Path) + req.Ref.Path = ri.Path + log.Debug().Str("storage", req.Ref.StorageId).Str("node", req.Ref.NodeId).Str("path", req.Ref.Path).Msg("upload") return s.initiateFileUpload(ctx, req) } @@ -515,13 +498,7 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile log.Debug().Msgf("shared child: %s", p) shareName, shareChild := s.splitShare(ctx, p) - statReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: shareName, - }, - }, - } + statReq := &provider.StatRequest{Ref: &provider.Reference{Path: shareName}} statRes, err := s.stat(ctx, statReq) if err != nil { return &gateway.InitiateFileUploadResponse{ @@ -564,12 +541,7 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile } // append child to target - target := path.Join(ri.Path, shareChild) - req.Ref = &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: target, - }, - } + req.Ref.Path = path.Join(ri.Path, shareChild) return s.initiateFileUpload(ctx, req) } @@ -635,13 +607,7 @@ func (s *svc) initiateFileUpload(ctx context.Context, req *provider.InitiateFile } func (s *svc) GetPath(ctx context.Context, req *provider.GetPathRequest) (*provider.GetPathResponse, error) { - statReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: req.ResourceId, - }, - }, - } + statReq := &provider.StatRequest{Ref: req.ResourceId} statRes, err := s.stat(ctx, statReq) if err != nil { err = errors.Wrap(err, "gateway: error stating ref:"+statReq.Ref.String()) @@ -687,13 +653,7 @@ func (s *svc) CreateContainer(ctx context.Context, req *provider.CreateContainer log.Debug().Msgf("shared child: %s", p) shareName, shareChild := s.splitShare(ctx, p) - statReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: shareName, - }, - }, - } + statReq := &provider.StatRequest{Ref: &provider.Reference{Path: shareName}} statRes, err := s.stat(ctx, statReq) if err != nil { return &provider.CreateContainerResponse{ @@ -727,12 +687,7 @@ func (s *svc) CreateContainer(ctx context.Context, req *provider.CreateContainer } // append child to target - target := path.Join(ri.Path, shareChild) - req.Ref = &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: target, - }, - } + req.Ref.Path = path.Join(ri.Path, shareChild) return s.createContainer(ctx, req) } @@ -788,11 +743,7 @@ func (s *svc) Delete(ctx context.Context, req *provider.DeleteRequest) (*provide if s.isShareName(ctx, p) { log.Debug().Msgf("path:%s points to share name", p) - ref := &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: p, - }, - } + ref := &provider.Reference{Path: p} req.Ref = ref return s.delete(ctx, req) @@ -802,11 +753,7 @@ func (s *svc) Delete(ctx context.Context, req *provider.DeleteRequest) (*provide shareName, shareChild := s.splitShare(ctx, p) log.Debug().Msgf("path:%s sharename:%s sharechild: %s", p, shareName, shareChild) - ref := &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: shareName, - }, - } + ref := &provider.Reference{Path: shareName} statReq := &provider.StatRequest{Ref: ref} statRes, err := s.stat(ctx, statReq) @@ -842,14 +789,7 @@ func (s *svc) Delete(ctx context.Context, req *provider.DeleteRequest) (*provide } // append child to target - target := path.Join(ri.Path, shareChild) - ref = &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: target, - }, - } - - req.Ref = ref + req.Ref.Path = path.Join(ri.Path, shareChild) return s.delete(ctx, req) } @@ -913,13 +853,7 @@ func (s *svc) Move(ctx context.Context, req *provider.MoveRequest) (*provider.Mo } - statReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: shareName, - }, - }, - } + statReq := &provider.StatRequest{Ref: &provider.Reference{Path: shareName}} statRes, err := s.stat(ctx, statReq) if err != nil { return &provider.MoveResponse{ @@ -953,14 +887,10 @@ func (s *svc) Move(ctx context.Context, req *provider.MoveRequest) (*provider.Mo } src := &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: path.Join(ri.Path, shareChild), - }, + Path: path.Join(ri.Path, shareChild), } dst := &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: path.Join(ri.Path, dshareChild), - }, + Path: path.Join(ri.Path, dshareChild), } req.Source = src @@ -1043,13 +973,7 @@ func (s *svc) UnsetArbitraryMetadata(ctx context.Context, req *provider.UnsetArb } func (s *svc) statHome(ctx context.Context) (*provider.StatResponse, error) { - statRes, err := s.stat(ctx, &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: s.getHome(ctx), - }, - }, - }) + statRes, err := s.stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: s.getHome(ctx)}}) if err != nil { return &provider.StatResponse{ Status: status.NewInternal(ctx, err, "gateway: error stating home"), @@ -1097,13 +1021,7 @@ func (s *svc) statHome(ctx context.Context) (*provider.StatResponse, error) { } func (s *svc) statSharesFolder(ctx context.Context) (*provider.StatResponse, error) { - statRes, err := s.stat(ctx, &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: s.getSharedFolder(ctx), - }, - }, - }) + statRes, err := s.stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: s.getSharedFolder(ctx)}}) if err != nil { return &provider.StatResponse{ Status: status.NewInternal(ctx, err, "gateway: error stating shares folder"), @@ -1190,9 +1108,9 @@ func (s *svc) stat(ctx context.Context, req *provider.StatRequest) (*provider.St return &provider.StatResponse{ Status: status.NewOK(ctx), Info: &provider.ResourceInfo{ - Id: &provider.ResourceId{ + Id: &provider.Reference{ StorageId: "/", - OpaqueId: uuid.New().String(), + NodeId: uuid.New().String(), }, Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER, Path: resPath, @@ -1214,13 +1132,7 @@ func (s *svc) statOnProvider(ctx context.Context, req *provider.StatRequest, res if resPath != "" && !strings.HasPrefix(resPath, p.ProviderPath) { newPath = p.ProviderPath } - r, err := c.Stat(ctx, &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: newPath, - }, - }, - }) + r, err := c.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: newPath}}) if err != nil { *e = errors.Wrap(err, "gateway: error calling ListContainer") return @@ -1296,13 +1208,7 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St if s.isShareChild(ctx, p) { shareName, shareChild := s.splitShare(ctx, p) - statReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: shareName, - }, - }, - } + statReq := &provider.StatRequest{Ref: &provider.Reference{Path: shareName}} statRes, err := s.stat(ctx, statReq) if err != nil { return &provider.StatResponse{ @@ -1338,11 +1244,7 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St } // append child to target - req.Ref = &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: path.Join(ri.Path, shareChild), - }, - } + req.Ref.Path = path.Join(ri.Path, shareChild) res, err := s.stat(ctx, req) if err != nil { return &provider.StatResponse{ @@ -1405,12 +1307,8 @@ func (s *svc) handleCS3Ref(ctx context.Context, opaque string) (*provider.Resour req := &provider.StatRequest{ Ref: &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: &provider.ResourceId{ - StorageId: parts[0], - OpaqueId: parts[1], - }, - }, + StorageId: parts[0], + NodeId: parts[1], }, } res, err := s.stat(ctx, req) @@ -1447,11 +1345,7 @@ func (s *svc) ListContainerStream(_ *provider.ListContainerStreamRequest, _ gate func (s *svc) listHome(ctx context.Context, req *provider.ListContainerRequest) (*provider.ListContainerResponse, error) { lcr, err := s.listContainer(ctx, &provider.ListContainerRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: s.getHome(ctx), - }, - }, + Ref: &provider.Reference{Path: s.getHome(ctx)}, ArbitraryMetadataKeys: req.ArbitraryMetadataKeys, }) if err != nil { @@ -1466,7 +1360,7 @@ func (s *svc) listHome(ctx context.Context, req *provider.ListContainerRequest) } for i := range lcr.Infos { - if s.isSharedFolder(ctx, lcr.Infos[i].Path) { + if s.isSharedFolder(ctx, lcr.Infos[i].GetPath()) { statSharedFolder, err := s.statSharesFolder(ctx) if err != nil { return &provider.ListContainerResponse{ @@ -1487,13 +1381,7 @@ func (s *svc) listHome(ctx context.Context, req *provider.ListContainerRequest) } func (s *svc) listSharesFolder(ctx context.Context) (*provider.ListContainerResponse, error) { - lcr, err := s.listContainer(ctx, &provider.ListContainerRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: s.getSharedFolder(ctx), - }, - }, - }) + lcr, err := s.listContainer(ctx, &provider.ListContainerRequest{Ref: &provider.Reference{Path: s.getSharedFolder(ctx)}}) if err != nil { return &provider.ListContainerResponse{ Status: status.NewInternal(ctx, err, "gateway: error listing shared folder"), @@ -1524,7 +1412,7 @@ func (s *svc) listSharesFolder(ctx context.Context) (*provider.ListContainerResp } } - info.Path = lcr.Infos[i].GetPath() + info.Path = lcr.Infos[i].Path checkedInfos = append(checkedInfos, info) } lcr.Infos = checkedInfos @@ -1572,9 +1460,9 @@ func (s *svc) listContainer(ctx context.Context, req *provider.ListContainerRequ for k, v := range indirects { inf := &provider.ResourceInfo{ - Id: &provider.ResourceId{ + Id: &provider.Reference{ StorageId: "/", - OpaqueId: uuid.New().String(), + NodeId: uuid.New().String(), }, Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER, Etag: etag.GenerateEtagFromResources(nil, v), @@ -1603,13 +1491,7 @@ func (s *svc) listContainerOnProvider(ctx context.Context, req *provider.ListCon if resPath != "" && !strings.HasPrefix(resPath, p.ProviderPath) { newPath = p.ProviderPath } - r, err := c.ListContainer(ctx, &provider.ListContainerRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: newPath, - }, - }, - }) + r, err := c.ListContainer(ctx, &provider.ListContainerRequest{Ref: &provider.Reference{Path: newPath}}) if err != nil { *e = errors.Wrap(err, "gateway: error calling ListContainer") return @@ -1640,13 +1522,7 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ // we need to provide the info of the target, not the reference. if s.isShareName(ctx, p) { - statReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: p, - }, - }, - } + statReq := &provider.StatRequest{Ref: &provider.Reference{Path: p}} statRes, err := s.stat(ctx, statReq) if err != nil { return &provider.ListContainerResponse{ @@ -1694,11 +1570,7 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ } newReq := &provider.ListContainerRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: ri.Path, - }, - }, + Ref: &provider.Reference{Path: ri.Path}, ArbitraryMetadataKeys: req.ArbitraryMetadataKeys, } newRes, err := s.listContainer(ctx, newReq) @@ -1727,13 +1599,7 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ if s.isShareChild(ctx, p) { shareName, shareChild := s.splitShare(ctx, p) - statReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: shareName, - }, - }, - } + statReq := &provider.StatRequest{Ref: &provider.Reference{Path: shareName}} statRes, err := s.stat(ctx, statReq) if err != nil { return &provider.ListContainerResponse{ @@ -1781,11 +1647,7 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ } newReq := &provider.ListContainerRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: path.Join(ri.Path, shareChild), - }, - }, + Ref: &provider.Reference{Path: path.Join(ri.Path, shareChild)}, ArbitraryMetadataKeys: req.ArbitraryMetadataKeys, } newRes, err := s.listContainer(ctx, newReq) @@ -1815,11 +1677,9 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ } func (s *svc) getPath(ctx context.Context, ref *provider.Reference, keys ...string) (string, *rpc.Status) { - if ref.GetPath() != "" { - return ref.GetPath(), &rpc.Status{Code: rpc.Code_CODE_OK} - } - if ref.GetId() != nil && ref.GetId().GetOpaqueId() != "" { + // check if it is an id based or combined reference first + if ref.StorageId != "" && ref.NodeId != "" { req := &provider.StatRequest{Ref: ref, ArbitraryMetadataKeys: keys} res, err := s.stat(ctx, req) if (res != nil && res.Status.Code != rpc.Code_CODE_OK) || err != nil { @@ -1829,6 +1689,9 @@ func (s *svc) getPath(ctx context.Context, ref *provider.Reference, keys ...stri return res.Info.Path, res.Status } + if ref.StorageId == "" && ref.NodeId == "" && ref.Path != "" { + return ref.Path, &rpc.Status{Code: rpc.Code_CODE_OK} + } return "", &rpc.Status{Code: rpc.Code_CODE_INTERNAL} } @@ -2017,21 +1880,8 @@ func (s *svc) GetQuota(ctx context.Context, req *gateway.GetQuotaRequest) (*prov return res, nil } -func (s *svc) findByID(ctx context.Context, id *provider.ResourceId) (provider.ProviderAPIClient, error) { - ref := &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: id, - }, - } - return s.find(ctx, ref) -} - func (s *svc) findByPath(ctx context.Context, path string) (provider.ProviderAPIClient, error) { - ref := &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: path, - }, - } + ref := &provider.Reference{Path: path} return s.find(ctx, ref) } diff --git a/internal/grpc/services/gateway/usershareprovider.go b/internal/grpc/services/gateway/usershareprovider.go index 175258765f..a070a6ee20 100644 --- a/internal/grpc/services/gateway/usershareprovider.go +++ b/internal/grpc/services/gateway/usershareprovider.go @@ -320,12 +320,12 @@ func (s *svc) UpdateReceivedShare(ctx context.Context, req *collaboration.Update }, nil } -func (s *svc) createReference(ctx context.Context, resourceID *provider.ResourceId) *rpc.Status { +func (s *svc) createReference(ctx context.Context, resourceID *provider.Reference) *rpc.Status { log := appctx.GetLogger(ctx) // get the metadata about the share - c, err := s.findByID(ctx, resourceID) + c, err := s.find(ctx, resourceID) if err != nil { if _, ok := err.(errtypes.IsNotFound); ok { return status.NewNotFound(ctx, "storage provider not found") @@ -334,11 +334,7 @@ func (s *svc) createReference(ctx context.Context, resourceID *provider.Resource } statReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: resourceID, - }, - }, + Ref: resourceID, } statRes, err := c.Stat(ctx, statReq) @@ -368,13 +364,13 @@ func (s *svc) createReference(ctx context.Context, resourceID *provider.Resource // It is the responsibility of the gateway to resolve these references and merge the response back // from the main request. // TODO(labkode): the name of the share should be the filename it points to by default. - refPath := path.Join(homeRes.Path, s.c.ShareFolder, path.Base(statRes.Info.Path)) + refPath := path.Join(homeRes.Ref.Path, s.c.ShareFolder, path.Base(statRes.Info.Path)) log.Info().Msg("mount path will be:" + refPath) createRefReq := &provider.CreateReferenceRequest{ - Path: refPath, + Ref: &provider.Reference{Path: refPath}, // cs3 is the Scheme and %s/%s is the Opaque parts of a net.URL. - TargetUri: fmt.Sprintf("cs3:%s/%s", resourceID.GetStorageId(), resourceID.GetOpaqueId()), + TargetUri: fmt.Sprintf("cs3:%s/%s", resourceID.GetStorageId(), resourceID.GetNodeId()), } c, err = s.findByPath(ctx, refPath) @@ -401,21 +397,17 @@ func (s *svc) createReference(ctx context.Context, resourceID *provider.Resource return status.NewOK(ctx) } -func (s *svc) addGrant(ctx context.Context, id *provider.ResourceId, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) { +func (s *svc) addGrant(ctx context.Context, id *provider.Reference, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) { grantReq := &provider.AddGrantRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: id, - }, - }, + Ref: id, Grant: &provider.Grant{ Grantee: g, Permissions: p, }, } - c, err := s.findByID(ctx, id) + c, err := s.find(ctx, id) if err != nil { if _, ok := err.(errtypes.IsNotFound); ok { return status.NewNotFound(ctx, "storage provider not found"), nil @@ -435,21 +427,17 @@ func (s *svc) addGrant(ctx context.Context, id *provider.ResourceId, g *provider return status.NewOK(ctx), nil } -func (s *svc) updateGrant(ctx context.Context, id *provider.ResourceId, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) { +func (s *svc) updateGrant(ctx context.Context, id *provider.Reference, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) { grantReq := &provider.UpdateGrantRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: id, - }, - }, + Ref: id, Grant: &provider.Grant{ Grantee: g, Permissions: p, }, } - c, err := s.findByID(ctx, id) + c, err := s.find(ctx, id) if err != nil { if _, ok := err.(errtypes.IsNotFound); ok { return status.NewNotFound(ctx, "storage provider not found"), nil @@ -469,21 +457,17 @@ func (s *svc) updateGrant(ctx context.Context, id *provider.ResourceId, g *provi return status.NewOK(ctx), nil } -func (s *svc) removeGrant(ctx context.Context, id *provider.ResourceId, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) { +func (s *svc) removeGrant(ctx context.Context, id *provider.Reference, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) { grantReq := &provider.RemoveGrantRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: id, - }, - }, + Ref: id, Grant: &provider.Grant{ Grantee: g, Permissions: p, }, } - c, err := s.findByID(ctx, id) + c, err := s.find(ctx, id) if err != nil { if _, ok := err.(errtypes.IsNotFound); ok { return status.NewNotFound(ctx, "storage provider not found"), nil diff --git a/internal/grpc/services/ocmcore/ocmcore.go b/internal/grpc/services/ocmcore/ocmcore.go index 81ae633154..0fcd1dba53 100644 --- a/internal/grpc/services/ocmcore/ocmcore.go +++ b/internal/grpc/services/ocmcore/ocmcore.go @@ -116,9 +116,9 @@ func (s *service) CreateOCMCoreShare(ctx context.Context, req *ocmcore.CreateOCM }, nil } - resource := &provider.ResourceId{ + resource := &provider.Reference{ StorageId: parts[0], - OpaqueId: parts[1], + NodeId: parts[1], } var resourcePermissions *provider.ResourcePermissions diff --git a/internal/grpc/services/publicstorageprovider/publicstorageprovider.go b/internal/grpc/services/publicstorageprovider/publicstorageprovider.go index b941b9b110..dcf8a4ff6b 100644 --- a/internal/grpc/services/publicstorageprovider/publicstorageprovider.go +++ b/internal/grpc/services/publicstorageprovider/publicstorageprovider.go @@ -148,9 +148,7 @@ func (s *service) translatePublicRefToCS3Ref(ctx context.Context, ref *provider. return nil, "", nil, st, nil } - cs3Ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: path.Join("/", originalPath, relativePath)}, - } + cs3Ref := &provider.Reference{Path: path.Join("/", originalPath, relativePath)} log.Debug(). Interface("sourceRef", ref). Interface("cs3Ref", cs3Ref). @@ -473,13 +471,7 @@ func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provide } var statResponse *provider.StatResponse // the call has to be made to the gateway instead of the storage. - statResponse, err = s.gateway.Stat(ctx, &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: p, - }, - }, - }) + statResponse, err = s.gateway.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: p}}) if err != nil { return &provider.StatResponse{ Status: status.NewInternal(ctx, err, "gateway: error calling Stat for ref:"+req.Ref.String()), @@ -540,13 +532,7 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer listContainerR, err := s.gateway.ListContainer( ctx, - &provider.ListContainerRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: path.Join("/", pathFromToken, relativePath), - }, - }, - }, + &provider.ListContainerRequest{Ref: &provider.Reference{Path: path.Join("/", pathFromToken, relativePath)}}, ) if err != nil { return &provider.ListContainerResponse{ @@ -587,8 +573,8 @@ func filterPermissions(l *provider.ResourcePermissions, r *provider.ResourcePerm } func (s *service) unwrap(ctx context.Context, ref *provider.Reference) (token string, relativePath string, err error) { - if ref.GetId() != nil { - return "", "", errtypes.BadRequest("need path based ref: got " + ref.String()) + if ref.StorageId != "" || ref.NodeId != "" { + return "", "", errtypes.BadRequest("need absolute path ref: got " + ref.String()) } if ref.GetPath() == "" { @@ -708,11 +694,7 @@ func (s *service) resolveToken(ctx context.Context, token string) (string, *link } sRes, err := s.gateway.Stat(ctx, &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: publicShareResponse.GetShare().GetResourceId(), - }, - }, + Ref: publicShareResponse.GetShare().GetResourceId(), }) switch { case err != nil: diff --git a/internal/grpc/services/storageprovider/storageprovider.go b/internal/grpc/services/storageprovider/storageprovider.go index 7785771fcb..9753d695ed 100644 --- a/internal/grpc/services/storageprovider/storageprovider.go +++ b/internal/grpc/services/storageprovider/storageprovider.go @@ -400,7 +400,7 @@ func (s *service) GetHome(ctx context.Context, req *provider.GetHomeRequest) (*p res := &provider.GetHomeResponse{ Status: status.NewOK(ctx), - Path: home, + Ref: &provider.Reference{Path: home}, } return res, nil @@ -816,7 +816,7 @@ func (s *service) ListRecycle(ctx context.Context, req *provider.ListRecycleRequ func (s *service) RestoreRecycleItem(ctx context.Context, req *provider.RestoreRecycleItemRequest) (*provider.RestoreRecycleItemResponse, error) { // TODO(labkode): CRITICAL: fill recycle info with storage provider. - if err := s.storage.RestoreRecycleItem(ctx, req.Key, req.RestorePath); err != nil { + if err := s.storage.RestoreRecycleItem(ctx, req.Key, req.RestoreRef); err != nil { var st *rpc.Status switch err.(type) { case errtypes.IsNotFound: @@ -839,8 +839,8 @@ func (s *service) RestoreRecycleItem(ctx context.Context, req *provider.RestoreR func (s *service) PurgeRecycle(ctx context.Context, req *provider.PurgeRecycleRequest) (*provider.PurgeRecycleResponse, error) { // if a key was sent as opacque id purge only that item - if req.GetRef().GetId() != nil && req.GetRef().GetId().GetOpaqueId() != "" { - if err := s.storage.PurgeRecycleItem(ctx, req.GetRef().GetId().GetOpaqueId()); err != nil { + if req.GetRef() != nil && req.GetRef().NodeId != "" { + if err := s.storage.PurgeRecycleItem(ctx, req.GetRef().NodeId); err != nil { var st *rpc.Status switch err.(type) { case errtypes.IsNotFound: @@ -1028,13 +1028,7 @@ func (s *service) CreateReference(ctx context.Context, req *provider.CreateRefer }, nil } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: req.Path, - }, - } - - newRef, err := s.unwrap(ctx, ref) + newRef, err := s.unwrap(ctx, req.Ref) if err != nil { return &provider.CreateReferenceResponse{ Status: status.NewInternal(ctx, err, "error unwrapping path"), @@ -1101,17 +1095,8 @@ func getFS(c *config) (storage.FS, error) { } func (s *service) unwrap(ctx context.Context, ref *provider.Reference) (*provider.Reference, error) { - if ref.GetId() != nil { - idRef := &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: &provider.ResourceId{ - StorageId: "", // we are unwrapping on purpose, bottom layers only need OpaqueId. - OpaqueId: ref.GetId().OpaqueId, - }, - }, - } - - return idRef, nil + if ref.StorageId != "" { + return ref, nil } if ref.GetPath() == "" { @@ -1125,11 +1110,7 @@ func (s *service) unwrap(ctx context.Context, ref *provider.Reference) (*provide return nil, err } - pathRef := &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: fsfn, - }, - } + pathRef := &provider.Reference{Path: fsfn} return pathRef, nil } diff --git a/internal/http/services/owncloud/ocdav/copy.go b/internal/http/services/owncloud/ocdav/copy.go index 1a7e29a704..a3cbee49ec 100644 --- a/internal/http/services/owncloud/ocdav/copy.go +++ b/internal/http/services/owncloud/ocdav/copy.go @@ -81,9 +81,7 @@ func (s *svc) handleCopy(w http.ResponseWriter, r *http.Request, ns string) { } // check src exists - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: src}, - } + ref := &provider.Reference{Path: src} srcStatReq := &provider.StatRequest{Ref: ref} srcStatRes, err := client.Stat(ctx, srcStatReq) if err != nil { @@ -98,9 +96,7 @@ func (s *svc) handleCopy(w http.ResponseWriter, r *http.Request, ns string) { } // check dst exists - ref = &provider.Reference{ - Spec: &provider.Reference_Path{Path: dst}, - } + ref = &provider.Reference{Path: dst} dstStatReq := &provider.StatRequest{Ref: ref} dstStatRes, err := client.Stat(ctx, dstStatReq) if err != nil { @@ -126,9 +122,7 @@ func (s *svc) handleCopy(w http.ResponseWriter, r *http.Request, ns string) { } else { // check if an intermediate path / the parent exists intermediateDir := path.Dir(dst) - ref = &provider.Reference{ - Spec: &provider.Reference_Path{Path: intermediateDir}, - } + ref = &provider.Reference{Path: intermediateDir} intStatReq := &provider.StatRequest{Ref: ref} intStatRes, err := client.Stat(ctx, intStatReq) if err != nil { @@ -164,9 +158,7 @@ func (s *svc) descend(ctx context.Context, client gateway.GatewayAPIClient, src if src.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER { // create dir createReq := &provider.CreateContainerRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: dst}, - }, + Ref: &provider.Reference{Path: dst}, } createRes, err := client.CreateContainer(ctx, createReq) if err != nil || createRes.Status.Code != rpc.Code_CODE_OK { @@ -181,9 +173,7 @@ func (s *svc) descend(ctx context.Context, client gateway.GatewayAPIClient, src // descend for children listReq := &provider.ListContainerRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: src.Path}, - }, + Ref: &provider.Reference{Path: src.Path}, } res, err := client.ListContainer(ctx, listReq) if err != nil { @@ -207,9 +197,7 @@ func (s *svc) descend(ctx context.Context, client gateway.GatewayAPIClient, src // 1. get download url dReq := &provider.InitiateFileDownloadRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: src.Path}, - }, + Ref: &provider.Reference{Path: src.Path}, } dRes, err := client.InitiateFileDownload(ctx, dReq) @@ -231,9 +219,7 @@ func (s *svc) descend(ctx context.Context, client gateway.GatewayAPIClient, src // 2. get upload url uReq := &provider.InitiateFileUploadRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: dst}, - }, + Ref: &provider.Reference{Path: dst}, Opaque: &typespb.Opaque{ Map: map[string]*typespb.OpaqueEntry{ "Upload-Length": { diff --git a/internal/http/services/owncloud/ocdav/dav.go b/internal/http/services/owncloud/ocdav/dav.go index ca5abc1884..a1681fe29d 100644 --- a/internal/http/services/owncloud/ocdav/dav.go +++ b/internal/http/services/owncloud/ocdav/dav.go @@ -249,9 +249,7 @@ func (h *DavHandler) Handler(s *svc) http.Handler { } func getTokenStatInfo(ctx context.Context, client gatewayv1beta1.GatewayAPIClient, token string) (*provider.StatResponse, error) { - return client.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: path.Join("/public", token)}, - }}) + return client.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: path.Join("/public", token)}}) } func handleBasicAuth(ctx context.Context, c gatewayv1beta1.GatewayAPIClient, token, pw string) (*gatewayv1beta1.AuthenticateResponse, error) { diff --git a/internal/http/services/owncloud/ocdav/delete.go b/internal/http/services/owncloud/ocdav/delete.go index 0bdf55561a..8898a95d1a 100644 --- a/internal/http/services/owncloud/ocdav/delete.go +++ b/internal/http/services/owncloud/ocdav/delete.go @@ -44,9 +44,7 @@ func (s *svc) handleDelete(w http.ResponseWriter, r *http.Request, ns string) { return } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - } + ref := &provider.Reference{Path: fn} req := &provider.DeleteRequest{Ref: ref} res, err := client.Delete(ctx, req) if err != nil { diff --git a/internal/http/services/owncloud/ocdav/get.go b/internal/http/services/owncloud/ocdav/get.go index d6ab7d6c89..d462d8fa1c 100644 --- a/internal/http/services/owncloud/ocdav/get.go +++ b/internal/http/services/owncloud/ocdav/get.go @@ -55,9 +55,7 @@ func (s *svc) handleGet(w http.ResponseWriter, r *http.Request, ns string) { } sReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - }, + Ref: &provider.Reference{Path: fn}, } sRes, err := client.Stat(ctx, sReq) if err != nil { @@ -79,9 +77,7 @@ func (s *svc) handleGet(w http.ResponseWriter, r *http.Request, ns string) { } dReq := &provider.InitiateFileDownloadRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - }, + Ref: &provider.Reference{Path: fn}, } dRes, err := client.InitiateFileDownload(ctx, dReq) diff --git a/internal/http/services/owncloud/ocdav/head.go b/internal/http/services/owncloud/ocdav/head.go index 250da299bb..f70d4b95d8 100644 --- a/internal/http/services/owncloud/ocdav/head.go +++ b/internal/http/services/owncloud/ocdav/head.go @@ -50,9 +50,7 @@ func (s *svc) handleHead(w http.ResponseWriter, r *http.Request, ns string) { return } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - } + ref := &provider.Reference{Path: fn} req := &provider.StatRequest{Ref: ref} res, err := client.Stat(ctx, req) if err != nil { diff --git a/internal/http/services/owncloud/ocdav/mkcol.go b/internal/http/services/owncloud/ocdav/mkcol.go index c93a8f9f67..889598a43b 100644 --- a/internal/http/services/owncloud/ocdav/mkcol.go +++ b/internal/http/services/owncloud/ocdav/mkcol.go @@ -54,9 +54,7 @@ func (s *svc) handleMkcol(w http.ResponseWriter, r *http.Request, ns string) { } // check fn exists - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - } + ref := &provider.Reference{Path: fn} statReq := &provider.StatRequest{Ref: ref} statRes, err := client.Stat(ctx, statReq) if err != nil { diff --git a/internal/http/services/owncloud/ocdav/move.go b/internal/http/services/owncloud/ocdav/move.go index 77debda500..e92bc1bede 100644 --- a/internal/http/services/owncloud/ocdav/move.go +++ b/internal/http/services/owncloud/ocdav/move.go @@ -67,9 +67,7 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) { // check src exists srcStatReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: src}, - }, + Ref: &provider.Reference{Path: src}, } srcStatRes, err := client.Stat(ctx, srcStatReq) if err != nil { @@ -83,9 +81,7 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) { } // check dst exists - dstStatRef := &provider.Reference{ - Spec: &provider.Reference_Path{Path: dst}, - } + dstStatRef := &provider.Reference{Path: dst} dstStatReq := &provider.StatRequest{Ref: dstStatRef} dstStatRes, err := client.Stat(ctx, dstStatReq) if err != nil { @@ -124,9 +120,7 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) { } else { // check if an intermediate path / the parent exists intermediateDir := path.Dir(dst) - ref2 := &provider.Reference{ - Spec: &provider.Reference_Path{Path: intermediateDir}, - } + ref2 := &provider.Reference{Path: intermediateDir} intStatReq := &provider.StatRequest{Ref: ref2} intStatRes, err := client.Stat(ctx, intStatReq) if err != nil { @@ -147,12 +141,8 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) { // TODO what if intermediate is a file? } - sourceRef := &provider.Reference{ - Spec: &provider.Reference_Path{Path: src}, - } - dstRef := &provider.Reference{ - Spec: &provider.Reference_Path{Path: dst}, - } + sourceRef := &provider.Reference{Path: src} + dstRef := &provider.Reference{Path: dst} mReq := &provider.MoveRequest{Source: sourceRef, Destination: dstRef} mRes, err := client.Move(ctx, mReq) if err != nil { diff --git a/internal/http/services/owncloud/ocdav/ocdav.go b/internal/http/services/owncloud/ocdav/ocdav.go index c2b7561cf2..9e973edea6 100644 --- a/internal/http/services/owncloud/ocdav/ocdav.go +++ b/internal/http/services/owncloud/ocdav/ocdav.go @@ -206,8 +206,8 @@ func applyLayout(ctx context.Context, ns string, useLoggedInUserNS bool, request return templates.WithUser(u, ns) } -func wrapResourceID(r *provider.ResourceId) string { - return wrap(r.StorageId, r.OpaqueId) +func wrapResourceID(r *provider.Reference) string { + return wrap(r.StorageId, r.NodeId) } // The fileID must be encoded @@ -218,7 +218,7 @@ func wrap(sid string, oid string) string { return base64.URLEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", sid, oid))) } -func unwrap(rid string) *provider.ResourceId { +func unwrap(rid string) *provider.Reference { decodedID, err := base64.URLEncoding.DecodeString(rid) if err != nil { return nil @@ -233,9 +233,9 @@ func unwrap(rid string) *provider.ResourceId { return nil } - return &provider.ResourceId{ + return &provider.Reference{ StorageId: parts[0], - OpaqueId: parts[1], + NodeId: parts[1], } } diff --git a/internal/http/services/owncloud/ocdav/propfind.go b/internal/http/services/owncloud/ocdav/propfind.go index 71eb313918..9e71d6b036 100644 --- a/internal/http/services/owncloud/ocdav/propfind.go +++ b/internal/http/services/owncloud/ocdav/propfind.go @@ -110,9 +110,7 @@ func (s *svc) handlePropfind(w http.ResponseWriter, r *http.Request, ns string) } } } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - } + ref := &provider.Reference{Path: fn} req := &provider.StatRequest{ Ref: ref, ArbitraryMetadataKeys: metadataKeys, @@ -155,9 +153,7 @@ func (s *svc) handlePropfind(w http.ResponseWriter, r *http.Request, ns string) for len(stack) > 0 { // retrieve path on top of stack path := stack[len(stack)-1] - ref = &provider.Reference{ - Spec: &provider.Reference_Path{Path: path}, - } + ref = &provider.Reference{Path: path} req := &provider.ListContainerRequest{ Ref: ref, ArbitraryMetadataKeys: metadataKeys, diff --git a/internal/http/services/owncloud/ocdav/proppatch.go b/internal/http/services/owncloud/ocdav/proppatch.go index a8fe5933a0..f7dd927743 100644 --- a/internal/http/services/owncloud/ocdav/proppatch.go +++ b/internal/http/services/owncloud/ocdav/proppatch.go @@ -63,9 +63,7 @@ func (s *svc) handleProppatch(w http.ResponseWriter, r *http.Request, ns string) // check if resource exists statReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - }, + Ref: &provider.Reference{Path: fn}, } statRes, err := c.Stat(ctx, statReq) if err != nil { @@ -80,15 +78,11 @@ func (s *svc) handleProppatch(w http.ResponseWriter, r *http.Request, ns string) } rreq := &provider.UnsetArbitraryMetadataRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - }, + Ref: &provider.Reference{Path: fn}, ArbitraryMetadataKeys: []string{""}, } sreq := &provider.SetArbitraryMetadataRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - }, + Ref: &provider.Reference{Path: fn}, ArbitraryMetadata: &provider.ArbitraryMetadata{ Metadata: map[string]string{}, }, diff --git a/internal/http/services/owncloud/ocdav/put.go b/internal/http/services/owncloud/ocdav/put.go index 71a8c1b7b3..7a9ad49963 100644 --- a/internal/http/services/owncloud/ocdav/put.go +++ b/internal/http/services/owncloud/ocdav/put.go @@ -156,9 +156,7 @@ func (s *svc) handlePutHelper(w http.ResponseWriter, r *http.Request, content io return } - ref := &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - } + ref := &provider.Reference{Path: fn} sReq := &provider.StatRequest{Ref: ref} sRes, err := client.Stat(ctx, sReq) if err != nil { @@ -315,13 +313,7 @@ func (s *svc) handlePutHelper(w http.ResponseWriter, r *http.Request, content io w.WriteHeader(http.StatusInternalServerError) return } - sReq = &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: chunk.Path, - }, - }, - } + sReq = &provider.StatRequest{Ref: &provider.Reference{Path: chunk.Path}} } // stat again to check the new file's metadata diff --git a/internal/http/services/owncloud/ocdav/trashbin.go b/internal/http/services/owncloud/ocdav/trashbin.go index c97353c76f..de5d9dede4 100644 --- a/internal/http/services/owncloud/ocdav/trashbin.go +++ b/internal/http/services/owncloud/ocdav/trashbin.go @@ -179,13 +179,7 @@ func (h *TrashbinHandler) listTrashbin(w http.ResponseWriter, r *http.Request, s // ask gateway for recycle items // TODO(labkode): add Reference to ListRecycleRequest - getRecycleRes, err := gc.ListRecycle(ctx, &gateway.ListRecycleRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: getHomeRes.Path, - }, - }, - }) + getRecycleRes, err := gc.ListRecycle(ctx, &gateway.ListRecycleRequest{Ref: getHomeRes.Ref}) if err != nil { sublog.Error().Err(err).Msg("error calling ListRecycle") @@ -285,8 +279,8 @@ func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, u *use Prop: []*propertyXML{}, }) // yes this is redundant, can be derived from oc:trashbin-original-location which contains the full path, clients should not fetch it - response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-original-filename", filepath.Base(item.Path))) - response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-original-location", strings.TrimPrefix(item.Path, "/"))) + response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-original-filename", filepath.Base(item.Ref.Path))) + response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-original-location", strings.TrimPrefix(item.Ref.Path, "/"))) response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-delete-timestamp", strconv.FormatUint(item.DeletionTime.Seconds, 10))) response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-delete-datetime", dTime)) if item.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER { @@ -322,10 +316,10 @@ func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, u *use } case "trashbin-original-filename": // yes this is redundant, can be derived from oc:trashbin-original-location which contains the full path, clients should not fetch it - propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-original-filename", filepath.Base(item.Path))) + propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-original-filename", filepath.Base(item.Ref.Path))) case "trashbin-original-location": // TODO (jfd) double check and clarify the cs3 spec what the Key is about and if Path is only the folder that contains the file or if it includes the filename - propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-original-location", strings.TrimPrefix(item.Path, "/"))) + propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-original-location", strings.TrimPrefix(item.Ref.Path, "/"))) case "trashbin-delete-datetime": propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-delete-datetime", dTime)) case "trashbin-delete-timestamp": @@ -399,13 +393,9 @@ func (h *TrashbinHandler) restore(w http.ResponseWriter, r *http.Request, s *svc // this means we can only undelete on the same storage, not to a different folder // use the key which is prefixed with the StoragePath to lookup the correct storage ... // TODO currently limited to the home storage - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: getHomeRes.Path, - }, - }, - Key: key, - RestorePath: dst, + Ref: getHomeRes.Ref, + Key: key, + RestoreRef: &provider.Reference{Path: dst}, } res, err := client.RestoreRecycleItem(ctx, req) @@ -447,13 +437,7 @@ func (h *TrashbinHandler) delete(w http.ResponseWriter, r *http.Request, s *svc, HandleErrorStatus(&sublog, w, getHomeRes.Status) return } - sRes, err := client.Stat(ctx, &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: getHomeRes.Path, - }, - }, - }) + sRes, err := client.Stat(ctx, &provider.StatRequest{Ref: getHomeRes.Ref}) if err != nil { sublog.Error().Err(err).Msg("error calling Stat") w.WriteHeader(http.StatusInternalServerError) @@ -469,12 +453,8 @@ func (h *TrashbinHandler) delete(w http.ResponseWriter, r *http.Request, s *svc, req := &gateway.PurgeRecycleRequest{ Ref: &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: &provider.ResourceId{ - OpaqueId: key, - StorageId: sRes.Info.Id.StorageId, - }, - }, + NodeId: key, + StorageId: sRes.Info.Id.StorageId, }, } diff --git a/internal/http/services/owncloud/ocdav/tus.go b/internal/http/services/owncloud/ocdav/tus.go index fec279f494..8fb4c7a1a1 100644 --- a/internal/http/services/owncloud/ocdav/tus.go +++ b/internal/http/services/owncloud/ocdav/tus.go @@ -84,9 +84,7 @@ func (s *svc) handleTusPost(w http.ResponseWriter, r *http.Request, ns string) { } sReq := &provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - }, + Ref: &provider.Reference{Path: fn}, } sRes, err := client.Stat(ctx, sReq) if err != nil { @@ -136,9 +134,7 @@ func (s *svc) handleTusPost(w http.ResponseWriter, r *http.Request, ns string) { // initiateUpload uReq := &provider.InitiateFileUploadRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{Path: fn}, - }, + Ref: &provider.Reference{Path: fn}, Opaque: &typespb.Opaque{ Map: opaqueMap, }, diff --git a/internal/http/services/owncloud/ocdav/versions.go b/internal/http/services/owncloud/ocdav/versions.go index bd261594ae..0f833205ad 100644 --- a/internal/http/services/owncloud/ocdav/versions.go +++ b/internal/http/services/owncloud/ocdav/versions.go @@ -42,11 +42,11 @@ func (h *VersionsHandler) init(c *Config) error { // Handler handles requests // versions can be listed with a PROPFIND to /remote.php/dav/meta//v // a version is identified by a timestamp, eg. /remote.php/dav/meta//v/1561410426 -func (h *VersionsHandler) Handler(s *svc, rid *provider.ResourceId) http.Handler { +func (h *VersionsHandler) Handler(s *svc, rid *provider.Reference) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - if rid == (*provider.ResourceId)(nil) { + if rid == nil { http.Error(w, "404 Not Found", http.StatusNotFound) return } @@ -78,7 +78,7 @@ func (h *VersionsHandler) Handler(s *svc, rid *provider.ResourceId) http.Handler }) } -func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request, s *svc, rid *provider.ResourceId) { +func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request, s *svc, rid *provider.Reference) { ctx := r.Context() ctx, span := trace.StartSpan(ctx, "listVersions") defer span.End() @@ -99,10 +99,7 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request, return } - ref := &provider.Reference{ - Spec: &provider.Reference_Id{Id: rid}, - } - req := &provider.StatRequest{Ref: ref} + req := &provider.StatRequest{Ref: rid} res, err := client.Stat(ctx, req) if err != nil { sublog.Error().Err(err).Msg("error sending a grpc stat request") @@ -117,7 +114,7 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request, info := res.Info lvReq := &provider.ListFileVersionsRequest{ - Ref: ref, + Ref: rid, } lvRes, err := client.ListFileVersions(ctx, lvReq) if err != nil { @@ -142,9 +139,9 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request, // TODO(jfd) we cannot access version content, this will be a problem when trying to fetch version thumbnails // Opaque Type: provider.ResourceType_RESOURCE_TYPE_FILE, - Id: &provider.ResourceId{ + Id: &provider.Reference{ StorageId: "versions", // this is a virtual storage - OpaqueId: info.Id.OpaqueId + "@" + versions[i].GetKey(), + NodeId: info.Id.NodeId + "@" + versions[i].GetKey(), }, // Checksum Etag: versions[i].Etag, @@ -178,7 +175,7 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request, } -func (h *VersionsHandler) doRestore(w http.ResponseWriter, r *http.Request, s *svc, rid *provider.ResourceId, key string) { +func (h *VersionsHandler) doRestore(w http.ResponseWriter, r *http.Request, s *svc, rid *provider.Reference, key string) { ctx := r.Context() ctx, span := trace.StartSpan(ctx, "restore") defer span.End() @@ -193,9 +190,7 @@ func (h *VersionsHandler) doRestore(w http.ResponseWriter, r *http.Request, s *s } req := &provider.RestoreFileVersionRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Id{Id: rid}, - }, + Ref: rid, Key: key, } diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go index 5c8029f4a1..7f7427a599 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go @@ -377,13 +377,7 @@ func (h *Handler) updatePublicShare(w http.ResponseWriter, r *http.Request, shar return } - statReq := provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: before.Share.ResourceId, - }, - }, - } + statReq := provider.StatRequest{Ref: before.Share.ResourceId} statRes, err := gwC.Stat(r.Context(), &statReq) if err != nil { diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go index fefe0acad2..5eeb0dd090 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go @@ -52,6 +52,7 @@ import ( "github.com/cs3org/reva/pkg/rhttp/router" "github.com/cs3org/reva/pkg/share/cache" "github.com/cs3org/reva/pkg/share/cache/registry" + "github.com/cs3org/reva/pkg/utils" "github.com/pkg/errors" ) @@ -217,11 +218,7 @@ func (h *Handler) createShare(w http.ResponseWriter, r *http.Request) { fn := path.Join(h.homeNamespace, r.FormValue("path")) statReq := provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: fn, - }, - }, + Ref: &provider.Reference{Path: fn}, } sublog := appctx.GetLogger(ctx).With().Str("path", fn).Logger() @@ -334,7 +331,7 @@ type PublicShareContextName string func (h *Handler) getShare(w http.ResponseWriter, r *http.Request, shareID string) { var share *conversions.ShareData - var resourceID *provider.ResourceId + var resourceID *provider.Reference ctx := r.Context() logger := appctx.GetLogger(r.Context()) logger.Debug().Str("shareID", shareID).Msg("get share by id") @@ -509,13 +506,7 @@ func (h *Handler) updateShare(w http.ResponseWriter, r *http.Request, shareID st return } - statReq := provider.StatRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: uRes.Share.ResourceId, - }, - }, - } + statReq := provider.StatRequest{Ref: uRes.Share.ResourceId} statRes, err := client.Stat(r.Context(), &statReq) if err != nil { @@ -625,8 +616,7 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { var info *provider.ResourceInfo if pinfo != nil { // check if the shared resource matches the path resource - if rs.Share.ResourceId.StorageId != pinfo.GetId().StorageId || - rs.Share.ResourceId.OpaqueId != pinfo.GetId().OpaqueId { + if !utils.ResourceEqual(rs.Share.ResourceId, pinfo.Id) { // try next share continue } @@ -772,8 +762,8 @@ func (h *Handler) addFilters(w http.ResponseWriter, r *http.Request, prefix stri return collaborationFilters, linkFilters, nil } -func wrapResourceID(r *provider.ResourceId) string { - return wrap(r.StorageId, r.OpaqueId) +func wrapResourceID(r *provider.Reference) string { + return wrap(r.StorageId, r.NodeId) } // The fileID must be encoded @@ -795,7 +785,7 @@ func (h *Handler) addFileInfo(ctx context.Context, s *conversions.ShareData, inf } s.MimeType = parsedMt // TODO STime: &types.Timestamp{Seconds: info.Mtime.Seconds, Nanos: info.Mtime.Nanos}, - s.StorageID = info.Id.StorageId + s.StorageID = info.Id.StorageId + "!" + info.Id.NodeId // TODO Storage: int s.ItemSource = wrapResourceID(info.Id) s.FileSource = s.ItemSource @@ -943,18 +933,12 @@ func (h *Handler) getAdditionalInfoAttribute(ctx context.Context, u *userIdentif func (h *Handler) getResourceInfoByPath(ctx context.Context, client gateway.GatewayAPIClient, path string) (*provider.ResourceInfo, *rpc.Status, error) { return h.getResourceInfo(ctx, client, path, &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: path, - }, + Path: path, }) } -func (h *Handler) getResourceInfoByID(ctx context.Context, client gateway.GatewayAPIClient, id *provider.ResourceId) (*provider.ResourceInfo, *rpc.Status, error) { - return h.getResourceInfo(ctx, client, wrapResourceID(id), &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: id, - }, - }) +func (h *Handler) getResourceInfoByID(ctx context.Context, client gateway.GatewayAPIClient, id *provider.Reference) (*provider.ResourceInfo, *rpc.Status, error) { + return h.getResourceInfo(ctx, client, wrapResourceID(id), id) } // getResourceInfo retrieves the resource info to a target. diff --git a/internal/http/services/owncloud/ocs/handlers/cloud/users/users.go b/internal/http/services/owncloud/ocs/handlers/cloud/users/users.go index 89538d075e..f99dbb6b46 100644 --- a/internal/http/services/owncloud/ocs/handlers/cloud/users/users.go +++ b/internal/http/services/owncloud/ocs/handlers/cloud/users/users.go @@ -126,13 +126,7 @@ func (h *Handler) handleUsers(w http.ResponseWriter, r *http.Request, u *userpb. return } - getQuotaRes, err := gc.GetQuota(ctx, &gateway.GetQuotaRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: getHomeRes.Path, - }, - }, - }) + getQuotaRes, err := gc.GetQuota(ctx, &gateway.GetQuotaRequest{Ref: getHomeRes.Ref}) if err != nil { sublog.Error().Err(err).Msg("error calling GetQuota") w.WriteHeader(http.StatusInternalServerError) diff --git a/pkg/app/app.go b/pkg/app/app.go index 4adb0904dd..1534094f2d 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -40,5 +40,5 @@ type ProviderInfo struct { // Provider is the interface that application providers implement // for providing the iframe location to a iframe UI Provider type Provider interface { - GetIFrame(ctx context.Context, resID *provider.ResourceId, token string) (string, error) + GetIFrame(ctx context.Context, resID *provider.Reference, token string) (string, error) } diff --git a/pkg/app/provider/demo/demo.go b/pkg/app/provider/demo/demo.go index 928c602b1b..ba934dac2c 100644 --- a/pkg/app/provider/demo/demo.go +++ b/pkg/app/provider/demo/demo.go @@ -32,8 +32,8 @@ type provider struct { iframeUIProvider string } -func (p *provider) GetIFrame(ctx context.Context, resID *providerpb.ResourceId, token string) (string, error) { - msg := fmt.Sprintf("