From f4321fc7f986db828495bcdab8eef95074c2d623 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] fix all 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 fix response format (#1724) [Build-deps]: Bump github.com/ReneKroon/ttlcache/v2 from 2.4.0 to 2.5.0 (#1728) [Build-deps]: Bump github.com/ory/fosite from 0.39.0 to 0.40.1 (#1726) Datatx createtransfershare (#1725) Co-authored-by: Ishank Arora fix publiclink download Signed-off-by: Jörn Friedrich Dreyer add changelog Signed-off-by: Jörn Friedrich Dreyer update to 3169b87 update usage of ResourceInfo.Ref -> ResourceInfo.Path ResourceInfo.Ref -> ResourceInfo.Path Signed-off-by: Jörn Friedrich Dreyer use string path --- changelog/unreleased/change-references.md | 8 + cmd/reva/download.go | 10 +- cmd/reva/ls.go | 6 +- cmd/reva/mkdir.go | 4 +- cmd/reva/mv.go | 8 +- cmd/reva/ocm-share-create.go | 12 +- cmd/reva/ocm-share-list-received.go | 4 +- cmd/reva/ocm-share-list.go | 16 +- cmd/reva/open-file-in-app-provider.go | 4 +- cmd/reva/open-in-app.go | 4 +- cmd/reva/public-share-create.go | 8 +- cmd/reva/public-share-list.go | 16 +- 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 | 9 +- cmd/reva/share-list-received.go | 4 +- cmd/reva/share-list.go | 16 +- cmd/reva/stat.go | 4 +- cmd/reva/transfer-create.go | 10 +- 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 | 15 +- .../services/gateway/publicshareprovider.go | 2 +- .../grpc/services/gateway/storageprovider.go | 267 ++++-------------- .../services/gateway/usershareprovider.go | 54 ++-- internal/grpc/services/ocmcore/ocmcore.go | 4 +- .../ocmshareprovider/ocmshareprovider.go | 2 +- .../publicstorageprovider.go | 34 +-- .../storageprovider/storageprovider.go | 45 +-- 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 +- .../services/owncloud/ocdav/publicfile.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 | 29 +- .../handlers/apps/sharing/shares/pending.go | 14 +- .../handlers/apps/sharing/shares/public.go | 10 +- .../handlers/apps/sharing/shares/remote.go | 2 +- .../handlers/apps/sharing/shares/shares.go | 56 ++-- .../ocs/handlers/apps/sharing/shares/user.go | 2 +- .../ocs/handlers/cloud/users/users.go | 8 +- pkg/app/app.go | 2 +- pkg/app/provider/demo/demo.go | 4 +- pkg/auth/scope/publicshare.go | 5 +- pkg/auth/scope/resourceinfo.go | 6 +- pkg/auth/scope/user.go | 6 +- pkg/cbox/publicshare/sql/sql.go | 8 +- pkg/cbox/share/sql/sql.go | 22 +- pkg/cbox/utils/conversions.go | 10 +- pkg/ocm/share/manager/json/json.go | 20 +- pkg/ocm/share/share.go | 2 +- pkg/publicshare/manager/json/json.go | 6 +- pkg/publicshare/manager/memory/memory.go | 7 +- 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 | 6 +- pkg/sdk/action/fileops.go | 20 +- pkg/sdk/action/upload.go | 6 +- pkg/share/cache/cbox/cbox.go | 8 +- pkg/share/manager/json/json.go | 16 +- pkg/share/manager/memory/memory.go | 16 +- pkg/storage/fs/owncloud/owncloud.go | 53 ++-- pkg/storage/fs/s3/s3.go | 27 +- 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 | 52 +--- 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 | 7 +- 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 | 39 +-- pkg/storage/utils/localfs/localfs.go | 36 +-- pkg/token/manager/demo/demo_test.go | 6 +- pkg/utils/utils.go | 4 +- .../integration/grpc/storageprovider_test.go | 57 ++-- 99 files changed, 555 insertions(+), 965 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/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..085af1bda6 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() @@ -70,7 +68,7 @@ func lsCommand() *command { for _, info := range infos { p := info.Path if !*fullFlag { - p = path.Base(info.Path) + p = path.Base(p) } if len(w) == 0 { if *longFlag { 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..509fffd2e5 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 { @@ -126,14 +124,14 @@ func ocmShareCreateCommand() *command { }, "name": &types.OpaqueEntry{ Decoder: "plain", - Value: []byte(res.Info.Path), + Value: []byte(res.Info.Path), // TODO what reference should be used here? }, }, } shareRequest := &ocm.CreateOCMShareRequest{ Opaque: opaqueObj, - ResourceId: res.Info.Id, + Ref: res.Info.Id, Grant: grant, RecipientMeshProvider: providerInfo.ProviderInfo, } @@ -149,11 +147,11 @@ func ocmShareCreateCommand() *command { t := table.NewWriter() t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"}) + t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "Reference", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"}) s := shareRes.Share t.AppendRows([]table.Row{ - {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), + {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.Ref.String(), s.Permissions.String(), s.Grantee.Type.String(), s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId, time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)}, }) diff --git a/cmd/reva/ocm-share-list-received.go b/cmd/reva/ocm-share-list-received.go index 851264c7b9..76a1511abe 100644 --- a/cmd/reva/ocm-share-list-received.go +++ b/cmd/reva/ocm-share-list-received.go @@ -54,11 +54,11 @@ func ocmShareListReceivedCommand() *command { if len(w) == 0 { t := table.NewWriter() t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", + t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "Reference", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated", "State", "ShareType"}) for _, s := range shareRes.Shares { t.AppendRows([]table.Row{ - {s.Share.Id.OpaqueId, s.Share.Owner.Idp, s.Share.Owner.OpaqueId, s.Share.ResourceId.String(), + {s.Share.Id.OpaqueId, s.Share.Owner.Idp, s.Share.Owner.OpaqueId, s.Share.Ref.String(), s.Share.Permissions.String(), s.Share.Grantee.Type.String(), s.Share.Grantee.GetUserId().Idp, s.Share.Grantee.GetUserId().OpaqueId, time.Unix(int64(s.Share.Ctime.Seconds), 0), time.Unix(int64(s.Share.Mtime.Seconds), 0), s.State.String(), s.Share.ShareType.String()}, diff --git a/cmd/reva/ocm-share-list.go b/cmd/reva/ocm-share-list.go index 06b8836c9b..bd753cee80 100644 --- a/cmd/reva/ocm-share-list.go +++ b/cmd/reva/ocm-share-list.go @@ -52,19 +52,19 @@ func ocmShareListCommand() *command { shareRequest := &ocm.ListOCMSharesRequest{} if *resID != "" { // check split by colon (:) - tokens := strings.Split(*resID, ":") + tokens := strings.Split(*resID, ":") // TODO fuuuuuck should use ! which is ugly on cli because it needs escaping ... RAAHHHHH if len(tokens) != 2 { return fmt.Errorf("resource id invalid") } - id := &provider.ResourceId{ + ref := &provider.Reference{ StorageId: tokens[0], - OpaqueId: tokens[1], + NodeId: tokens[1], } shareRequest.Filters = []*ocm.ListOCMSharesRequest_Filter{ &ocm.ListOCMSharesRequest_Filter{ - Type: ocm.ListOCMSharesRequest_Filter_TYPE_RESOURCE_ID, - Term: &ocm.ListOCMSharesRequest_Filter_ResourceId{ - ResourceId: id, + Type: ocm.ListOCMSharesRequest_Filter_TYPE_REFERENCE, + Term: &ocm.ListOCMSharesRequest_Filter_Ref{ + Ref: ref, }, }, } @@ -82,12 +82,12 @@ func ocmShareListCommand() *command { if len(w) == 0 { t := table.NewWriter() t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", + t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "Reference", "Permissions", "Type", "ShareType", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"}) for _, s := range shareRes.Shares { t.AppendRows([]table.Row{ - {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), + {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.Ref.String(), s.Permissions.String(), s.Grantee.Type.String(), s.ShareType.String(), s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId, time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)}, }) 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..d6fd70974b 100644 --- a/cmd/reva/open-in-app.go +++ b/cmd/reva/open-in-app.go @@ -61,9 +61,7 @@ func openInAppCommand() *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/public-share-create.go b/cmd/reva/public-share-create.go index b50af172a5..26f7c50bb2 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) @@ -93,11 +91,11 @@ func publicShareCreateCommand() *command { t := table.NewWriter() t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Token", "Expiration", "Created", "Updated"}) + t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "Reference", "Permissions", "Token", "Expiration", "Created", "Updated"}) s := shareRes.Share t.AppendRows([]table.Row{ - {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), s.Token, s.Expiration.String(), time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)}, + {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.Ref.String(), s.Permissions.String(), s.Token, s.Expiration.String(), time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)}, }) t.Render() diff --git a/cmd/reva/public-share-list.go b/cmd/reva/public-share-list.go index b8dbf322ce..423dfa23ca 100644 --- a/cmd/reva/public-share-list.go +++ b/cmd/reva/public-share-list.go @@ -52,19 +52,19 @@ func publicShareListCommand() *command { shareRequest := &link.ListPublicSharesRequest{} if *resID != "" { // check split by colon (:) - tokens := strings.Split(*resID, ":") + tokens := strings.Split(*resID, ":") // TODO fuuuuuck should use ! which is ugly on cli because it needs escaping ... RAAHHHHH if len(tokens) != 2 { return fmt.Errorf("resource id invalid") } - id := &provider.ResourceId{ + ref := &provider.Reference{ StorageId: tokens[0], - OpaqueId: tokens[1], + NodeId: tokens[1], } shareRequest.Filters = []*link.ListPublicSharesRequest_Filter{ &link.ListPublicSharesRequest_Filter{ - Type: link.ListPublicSharesRequest_Filter_TYPE_RESOURCE_ID, - Term: &link.ListPublicSharesRequest_Filter_ResourceId{ - ResourceId: id, + Type: link.ListPublicSharesRequest_Filter_TYPE_REFERENCE, + Term: &link.ListPublicSharesRequest_Filter_Ref{ + Ref: ref, }, }, } @@ -82,11 +82,11 @@ func publicShareListCommand() *command { if len(w) == 0 { t := table.NewWriter() t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Token", "Expiration", "Created", "Updated"}) + t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "Reference", "Permissions", "Token", "Expiration", "Created", "Updated"}) for _, s := range shareRes.Share { t.AppendRows([]table.Row{ - {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), s.Token, s.Expiration.String(), time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)}, + {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.Ref.String(), s.Permissions.String(), s.Token, s.Expiration.String(), time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)}, }) } t.Render() 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..e0e1e1eb5f 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 { @@ -123,7 +120,7 @@ func shareCreateCommand() *command { t := table.NewWriter() t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"}) + t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "Reference", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"}) s := shareRes.Share var idp, opaque string @@ -133,7 +130,7 @@ func shareCreateCommand() *command { idp, opaque = s.Grantee.GetGroupId().Idp, s.Grantee.GetGroupId().OpaqueId } t.AppendRows([]table.Row{ - {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), + {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.Ref.String(), s.Permissions.String(), s.Grantee.Type.String(), idp, opaque, time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)}, }) diff --git a/cmd/reva/share-list-received.go b/cmd/reva/share-list-received.go index 97c7d82b19..e97e00accb 100644 --- a/cmd/reva/share-list-received.go +++ b/cmd/reva/share-list-received.go @@ -55,7 +55,7 @@ func shareListReceivedCommand() *command { if len(w) == 0 { t := table.NewWriter() t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", + t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "Reference", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated", "State"}) for _, s := range shareRes.Shares { var idp, opaque string @@ -65,7 +65,7 @@ func shareListReceivedCommand() *command { idp, opaque = s.Share.Grantee.GetGroupId().Idp, s.Share.Grantee.GetGroupId().OpaqueId } t.AppendRows([]table.Row{ - {s.Share.Id.OpaqueId, s.Share.Owner.Idp, s.Share.Owner.OpaqueId, s.Share.ResourceId.String(), + {s.Share.Id.OpaqueId, s.Share.Owner.Idp, s.Share.Owner.OpaqueId, s.Share.Ref.String(), s.Share.Permissions.String(), s.Share.Grantee.Type.String(), idp, opaque, time.Unix(int64(s.Share.Ctime.Seconds), 0), time.Unix(int64(s.Share.Mtime.Seconds), 0), s.State.String()}, diff --git a/cmd/reva/share-list.go b/cmd/reva/share-list.go index 73b005d0cd..78d3d5038f 100644 --- a/cmd/reva/share-list.go +++ b/cmd/reva/share-list.go @@ -52,19 +52,19 @@ func shareListCommand() *command { shareRequest := &collaboration.ListSharesRequest{} if *resID != "" { // check split by colon (:) - tokens := strings.Split(*resID, ":") + tokens := strings.Split(*resID, ":") // TODO fuuuuuck should use ! which is ugly on cli because it needs escaping ... RAAHHHHH if len(tokens) != 2 { return fmt.Errorf("resource id invalid") } - id := &provider.ResourceId{ + ref := &provider.Reference{ StorageId: tokens[0], - OpaqueId: tokens[1], + NodeId: tokens[1], } shareRequest.Filters = []*collaboration.ListSharesRequest_Filter{ &collaboration.ListSharesRequest_Filter{ - Type: collaboration.ListSharesRequest_Filter_TYPE_RESOURCE_ID, - Term: &collaboration.ListSharesRequest_Filter_ResourceId{ - ResourceId: id, + Type: collaboration.ListSharesRequest_Filter_TYPE_REFERENCE, + Term: &collaboration.ListSharesRequest_Filter_Ref{ + Ref: ref, }, }, } @@ -82,7 +82,7 @@ func shareListCommand() *command { if len(w) == 0 { t := table.NewWriter() t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", + t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "Reference", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"}) for _, s := range shareRes.Shares { @@ -93,7 +93,7 @@ func shareListCommand() *command { idp, opaque = s.Grantee.GetGroupId().Idp, s.Grantee.GetGroupId().OpaqueId } t.AppendRows([]table.Row{ - {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), + {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.Ref.String(), s.Permissions.String(), s.Grantee.Type.String(), idp, opaque, time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)}, }) 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..1f13e8ac9d 100644 --- a/cmd/reva/transfer-create.go +++ b/cmd/reva/transfer-create.go @@ -79,9 +79,7 @@ func transferCreateCommand() *command { // verify resource stats statReq := &provider.StatRequest{ Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: fn, - }, + Path: fn, }, } statRes, err := client.Stat(ctx, statReq) @@ -126,7 +124,7 @@ func transferCreateCommand() *command { }, }, }, - ResourceId: statRes.Info.Id, + Ref: statRes.Info.Id, Grant: &ocm.ShareGrant{ Grantee: &provider.Grantee{ Type: gt, @@ -155,11 +153,11 @@ func transferCreateCommand() *command { t := table.NewWriter() t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "ShareType", "Created", "Updated"}) + t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "Reference", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "ShareType", "Created", "Updated"}) s := createShareResponse.Share t.AppendRows([]table.Row{ - {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), + {s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.Ref.String(), s.Permissions.String(), s.Grantee.Type.String(), s.Grantee.GetUserId().Idp, s.Grantee.GetUserId().OpaqueId, s.ShareType.String(), time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)}, }) 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 e366171737..7dec468776 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-20210602144930-1f2e59cb157a 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 bb20fe3759..8f4fcffd3e 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-20210602144930-1f2e59cb157a h1:3LSlFRGsRtP49N5K1Yxi2uzxZ3RLLlJxxQlcrT7/RF0= +github.com/butonic/go-cs3apis v0.0.0-20210602144930-1f2e59cb157a/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= @@ -150,8 +152,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..8420bc61c4 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.Ref} 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..881b680eae 100644 --- a/internal/grpc/services/gateway/ocmshareprovider.go +++ b/internal/grpc/services/gateway/ocmshareprovider.go @@ -54,7 +54,7 @@ func (s *svc) CreateOCMShare(ctx context.Context, req *ocm.CreateOCMShareRequest // TODO(labkode): if both commits are enabled they could be done concurrently. if s.c.CommitShareToStorageGrant { - addGrantStatus, err := s.addGrant(ctx, req.ResourceId, req.Grant.Grantee, req.Grant.Permissions.Permissions) + addGrantStatus, err := s.addGrant(ctx, req.Ref, req.Grant.Grantee, req.Grant.Permissions.Permissions) if err != nil { return nil, errors.Wrap(err, "gateway: error adding OCM grant to storage") } @@ -109,7 +109,7 @@ func (s *svc) RemoveOCMShare(ctx context.Context, req *ocm.RemoveOCMShareRequest // TODO(labkode): if both commits are enabled they could be done concurrently. if s.c.CommitShareToStorageGrant { - removeGrantStatus, err := s.removeGrant(ctx, share.ResourceId, share.Grantee, share.Permissions.Permissions) + removeGrantStatus, err := s.removeGrant(ctx, share.Ref, share.Grantee, share.Permissions.Permissions) if err != nil { return nil, errors.Wrap(err, "gateway: error removing OCM grant from storage") } @@ -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,22 @@ 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 { + // FIXME: @butonic REFERENCE // 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/publicshareprovider.go b/internal/grpc/services/gateway/publicshareprovider.go index 88bb41b1c9..c60ce4a6e2 100644 --- a/internal/grpc/services/gateway/publicshareprovider.go +++ b/internal/grpc/services/gateway/publicshareprovider.go @@ -30,7 +30,7 @@ import ( ) func (s *svc) CreatePublicShare(ctx context.Context, req *link.CreatePublicShareRequest) (*link.CreatePublicShareResponse, error) { - if s.isSharedFolder(ctx, req.ResourceInfo.GetPath()) { + if s.isSharedFolder(ctx, req.ResourceInfo.Path) { // FIXME @butonic REFERENCE ... pass ref to isSharedFolder? return nil, errtypes.AlreadyExists("gateway: can't create a public share of the share folder itself") } diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index 90a5a04272..0b64dfb026 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 @butonic 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 @butonic 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 = ri.Id + log.Debug().Str("storage", req.Ref.StorageId).Str("node", req.Ref.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", req.Ref.StorageId).Str("node", req.Ref.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 = ri.Id + 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.Ref} statRes, err := s.stat(ctx, statReq) if err != nil { err = errors.Wrap(err, "gateway: error stating ref:"+statReq.Ref.String()) @@ -656,7 +622,7 @@ func (s *svc) GetPath(ctx context.Context, req *provider.GetPathRequest) (*provi return &provider.GetPathResponse{ Status: statRes.Status, - Path: statRes.GetInfo().GetPath(), + Ref: statRes.GetInfo().GetId(), }, nil } @@ -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"), @@ -1079,7 +1003,7 @@ func (s *svc) statHome(ctx context.Context) (*provider.StatResponse, error) { }, nil } - if etagIface, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path); err == nil { + if etagIface, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path); err == nil { // FIXME @butonic REFERENCE also use node fo etag cache? resMtime := utils.TSToTime(statRes.Info.Mtime) resEtag := etagIface.(etagWithTS) // Use the updated etag if the home folder has been modified @@ -1089,7 +1013,7 @@ func (s *svc) statHome(ctx context.Context) (*provider.StatResponse, error) { } else { statRes.Info.Etag = etag.GenerateEtagFromResources(statRes.Info, []*provider.ResourceInfo{statSharedFolder.Info}) if s.c.EtagCacheTTL > 0 { - _ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path, etagWithTS{statRes.Info.Etag, time.Now()}) + _ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path, etagWithTS{statRes.Info.Etag, time.Now()}) // FIXME @butonic REFERENCE also use node fo etag cache? } } @@ -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"), @@ -1128,7 +1046,7 @@ func (s *svc) statSharesFolder(ctx context.Context) (*provider.StatResponse, err }, nil } - if etagIface, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path); err == nil { + if etagIface, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path); err == nil { // FIXME @butonic REFERENCE also use node fo etag cache? resMtime := utils.TSToTime(statRes.Info.Mtime) resEtag := etagIface.(etagWithTS) // Use the updated etag if the shares folder has been modified, i.e., a new @@ -1139,7 +1057,7 @@ func (s *svc) statSharesFolder(ctx context.Context) (*provider.StatResponse, err } else { statRes.Info.Etag = etag.GenerateEtagFromResources(statRes.Info, lsRes.Infos) if s.c.EtagCacheTTL > 0 { - _ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path, etagWithTS{statRes.Info.Etag, time.Now()}) + _ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path, etagWithTS{statRes.Info.Etag, time.Now()}) // FIXME @butonic REFERENCE also use node fo etag cache? } } return statRes, nil @@ -1154,6 +1072,7 @@ func (s *svc) stat(ctx context.Context, req *provider.StatRequest) (*provider.St } resPath := req.Ref.GetPath() + // do we have an exact match for the provider? if len(providers) == 1 && (resPath == "" || strings.HasPrefix(resPath, providers[0].ProviderPath)) { c, err := s.getStorageProviderClient(ctx, providers[0]) if err != nil { @@ -1164,6 +1083,9 @@ func (s *svc) stat(ctx context.Context, req *provider.StatRequest) (*provider.St return c.Stat(ctx, req) } + // stat all found providers + // TODO why would we have more than one provider? shouldnt the reference always be good enough for a storage provider? regardless of the properties that are set + // if the reference only has a path the storage registry will send us to the correct provider, right? infoFromProviders := make([]*provider.ResourceInfo, len(providers)) errors := make([]error, len(providers)) var wg sync.WaitGroup @@ -1190,12 +1112,12 @@ 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{ - StorageId: "/", - OpaqueId: uuid.New().String(), + Id: &provider.Reference{ + StorageId: "/", // TODO what would this mean? + NodeId: uuid.New().String(), }, Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER, - Path: resPath, + Path: resPath, // TODO this is an absolute path ... we should only return the name Size: totalSize, }, }, nil @@ -1214,13 +1136,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 +1212,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 +1248,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 +1311,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 +1349,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 { @@ -1487,13 +1385,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 +1416,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 +1464,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 +1495,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 +1526,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 +1574,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 +1603,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 +1651,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 +1681,8 @@ 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() != "" { + 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 +1692,9 @@ func (s *svc) getPath(ctx context.Context, ref *provider.Reference, keys ...stri return res.Info.Path, res.Status } + if ref.Path != "" { + return ref.Path, &rpc.Status{Code: rpc.Code_CODE_OK} + } return "", &rpc.Status{Code: rpc.Code_CODE_INTERNAL} } @@ -2017,21 +1883,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) } @@ -2064,7 +1917,7 @@ func (s *svc) findProviders(ctx context.Context, ref *provider.Reference) ([]*re }) if err != nil { - return nil, errors.Wrap(err, "gateway: error calling GetStorageProvider") + return nil, errors.Wrap(err, "gateway: error calling GetStorageProviders") } if res.Status.Code != rpc.Code_CODE_OK { diff --git a/internal/grpc/services/gateway/usershareprovider.go b/internal/grpc/services/gateway/usershareprovider.go index 175258765f..9022d3d577 100644 --- a/internal/grpc/services/gateway/usershareprovider.go +++ b/internal/grpc/services/gateway/usershareprovider.go @@ -36,7 +36,7 @@ import ( // TODO(labkode): add multi-phase commit logic when commit share or commit ref is enabled. func (s *svc) CreateShare(ctx context.Context, req *collaboration.CreateShareRequest) (*collaboration.CreateShareResponse, error) { - if s.isSharedFolder(ctx, req.ResourceInfo.GetPath()) { + if s.isSharedFolder(ctx, req.ResourceInfo.Path) { // FIXME @butonic REFERENCE ... pass ref to isSharedFolder? return nil, errtypes.AlreadyExists("gateway: can't share the share folder itself") } @@ -118,7 +118,7 @@ func (s *svc) RemoveShare(ctx context.Context, req *collaboration.RemoveShareReq // TODO(labkode): if both commits are enabled they could be done concurrently. if s.c.CommitShareToStorageGrant { - removeGrantStatus, err := s.removeGrant(ctx, share.ResourceId, share.Grantee, share.Permissions.Permissions) + removeGrantStatus, err := s.removeGrant(ctx, share.Ref, share.Grantee, share.Permissions.Permissions) if err != nil { return nil, errors.Wrap(err, "gateway: error removing grant from storage") } @@ -196,7 +196,7 @@ func (s *svc) UpdateShare(ctx context.Context, req *collaboration.UpdateShareReq // TODO(labkode): if both commits are enabled they could be done concurrently. if s.c.CommitShareToStorageGrant { - updateGrantStatus, err := s.updateGrant(ctx, res.GetShare().GetResourceId(), + updateGrantStatus, err := s.updateGrant(ctx, res.GetShare().GetRef(), res.GetShare().GetGrantee(), res.GetShare().GetPermissions().GetPermissions()) @@ -300,7 +300,7 @@ func (s *svc) UpdateReceivedShare(ctx context.Context, req *collaboration.Update if share == nil { panic("gateway: error updating a received share: the share is nil") } - createRefStatus := s.createReference(ctx, share.Share.ResourceId) + createRefStatus := s.createReference(ctx, share.Share.Ref) rsp := &collaboration.UpdateReceivedShareResponse{Status: createRefStatus} if createRefStatus.Code == rpc.Code_CODE_OK { @@ -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.StorageId, resourceID.NodeId), } 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/ocmshareprovider/ocmshareprovider.go b/internal/grpc/services/ocmshareprovider/ocmshareprovider.go index 1b4e8676db..ff120bd6dd 100644 --- a/internal/grpc/services/ocmshareprovider/ocmshareprovider.go +++ b/internal/grpc/services/ocmshareprovider/ocmshareprovider.go @@ -161,7 +161,7 @@ func (s *service) CreateOCMShare(ctx context.Context, req *ocm.CreateOCMShareReq } } - share, err := s.sm.Share(ctx, req.ResourceId, req.Grant, name, req.RecipientMeshProvider, permissions, nil, "", sharetype) + share, err := s.sm.Share(ctx, req.Ref, req.Grant, name, req.RecipientMeshProvider, permissions, nil, "", sharetype) if err != nil { return &ocm.CreateOCMShareResponse{ Status: status.NewInternal(ctx, err, "error creating share"), diff --git a/internal/grpc/services/publicstorageprovider/publicstorageprovider.go b/internal/grpc/services/publicstorageprovider/publicstorageprovider.go index b941b9b110..e1dbcb237e 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() == "" { @@ -698,7 +684,7 @@ func (s *service) resolveToken(ctx context.Context, token string) (string, *link } pathRes, err := s.gateway.GetPath(ctx, &provider.GetPathRequest{ - ResourceId: publicShareResponse.GetShare().GetResourceId(), + Ref: publicShareResponse.GetShare().GetRef(), }) switch { case err != nil: @@ -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().GetRef(), }) switch { case err != nil: @@ -720,5 +702,5 @@ func (s *service) resolveToken(ctx context.Context, token string) (string, *link case sRes.Status.Code != rpc.Code_CODE_OK: return "", nil, nil, sRes.Status, nil } - return pathRes.Path, publicShareResponse.GetShare(), sRes.Info, nil, nil + return pathRes.Ref.Path, publicShareResponse.GetShare(), sRes.Info, nil, nil } diff --git a/internal/grpc/services/storageprovider/storageprovider.go b/internal/grpc/services/storageprovider/storageprovider.go index 7785771fcb..e2f2d59811 100644 --- a/internal/grpc/services/storageprovider/storageprovider.go +++ b/internal/grpc/services/storageprovider/storageprovider.go @@ -380,7 +380,7 @@ func (s *service) InitiateFileUpload(ctx context.Context, req *provider.Initiate func (s *service) GetPath(ctx context.Context, req *provider.GetPathRequest) (*provider.GetPathResponse, error) { // TODO(labkode): check that the storage ID is the same as the storage provider id. - fn, err := s.storage.GetPathByID(ctx, req.ResourceId) + fn, err := s.storage.GetPathByID(ctx, req.Ref) if err != nil { return &provider.GetPathResponse{ Status: status.NewInternal(ctx, err, "error getting path by id"), @@ -389,7 +389,8 @@ func (s *service) GetPath(ctx context.Context, req *provider.GetPathRequest) (*p fn = path.Join(s.mountPath, path.Clean(fn)) res := &provider.GetPathResponse{ - Path: fn, + // FIXME @butonic REFERENCE return StorageId, NodeId and relative path if request contains ids? + Ref: &provider.Reference{Path: fn}, Status: status.NewOK(ctx), } return res, nil @@ -400,7 +401,8 @@ func (s *service) GetHome(ctx context.Context, req *provider.GetHomeRequest) (*p res := &provider.GetHomeResponse{ Status: status.NewOK(ctx), - Path: home, + // FIXME @butonic REFERENCE return StorageId, NodeId and relative path if request contains ids + Ref: &provider.Reference{Path: home}, // FIXME @butonic REFERENCE this is a configured mount path ... why } return res, nil @@ -816,7 +818,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 +841,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 +1030,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 +1097,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() == "" { @@ -1120,16 +1107,12 @@ func (s *service) unwrap(ctx context.Context, ref *provider.Reference) (*provide } fn := ref.GetPath() - fsfn, err := s.trimMountPrefix(fn) + fsfn, err := s.trimMountPrefix(fn) // FIXME @butonic REFERENCE nooooo the provider should not know where it is mounted if err != nil { return nil, err } - pathRef := &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: fsfn, - }, - } + pathRef := &provider.Reference{Path: fsfn} return pathRef, nil } @@ -1146,6 +1129,6 @@ func (s *service) wrap(ctx context.Context, ri *provider.ResourceInfo) error { // For wrapper drivers, the storage ID might already be set. In that case, skip setting it ri.Id.StorageId = s.mountID } - ri.Path = path.Join(s.mountPath, ri.Path) + ri.Path = path.Join(s.mountPath, ri.Path) // FIXME @butonic REFERENCE nooooo the provider should not know where it is mounted return 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/publicfile.go b/internal/http/services/owncloud/ocdav/publicfile.go index c5670014f0..ebf7394e1e 100644 --- a/internal/http/services/owncloud/ocdav/publicfile.go +++ b/internal/http/services/owncloud/ocdav/publicfile.go @@ -102,7 +102,7 @@ func (s *svc) adjustResourcePathInURL(w http.ResponseWriter, r *http.Request) bo return false } pathRes, err := client.GetPath(ctx, &provider.GetPathRequest{ - ResourceId: tokenStatInfo.GetId(), + Ref: tokenStatInfo.GetId(), }) if err != nil { sublog.Error().Msg("Could not get path of resource") @@ -113,10 +113,10 @@ func (s *svc) adjustResourcePathInURL(w http.ResponseWriter, r *http.Request) bo HandleErrorStatus(&sublog, w, pathRes.Status) return false } - if path.Base(r.URL.Path) != path.Base(pathRes.Path) { + if path.Base(r.URL.Path) != path.Base(pathRes.Ref.Path) { sublog.Debug(). Str("requestbase", path.Base(r.URL.Path)). - Str("pathbase", path.Base(pathRes.Path)). + Str("pathbase", path.Base(pathRes.Ref.Path)). Msg("base paths don't match") w.WriteHeader(http.StatusConflict) return false @@ -166,7 +166,7 @@ func (s *svc) handlePropfindOnToken(w http.ResponseWriter, r *http.Request, ns s // find actual file name pathRes, err := client.GetPath(ctx, &provider.GetPathRequest{ - ResourceId: tokenStatInfo.GetId(), + Ref: tokenStatInfo.GetId(), }) if err != nil { sublog.Warn().Msg("Could not get path of resource") @@ -178,13 +178,13 @@ func (s *svc) handlePropfindOnToken(w http.ResponseWriter, r *http.Request, ns s return } - if !onContainer && path.Base(r.URL.Path) != path.Base(pathRes.Path) { + if !onContainer && path.Base(r.URL.Path) != path.Base(pathRes.Ref.Path) { // if queried on the wrong path, return not found w.WriteHeader(http.StatusNotFound) return } // adjust path - tokenStatInfo.Path = path.Join("/", tokenStatInfo.Path, path.Base(pathRes.Path)) + tokenStatInfo.Path = path.Join("/", tokenStatInfo.Path, path.Base(pathRes.Ref.Path)) infos := s.getPublicFileInfos(onContainer, depth == "0", tokenStatInfo) 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..b547aa6a92 100644 --- a/internal/http/services/owncloud/ocdav/versions.go +++ b/internal/http/services/owncloud/ocdav/versions.go @@ -42,17 +42,17 @@ 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, ref *provider.Reference) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - if rid == (*provider.ResourceId)(nil) { + if ref == nil { http.Error(w, "404 Not Found", http.StatusNotFound) return } // baseURI is encoded as part of the response payload in href field - baseURI := path.Join(ctx.Value(ctxKeyBaseURI).(string), wrapResourceID(rid)) + baseURI := path.Join(ctx.Value(ctxKeyBaseURI).(string), wrapResourceID(ref)) ctx = context.WithValue(ctx, ctxKeyBaseURI, baseURI) r = r.WithContext(ctx) @@ -63,14 +63,14 @@ func (h *VersionsHandler) Handler(s *svc, rid *provider.ResourceId) http.Handler return } if key == "" && r.Method == "PROPFIND" { - h.doListVersions(w, r, s, rid) + h.doListVersions(w, r, s, ref) return } if key != "" && r.Method == "COPY" { // TODO(jfd) it seems we cannot directly GET version content with cs3 ... // TODO(jfd) cs3api has no delete file version call // TODO(jfd) restore version to given Destination, but cs3api has no destination - h.doRestore(w, r, s, rid, key) + h.doRestore(w, r, s, ref, key) return } @@ -78,12 +78,12 @@ 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, ref *provider.Reference) { ctx := r.Context() ctx, span := trace.StartSpan(ctx, "listVersions") defer span.End() - sublog := appctx.GetLogger(ctx).With().Interface("resourceid", rid).Logger() + sublog := appctx.GetLogger(ctx).With().Interface("reference", ref).Logger() pf, status, err := readPropfind(r.Body) if err != nil { @@ -99,9 +99,6 @@ 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} res, err := client.Stat(ctx, req) 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,12 +175,12 @@ 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, ref *provider.Reference, key string) { ctx := r.Context() ctx, span := trace.StartSpan(ctx, "restore") defer span.End() - sublog := appctx.GetLogger(ctx).With().Interface("resourceid", rid).Str("key", key).Logger() + sublog := appctx.GetLogger(ctx).With().Interface("reference", ref).Str("key", key).Logger() client, err := s.getClient() if err != nil { @@ -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: ref, Key: key, } diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/pending.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/pending.go index 33636f3227..f046acf5c4 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/pending.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/pending.go @@ -82,7 +82,7 @@ func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, sh rs := shareRes.GetShare() - info, status, err := h.getResourceInfoByID(ctx, client, rs.Share.ResourceId) + info, status, err := h.getResourceInfoByID(ctx, client, rs.Share.Ref) if err != nil || status.Code != rpc.Code_CODE_OK { h.logProblems(status, err, "could not stat, skipping") } @@ -101,7 +101,17 @@ func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, sh if data.State == ocsStateAccepted { // Needed because received shares can be jailed in a folder in the users home - data.FileTarget = path.Join(h.sharePrefix, path.Base(info.Path)) + // FIXME @butonic REFERENCE these would use the /dav/spaces endpoint with a storageid,nodeid and a relative path + // what do we need to do to get absolute paths from the gateway? + // send references with the path only set? + // The registry would route them to the closest matching path + // The storage provider would else see a reference that only has the path set? + // So it would have to resolve the storage based on the path, which is driver specific + // And it could return an absolute path ... and no id set in the 'Path' of the Ref property of ResourceInfos + // But if a request DOES use an id, the Ref contains the same id? at least in the Ref part of the ResouceInfo + // In the Id of a Resoucre info the storageid and node id are always set. + // so ... if info.Ref.StorageId != "" -> use /dav/spaces path, otherwise use path and append it to webdav endpoint + data.FileTarget = path.Join(h.sharePrefix, path.Base(info.Path)) // FIXME @butonic REFERENCES use same "wrong" path!!!! data.Path = path.Join(h.sharePrefix, path.Base(info.Path)) } 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..13ebe89904 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 @@ -160,7 +160,7 @@ func (h *Handler) listPublicShares(r *http.Request, filters []*link.ListPublicSh } for _, share := range res.GetShare() { - info, status, err := h.getResourceInfoByID(ctx, client, share.ResourceId) + info, status, err := h.getResourceInfoByID(ctx, client, share.Ref) if err != nil || status.Code != rpc.Code_CODE_OK { log.Debug().Interface("share", share).Interface("status", status).Err(err).Msg("could not stat share, skipping") continue @@ -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.Ref} statRes, err := gwC.Stat(r.Context(), &statReq) if err != nil { diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/remote.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/remote.go index f77db99cf6..c296593839 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/remote.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/remote.go @@ -89,7 +89,7 @@ func (h *Handler) createFederatedCloudShare(w http.ResponseWriter, r *http.Reque }, }, }, - ResourceId: statInfo.Id, + Ref: statInfo.Id, Grant: &ocm.ShareGrant{ Grantee: &provider.Grantee{ Type: provider.GranteeType_GRANTEE_TYPE_USER, 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..e649a9ae8c 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") @@ -374,7 +371,7 @@ func (h *Handler) getShare(w http.ResponseWriter, r *http.Request, shareID strin if err == nil && psRes.GetShare() != nil { share = conversions.PublicShare2ShareData(psRes.Share, r, h.publicURL) - resourceID = psRes.Share.ResourceId + resourceID = psRes.Share.Ref } if share == nil { @@ -407,7 +404,7 @@ func (h *Handler) getShare(w http.ResponseWriter, r *http.Request, shareID strin */ if err == nil && uRes.GetShare() != nil { - resourceID = uRes.Share.ResourceId + resourceID = uRes.Share.Ref share, err = conversions.CS3Share2ShareData(ctx, uRes.Share) if err != nil { response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error mapping share data", err) @@ -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.Ref} 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.Ref, pinfo.Id) { // try next share continue } @@ -634,7 +624,7 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { info = pinfo } else { var status *rpc.Status - info, status, err = h.getResourceInfoByID(ctx, client, rs.Share.ResourceId) + info, status, err = h.getResourceInfoByID(ctx, client, rs.Share.Ref) if err != nil || status.Code != rpc.Code_CODE_OK { h.logProblems(status, err, "could not stat, skipping") continue @@ -756,24 +746,24 @@ func (h *Handler) addFilters(w http.ResponseWriter, r *http.Request, prefix stri } collaborationFilters = append(collaborationFilters, &collaboration.ListSharesRequest_Filter{ - Type: collaboration.ListSharesRequest_Filter_TYPE_RESOURCE_ID, - Term: &collaboration.ListSharesRequest_Filter_ResourceId{ - ResourceId: info.Id, + Type: collaboration.ListSharesRequest_Filter_TYPE_REFERENCE, + Term: &collaboration.ListSharesRequest_Filter_Ref{ + Ref: info.Id, }, }) linkFilters = append(linkFilters, &link.ListPublicSharesRequest_Filter{ - Type: link.ListPublicSharesRequest_Filter_TYPE_RESOURCE_ID, - Term: &link.ListPublicSharesRequest_Filter_ResourceId{ - ResourceId: info.Id, + Type: link.ListPublicSharesRequest_Filter_TYPE_REFERENCE, + Term: &link.ListPublicSharesRequest_Filter_Ref{ + Ref: info.Id, }, }) 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/apps/sharing/shares/user.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go index 1a133f34b6..2bc9241963 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go @@ -153,7 +153,7 @@ func (h *Handler) listUserShares(r *http.Request, filters []*collaboration.ListS continue } - info, status, err := h.getResourceInfoByID(ctx, client, s.ResourceId) + info, status, err := h.getResourceInfoByID(ctx, client, s.Ref) if err != nil || status.Code != rpc.Code_CODE_OK { log.Debug().Interface("share", s).Interface("status", status).Interface("shareData", data).Err(err).Msg("could not stat share, skipping") continue 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("