From 78e1e4bf0a448413244406ee3618c22a13aa0486 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 --- cmd/reva/arguments.go | 2 +- cmd/reva/download.go | 10 +- cmd/reva/ls.go | 8 +- 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/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/upload.go | 14 +- examples/sdk/sdk.go | 8 +- go.mod | 1 + go.sum | 4 +- internal/grpc/interceptors/auth/auth.go | 10 +- .../grpc/services/appprovider/appprovider.go | 4 +- internal/grpc/services/gateway/appprovider.go | 12 +- .../grpc/services/gateway/ocmshareprovider.go | 9 +- .../services/gateway/publicshareprovider.go | 2 +- .../grpc/services/gateway/storageprovider.go | 306 +++++------------- .../services/gateway/usershareprovider.go | 54 ++-- .../services/gateway/webdavstorageprovider.go | 2 +- internal/grpc/services/ocmcore/ocmcore.go | 4 +- .../ocmshareprovider/ocmshareprovider.go | 2 +- .../publicstorageprovider.go | 38 +-- .../storageprovider/storageprovider.go | 45 +-- internal/http/services/owncloud/ocdav/copy.go | 32 +- internal/http/services/owncloud/ocdav/dav.go | 4 +- .../http/services/owncloud/ocdav/delete.go | 4 +- internal/http/services/owncloud/ocdav/get.go | 10 +- 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 | 20 +- .../http/services/owncloud/ocdav/proppatch.go | 12 +- .../services/owncloud/ocdav/publicfile.go | 14 +- 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 | 31 +- .../handlers/apps/sharing/shares/pending.go | 16 +- .../handlers/apps/sharing/shares/public.go | 10 +- .../handlers/apps/sharing/shares/remote.go | 4 +- .../handlers/apps/sharing/shares/shares.go | 64 ++-- .../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 | 4 +- pkg/auth/scope/scope.go | 8 +- pkg/cbox/publicshare/sql/sql.go | 8 +- pkg/cbox/share/sql/sql.go | 24 +- 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 | 52 +-- pkg/storage/fs/s3/s3.go | 33 +- 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 | 12 +- pkg/storage/utils/decomposedfs/recycle.go | 6 +- pkg/storage/utils/decomposedfs/tree/tree.go | 2 +- pkg/storage/utils/decomposedfs/upload_test.go | 6 +- pkg/storage/utils/eosfs/eosfs.go | 50 +-- pkg/storage/utils/etag/etag.go | 2 +- pkg/storage/utils/localfs/localfs.go | 40 ++- pkg/token/manager/demo/demo_test.go | 6 +- pkg/utils/utils.go | 4 +- .../integration/grpc/storageprovider_test.go | 59 ++-- 99 files changed, 602 insertions(+), 1008 deletions(-) diff --git a/cmd/reva/arguments.go b/cmd/reva/arguments.go index b618a159b5c..ff049a748e3 100644 --- a/cmd/reva/arguments.go +++ b/cmd/reva/arguments.go @@ -85,7 +85,7 @@ func (c *Completer) lsArgumentCompleter(onlyDirs bool) []prompt.Suggest { suggests = append(suggests, prompt.Suggest{Text: "/home"}) for _, r := range info { if !onlyDirs || r.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER { - suggests = append(suggests, prompt.Suggest{Text: r.Path}) + suggests = append(suggests, prompt.Suggest{Text: r.Ref.Path}) } } } diff --git a/cmd/reva/download.go b/cmd/reva/download.go index 53b38a098b3..7dcb383a2cd 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 fa93fd95178..a5e72bae4b6 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() @@ -68,9 +66,9 @@ func lsCommand() *command { infos := res.Infos for _, info := range infos { - p := info.Path + p := info.Ref.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 d98b4743199..c81e7560d6f 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 bacb13aeb65..72a9bd09efa 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 aa83d578576..ea90d0b33a4 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.Ref.Path), // TODO what reference should be used here? }, }, } shareRequest := &ocm.CreateOCMShareRequest{ Opaque: opaqueObj, - ResourceId: res.Info.Id, + Ref: res.Info.Ref, 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 83a1122086e..ac26f5d8ed0 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"}) 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()}, diff --git a/cmd/reva/ocm-share-list.go b/cmd/reva/ocm-share-list.go index 9229b87e60c..5e4fa7d42ec 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", "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.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 c4514a0fd45..0d92a885041 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/public-share-create.go b/cmd/reva/public-share-create.go index b50af172a5c..26f7c50bb2c 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 b8dbf322cee..423dfa23cae 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 649ae48dc25..7830ca61e66 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 d33e43553ff..c9f793edada 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 5915b21387e..1b62778c496 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 b596e745d0a..d9925645283 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 77194f07abb..e0e1e1eb5f9 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 97c7d82b19b..e97e00accb7 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 73b005d0cd0..78d3d5038f2 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 29147038cd1..c84cba9a0f7 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/upload.go b/cmd/reva/upload.go index 56ca5d8db40..25577b55d60 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.Ref.Path) return nil } diff --git a/examples/sdk/sdk.go b/examples/sdk/sdk.go index 05cee60f5b0..62b54c11fa9 100644 --- a/examples/sdk/sdk.go +++ b/examples/sdk/sdk.go @@ -54,7 +54,7 @@ func runActions(session *sdk.Session) { act := action.MustNewUploadAction(session) act.EnableTUS = true if info, err := act.UploadBytes([]byte("HELLO WORLD!\n"), "/home/subdir/tests.txt"); err == nil { - log.Printf("Uploaded file: %s [%db] -- %s", info.Path, info.Size, info.Type) + log.Printf("Uploaded file: %s [%db] -- %s", info.Ref.Path, info.Size, info.Type) } else { log.Printf("Can't upload file: %v", err) } @@ -77,14 +77,14 @@ func runActions(session *sdk.Session) { act := action.MustNewEnumFilesAction(session) if files, err := act.ListFiles("/home", true); err == nil { for _, info := range files { - log.Printf("%s [%db] -- %s", info.Path, info.Size, info.Type) + log.Printf("%s [%db] -- %s", info.Ref.Path, info.Size, info.Type) // Download the file actDl := action.MustNewDownloadAction(session) if data, err := actDl.Download(info); err == nil { - log.Printf("Downloaded %d bytes for '%v'", len(data), info.Path) + log.Printf("Downloaded %d bytes for '%v'", len(data), info.Ref.Path) } else { - log.Printf("Unable to download data for '%v': %v", info.Path, err) + log.Printf("Unable to download data for '%v': %v", info.Ref.Path, err) } log.Println("---") diff --git a/go.mod b/go.mod index db1cfe3977f..abeffc9242a 100644 --- a/go.mod +++ b/go.mod @@ -60,6 +60,7 @@ require ( go 1.16 replace ( + github.com/cs3org/go-cs3apis => github.com/refs/go-cs3apis v0.0.0-20210520134557-97cdc479815b 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 9038a8daf71..aab9841a88f 100644 --- a/go.sum +++ b/go.sum @@ -144,8 +144,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-20210507060801-f176760d55f4 h1:lihiUwqal+sO+57VTHGRvHbI9baN+D85fPZG2N1Sk6s= -github.com/cs3org/go-cs3apis v0.0.0-20210507060801-f176760d55f4/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= @@ -925,6 +923,8 @@ github.com/prometheus/statsd_exporter v0.20.0 h1:M0hQphnq2WyWKS5CefQL8PqWwBOBPhi github.com/prometheus/statsd_exporter v0.20.0/go.mod h1:YL3FWCG8JBBtaUSxAg4Gz2ZYu22bS84XM89ZQXXTWmQ= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/refs/go-cs3apis v0.0.0-20210520134557-97cdc479815b h1:EQM9QE2M63TQNy4p/iqQqZAsFjTO8SDBy9ZHWpqqu4w= +github.com/refs/go-cs3apis v0.0.0-20210520134557-97cdc479815b/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.0.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= diff --git a/internal/grpc/interceptors/auth/auth.go b/internal/grpc/interceptors/auth/auth.go index 9a2cda1bb70..c5037d7fb5a 100644 --- a/internal/grpc/interceptors/auth/auth.go +++ b/internal/grpc/interceptors/auth/auth.go @@ -254,18 +254,16 @@ 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 { return nil, err } - if strings.HasPrefix(ref.GetPath(), statResponse.Info.Path) { + if ref.StorageId == statResponse.Info.Ref.StorageId && + ref.NodeId == statResponse.Info.Ref.NodeId && + strings.HasPrefix(ref.GetPath(), statResponse.Info.Ref.Path) { // The path corresponds to the resource to which the token has access. // We allow access to it. return u, nil diff --git a/internal/grpc/services/appprovider/appprovider.go b/internal/grpc/services/appprovider/appprovider.go index b4b48674990..f5f7e2e26c0 100644 --- a/internal/grpc/services/appprovider/appprovider.go +++ b/internal/grpc/services/appprovider/appprovider.go @@ -165,7 +165,7 @@ func (s *service) OpenFileInAppProvider(ctx context.Context, req *providerpb.Ope } 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())` @@ -218,7 +218,7 @@ func (s *service) OpenFileInAppProvider(ctx context.Context, req *providerpb.Ope } return res, nil } - viewOptions := appsURLMap[path.Ext(req.ResourceInfo.GetPath())] + viewOptions := appsURLMap[path.Ext(req.ResourceInfo.Ref.Path)] viewOptionsMap, ok := viewOptions.(map[string]interface{}) if !ok { res := &providerpb.OpenFileInAppProviderResponse{ diff --git a/internal/grpc/services/gateway/appprovider.go b/internal/grpc/services/gateway/appprovider.go index b66c42dfe26..c892f26bfd7 100644 --- a/internal/grpc/services/gateway/appprovider.go +++ b/internal/grpc/services/gateway/appprovider.go @@ -67,11 +67,7 @@ func (s *svc) OpenFileInAppProvider(ctx context.Context, req *gateway.OpenFileIn } 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.OpenFileInAppProviderResponse{ @@ -131,11 +127,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.OpenFileInAppProviderRequest{ Ref: ref, ViewMode: vm, diff --git a/internal/grpc/services/gateway/ocmshareprovider.go b/internal/grpc/services/gateway/ocmshareprovider.go index 8ee4935f3bf..11357da62a7 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") } @@ -314,15 +314,16 @@ func (s *svc) createWebdavReference(ctx context.Context, share *ocm.Share) (*rpc return status.NewInternal(ctx, err, "error updating received share"), nil } + // 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)) log.Info().Msg("mount path will be:" + refPath) createRefReq := &provider.CreateReferenceRequest{ - Path: refPath, + Ref: &provider.Reference{Path: refPath}, // 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), } diff --git a/internal/grpc/services/gateway/publicshareprovider.go b/internal/grpc/services/gateway/publicshareprovider.go index 88bb41b1c95..c4faa7942b4 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.Ref.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 90a5a042725..fc7fda77f7e 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.Ref + log.Debug().Str("storage", ri.Ref.StorageId).Str("node", ri.Ref.NodeId).Str("path", ri.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.Ref.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.Ref + 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.Ref.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().GetRef(), }, 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.Ref.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.Ref.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,14 @@ 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), - }, + StorageId: ri.Ref.StorageId, + NodeId: ri.Ref.NodeId, + Path: path.Join(ri.Ref.Path, shareChild), } dst := &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: path.Join(ri.Path, dshareChild), - }, + StorageId: ri.Ref.StorageId, + NodeId: ri.Ref.NodeId, + Path: path.Join(ri.Ref.Path, dshareChild), } req.Source = src @@ -1043,13 +977,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 +1007,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.Ref.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 +1017,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.Ref.Path, etagWithTS{statRes.Info.Etag, time.Now()}) // FIXME @butonic REFERENCE also use node fo etag cache? } } @@ -1097,13 +1025,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 +1050,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.Ref.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 +1061,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.Ref.Path, etagWithTS{statRes.Info.Etag, time.Now()}) // FIXME @butonic REFERENCE also use node fo etag cache? } } return statRes, nil @@ -1154,6 +1076,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 +1087,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 +1116,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, + Ref: &provider.Reference{Path: resPath}, // TODO this is an absolute path ... we should only return the name Size: totalSize, }, }, nil @@ -1214,13 +1140,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 @@ -1286,9 +1206,9 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St // information. For example, if requests comes to: /home/MyShares/photos and photos // is reference to /user/peter/Holidays/photos, we need to still return to the user // /home/MyShares/photos - orgPath := statRes.Info.Path + orgPath := statRes.Info.Ref.Path statRes.Info = ri - statRes.Info.Path = orgPath + statRes.Info.Ref.Path = orgPath return statRes, nil } @@ -1296,13 +1216,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{ @@ -1330,7 +1244,7 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St Status: status.NewInternal(ctx, err, "gateway: error resolving webdav reference: "+p), }, nil } - ri.Path = p + ri.Ref.Path = p return &provider.StatResponse{ Status: status.NewOK(ctx), Info: ri, @@ -1338,11 +1252,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.Ref.Path, shareChild) res, err := s.stat(ctx, req) if err != nil { return &provider.StatResponse{ @@ -1357,7 +1267,7 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St // we need to make sure we don't expose the reference target in the resource // information. - res.Info.Path = p + res.Info.Ref.Path = p return res, nil } @@ -1405,12 +1315,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 +1353,7 @@ func (s *svc) ListContainerStream(_ *provider.ListContainerStreamRequest, _ gate func (s *svc) listHome(ctx context.Context, req *provider.ListContainerRequest) (*provider.ListContainerResponse, error) { lcr, err := s.listContainer(ctx, &provider.ListContainerRequest{ - Ref: &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: s.getHome(ctx), - }, - }, + Ref: &provider.Reference{Path: s.getHome(ctx)}, ArbitraryMetadataKeys: req.ArbitraryMetadataKeys, }) if err != nil { @@ -1466,7 +1368,7 @@ func (s *svc) listHome(ctx context.Context, req *provider.ListContainerRequest) } for i := range lcr.Infos { - if s.isSharedFolder(ctx, lcr.Infos[i].Path) { + if s.isSharedFolder(ctx, lcr.Infos[i].Ref.Path) { statSharedFolder, err := s.statSharesFolder(ctx) if err != nil { return &provider.ListContainerResponse{ @@ -1487,13 +1389,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 +1420,7 @@ func (s *svc) listSharesFolder(ctx context.Context) (*provider.ListContainerResp } } - info.Path = lcr.Infos[i].GetPath() + info.Ref = lcr.Infos[i].Ref checkedInfos = append(checkedInfos, info) } lcr.Infos = checkedInfos @@ -1560,8 +1456,8 @@ func (s *svc) listContainer(ctx context.Context, req *provider.ListContainerRequ }, nil } for _, inf := range infoFromProviders[i] { - if parent := path.Dir(inf.Path); resPath != "" && resPath != parent { - parts := strings.Split(strings.TrimPrefix(inf.Path, resPath), "/") + if parent := path.Dir(inf.Ref.Path); resPath != "" && resPath != parent { + parts := strings.Split(strings.TrimPrefix(inf.Ref.Path, resPath), "/") p := path.Join(resPath, parts[1]) indirects[p] = append(indirects[p], inf) } else { @@ -1572,13 +1468,13 @@ 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), - Path: k, + Ref: &provider.Reference{Path: k}, Size: 0, } infos = append(infos, inf) @@ -1603,13 +1499,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 +1530,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{ @@ -1676,8 +1560,8 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ } for _, info := range infos { - base := path.Base(info.Path) - info.Path = path.Join(p, base) + base := path.Base(info.Ref.Path) + info.Ref.Path = path.Join(p, base) } return &provider.ListContainerResponse{ Status: status.NewOK(ctx), @@ -1686,7 +1570,7 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ } if ri.Type != provider.ResourceType_RESOURCE_TYPE_CONTAINER { - err := errtypes.NotSupported("gateway: list container: cannot list non-container type:" + ri.Path) + err := errtypes.NotSupported("gateway: list container: cannot list non-container type:" + ri.Ref.Path) log.Err(err).Msg("gateway: error listing") return &provider.ListContainerResponse{ Status: status.NewInvalidArg(ctx, "resource is not a container"), @@ -1694,11 +1578,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.Ref.Path}, ArbitraryMetadataKeys: req.ArbitraryMetadataKeys, } newRes, err := s.listContainer(ctx, newReq) @@ -1716,8 +1596,8 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ // paths needs to be converted for _, info := range newRes.Infos { - base := path.Base(info.Path) - info.Path = path.Join(p, base) + base := path.Base(info.Ref.Path) + info.Ref.Path = path.Join(p, base) } return newRes, nil @@ -1727,13 +1607,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{ @@ -1763,8 +1637,8 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ } for _, info := range infos { - base := path.Base(info.Path) - info.Path = path.Join(shareName, shareChild, base) + base := path.Base(info.Ref.Path) + info.Ref.Path = path.Join(shareName, shareChild, base) } return &provider.ListContainerResponse{ Status: status.NewOK(ctx), @@ -1773,7 +1647,7 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ } if ri.Type != provider.ResourceType_RESOURCE_TYPE_CONTAINER { - err := errtypes.NotSupported("gateway: list container: cannot list non-container type:" + ri.Path) + err := errtypes.NotSupported("gateway: list container: cannot list non-container type:" + ri.Ref.Path) log.Err(err).Msg("gateway: error listing") return &provider.ListContainerResponse{ Status: status.NewInvalidArg(ctx, "resource is not a container"), @@ -1781,11 +1655,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.Ref.Path, shareChild)}, ArbitraryMetadataKeys: req.ArbitraryMetadataKeys, } newRes, err := s.listContainer(ctx, newReq) @@ -1803,8 +1673,8 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ // paths needs to be converted for _, info := range newRes.Infos { - base := path.Base(info.Path) - info.Path = path.Join(shareName, shareChild, base) + base := path.Base(info.Ref.Path) + info.Ref.Path = path.Join(shareName, shareChild, base) } return newRes, nil @@ -1815,21 +1685,18 @@ 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 { return "", res.Status } - return res.Info.Path, res.Status + return res.Info.Ref.Path, res.Status } - return "", &rpc.Status{Code: rpc.Code_CODE_INTERNAL} + return ref.Path, &rpc.Status{Code: rpc.Code_CODE_OK} } // /home/MyShares/ @@ -2017,21 +1884,8 @@ func (s *svc) GetQuota(ctx context.Context, req *gateway.GetQuotaRequest) (*prov return res, nil } -func (s *svc) findByID(ctx context.Context, id *provider.ResourceId) (provider.ProviderAPIClient, error) { - ref := &provider.Reference{ - Spec: &provider.Reference_Id{ - Id: id, - }, - } - return s.find(ctx, ref) -} - func (s *svc) findByPath(ctx context.Context, path string) (provider.ProviderAPIClient, error) { - ref := &provider.Reference{ - Spec: &provider.Reference_Path{ - Path: path, - }, - } + ref := &provider.Reference{Path: path} return s.find(ctx, ref) } diff --git a/internal/grpc/services/gateway/usershareprovider.go b/internal/grpc/services/gateway/usershareprovider.go index 175258765f1..449f403b01e 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.Ref.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.Ref.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/gateway/webdavstorageprovider.go b/internal/grpc/services/gateway/webdavstorageprovider.go index b49fd91b8a1..9d8069378c7 100644 --- a/internal/grpc/services/gateway/webdavstorageprovider.go +++ b/internal/grpc/services/gateway/webdavstorageprovider.go @@ -255,7 +255,7 @@ func (s *svc) getWebdavEndpoint(ctx context.Context, domain string) (string, err func normalize(info *gowebdav.File) *provider.ResourceInfo { return &provider.ResourceInfo{ // TODO(ishank011): Add Id, PermissionSet, Owner - Path: info.Path(), + Ref: &provider.Reference{Path: info.Path()}, Type: getResourceType(info.IsDir()), Etag: info.ETag(), MimeType: info.ContentType(), diff --git a/internal/grpc/services/ocmcore/ocmcore.go b/internal/grpc/services/ocmcore/ocmcore.go index f6bbbf6725d..46d71ea46b9 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 676da090cce..d1da6f983c6 100644 --- a/internal/grpc/services/ocmshareprovider/ocmshareprovider.go +++ b/internal/grpc/services/ocmshareprovider/ocmshareprovider.go @@ -144,7 +144,7 @@ func (s *service) CreateOCMShare(ctx context.Context, req *ocm.CreateOCMShareReq }, nil } - share, err := s.sm.Share(ctx, req.ResourceId, req.Grant, name, req.RecipientMeshProvider, permissions, nil, "", ocm.Share_SHARE_TYPE_REGULAR) + share, err := s.sm.Share(ctx, req.Ref, req.Grant, name, req.RecipientMeshProvider, permissions, nil, "", ocm.Share_SHARE_TYPE_REGULAR) 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 b941b9b1101..5192669a45f 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()), @@ -491,7 +483,7 @@ func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provide if err := addShare(statResponse.Info, ls); err != nil { appctx.GetLogger(ctx).Error().Err(err).Interface("share", ls).Interface("info", statResponse.Info).Msg("error when adding share") } - statResponse.Info.Path = path.Join(s.mountPath, "/", tkn, relativePath) + statResponse.Info.Ref.Path = path.Join(s.mountPath, "/", tkn, relativePath) filterPermissions(statResponse.Info.PermissionSet, ls.GetPermissions().Permissions) } @@ -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{ @@ -556,7 +542,7 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer for i := range listContainerR.Infos { filterPermissions(listContainerR.Infos[i].PermissionSet, ls.GetPermissions().Permissions) - listContainerR.Infos[i].Path = path.Join(s.mountPath, "/", tkn, relativePath, path.Base(listContainerR.Infos[i].Path)) + listContainerR.Infos[i].Ref.Path = path.Join(s.mountPath, "/", tkn, relativePath, path.Base(listContainerR.Infos[i].Ref.Path)) if err := addShare(listContainerR.Infos[i], ls); err != nil { appctx.GetLogger(ctx).Error().Err(err).Interface("share", ls).Interface("info", listContainerR.Infos[i]).Msg("error when adding share") } @@ -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 bede723cedb..1982111c853 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.Ref.Path = path.Join(s.mountPath, ri.Ref.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 1a7e29a7046..de260b1a34b 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 { @@ -160,13 +154,11 @@ func (s *svc) handleCopy(w http.ResponseWriter, r *http.Request, ns string) { func (s *svc) descend(ctx context.Context, client gateway.GatewayAPIClient, src *provider.ResourceInfo, dst string, recurse bool) error { log := appctx.GetLogger(ctx) - log.Debug().Str("src", src.Path).Str("dst", dst).Msg("descending") + log.Debug().Str("src", src.Ref.Path).Str("dst", dst).Msg("descending") 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.Ref.Path}, } res, err := client.ListContainer(ctx, listReq) if err != nil { @@ -194,7 +184,7 @@ func (s *svc) descend(ctx context.Context, client gateway.GatewayAPIClient, src } for i := range res.Infos { - childDst := path.Join(dst, path.Base(res.Infos[i].Path)) + childDst := path.Join(dst, path.Base(res.Infos[i].Ref.Path)) err := s.descend(ctx, client, res.Infos[i], childDst, recurse) if err != nil { return err @@ -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.Ref.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 ca5abc18845..a1681fe29d0 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 0bdf55561ad..8898a95d1a1 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 d6ab7d6c896..00589d75df4 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) @@ -132,7 +128,7 @@ func (s *svc) handleGet(w http.ResponseWriter, r *http.Request, ns string) { w.Header().Set("Content-Type", info.MimeType) w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+ - path.Base(info.Path)+"; filename=\""+path.Base(info.Path)+"\"") + path.Base(info.Ref.Path)+"; filename=\""+path.Base(info.Ref.Path)+"\"") w.Header().Set("ETag", info.Etag) w.Header().Set("OC-FileId", wrapResourceID(info.Id)) w.Header().Set("OC-ETag", info.Etag) diff --git a/internal/http/services/owncloud/ocdav/head.go b/internal/http/services/owncloud/ocdav/head.go index 250da299bb4..f70d4b95d89 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 c93a8f9f674..889598a43ba 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 77debda5004..e92bc1bedee 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 c2b7561cf2b..9e973edea67 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 71eb313918b..df3a04b940d 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, @@ -151,13 +149,11 @@ func (s *svc) handlePropfind(w http.ResponseWriter, r *http.Request, ns string) } else if depth == "infinity" { // FIXME: doesn't work cross-storage as the results will have the wrong paths! // use a stack to explore sub-containers breadth-first - stack := []string{info.Path} + stack := []string{info.Ref.Path} 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, @@ -188,7 +184,7 @@ func (s *svc) handlePropfind(w http.ResponseWriter, r *http.Request, ns string) for i := len(res.Infos) - 1; i >= 0; i-- { // for i := range res.Infos { if res.Infos[i].Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER { - stack = append(stack, res.Infos[i].Path) + stack = append(stack, res.Infos[i].Ref.Path) } } } @@ -334,11 +330,11 @@ func (s *svc) newPropRaw(key, val string) *propertyXML { // prefixing it with the baseURI func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provider.ResourceInfo, ns string) (*responseXML, error) { sublog := appctx.GetLogger(ctx).With().Interface("md", md).Str("ns", ns).Logger() - md.Path = strings.TrimPrefix(md.Path, ns) + md.Ref.Path = strings.TrimPrefix(md.Ref.Path, ns) baseURI := ctx.Value(ctxKeyBaseURI).(string) - ref := path.Join(baseURI, md.Path) + ref := path.Join(baseURI, md.Ref.Path) if md.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER { ref += "/" } @@ -666,12 +662,12 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide if isPublic && md.Type == provider.ResourceType_RESOURCE_TYPE_FILE { var path string if !ls.PasswordProtected { - path = md.Path + path = md.Ref.Path } else { expiration := time.Unix(int64(ls.Signature.SignatureExpiration.Seconds), int64(ls.Signature.SignatureExpiration.Nanos)) var sb strings.Builder - sb.WriteString(md.Path) + sb.WriteString(md.Ref.Path) sb.WriteString("?signature=") sb.WriteString(ls.Signature.Signature) sb.WriteString("&expiration=") diff --git a/internal/http/services/owncloud/ocdav/proppatch.go b/internal/http/services/owncloud/ocdav/proppatch.go index a8fe5933a00..f7dd9277438 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 c5670014f07..df04a1d71c5 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.GetRef(), }) 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.GetRef(), }) 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.Ref.Path = path.Join("/", tokenStatInfo.Ref.Path, path.Base(pathRes.Ref.Path)) infos := s.getPublicFileInfos(onContainer, depth == "0", tokenStatInfo) @@ -223,7 +223,7 @@ func (s *svc) getPublicFileInfos(onContainer, onlyRoot bool, i *provider.Resourc infos = append(infos, &provider.ResourceInfo{ // Opaque carries the link-share data we need when rendering the collection root href Opaque: o, - Path: path.Dir(i.Path), + Ref: &provider.Reference{Path: path.Dir(i.Ref.Path)}, Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER, }) if onlyRoot { diff --git a/internal/http/services/owncloud/ocdav/put.go b/internal/http/services/owncloud/ocdav/put.go index 71a8c1b7b31..7a9ad49963b 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 c97353c76f7..de5d9dede44 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 fec279f494b..8fb4c7a1a15 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 bd261594ae0..7c4ad9b261b 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, @@ -153,7 +150,7 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request, Seconds: versions[i].Mtime, // TODO cs3apis FileVersion should use types.Timestamp instead of uint64 }, - Path: path.Join("v", versions[i].Key), + Ref: &provider.Reference{Path: path.Join("v", versions[i].Key)}, // PermissionSet Size: versions[i].Size, Owner: info.Owner, @@ -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 4a7d06684a0..086c720d4f5 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,8 +101,18 @@ 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)) - data.Path = 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 alse 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, info.Ref.Path) + data.Path = path.Join(h.sharePrefix, info.Ref.Path) } response.WriteOCSSuccess(w, r, data) 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 5c8029f4a1d..13ebe89904d 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 f77db99cf62..3d75e305e24 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 @@ -85,11 +85,11 @@ func (h *Handler) createFederatedCloudShare(w http.ResponseWriter, r *http.Reque }, "name": { Decoder: "plain", - Value: []byte(statInfo.Path), + Value: []byte(statInfo.Ref.Path), }, }, }, - 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 fefe0acad2d..d7442603ddf 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 @@ -657,8 +647,8 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { 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)) - data.Path = path.Join(h.sharePrefix, path.Base(info.Path)) + data.FileTarget = path.Join(h.sharePrefix, info.Ref.Path) + data.Path = path.Join(h.sharePrefix, info.Ref.Path) } shares = append(shares, data) @@ -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,12 +785,12 @@ 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 - s.FileTarget = path.Join("/", path.Base(info.Path)) - s.Path = path.Join("/", path.Base(info.Path)) // TODO hm this might have to be relative to the users home ... depends on the webdav_namespace config + s.FileTarget = path.Join("/", path.Base(info.Ref.Path)) + s.Path = path.Join("/", path.Base(info.Ref.Path)) // TODO hm this might have to be relative to the users home ... depends on the webdav_namespace config // TODO FileParent: // item type s.ItemType = conversions.ResourceType(info.GetType()).String() @@ -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 1a133f34b6c..2bc92419630 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 89538d075ee..f99dbb6b46d 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 4adb0904dd0..1534094f2dc 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 928c602b1bb..ba934dac2ca 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("