diff --git a/changelog/unreleased/new-space-id-functions.md b/changelog/unreleased/new-space-id-functions.md new file mode 100644 index 00000000000..e399665dc81 --- /dev/null +++ b/changelog/unreleased/new-space-id-functions.md @@ -0,0 +1,5 @@ +Change: Use new space ID util functions + +Changed code to use the new space ID util functions so that everything works with the new spaces ID format. + +https://github.com/owncloud/ocis/pull/3648 diff --git a/extensions/audit/pkg/types/conversion.go b/extensions/audit/pkg/types/conversion.go index fbb789ea596..2140f485f82 100644 --- a/extensions/audit/pkg/types/conversion.go +++ b/extensions/audit/pkg/types/conversion.go @@ -5,7 +5,7 @@ import ( "time" "github.com/cs3org/reva/v2/pkg/events" - "github.com/cs3org/reva/v2/pkg/utils" + "github.com/cs3org/reva/v2/pkg/storagespace" group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1" user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" @@ -453,7 +453,7 @@ func extractFileDetails(ref *provider.Reference, owner *user.UserId) (string, st id, path := "", "" if ref != nil { path = ref.GetPath() - id, _ = utils.FormatStorageSpaceReference(ref) + id, _ = storagespace.FormatReference(ref) } uid := "" diff --git a/extensions/graph/pkg/service/v0/driveitems.go b/extensions/graph/pkg/service/v0/driveitems.go index 7b3e1beb0a6..38504ea9925 100644 --- a/extensions/graph/pkg/service/v0/driveitems.go +++ b/extensions/graph/pkg/service/v0/driveitems.go @@ -12,7 +12,7 @@ import ( cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" - "github.com/cs3org/reva/v2/pkg/utils/resourceid" + "github.com/cs3org/reva/v2/pkg/storagespace" "github.com/go-chi/render" libregraph "github.com/owncloud/libre-graph-api-go" "github.com/owncloud/ocis/extensions/graph/pkg/service/v0/errorcode" @@ -113,7 +113,7 @@ func (g Graph) getRemoteItem(ctx context.Context, root *storageprovider.Resource return nil, err } - item.WebDavUrl = libregraph.PtrString(baseURL.String() + resourceid.OwnCloudResourceIDWrap(root)) + item.WebDavUrl = libregraph.PtrString(baseURL.String() + storagespace.FormatResourceID(*root)) return item, nil } @@ -139,7 +139,7 @@ func cs3ResourceToDriveItem(res *storageprovider.ResourceInfo) (*libregraph.Driv *size = int64(res.Size) // TODO lurking overflow: make size of libregraph drive item use uint64 driveItem := &libregraph.DriveItem{ - Id: libregraph.PtrString(resourceid.OwnCloudResourceIDWrap(res.Id)), + Id: libregraph.PtrString(storagespace.FormatResourceID(*res.Id)), Size: size, } @@ -170,7 +170,7 @@ func cs3ResourceToRemoteItem(res *storageprovider.ResourceInfo) (*libregraph.Rem *size = int64(res.Size) // TODO lurking overflow: make size of libregraph drive item use uint64 remoteItem := &libregraph.RemoteItem{ - Id: libregraph.PtrString(resourceid.OwnCloudResourceIDWrap(res.Id)), + Id: libregraph.PtrString(storagespace.FormatResourceID(*res.Id)), Size: size, } @@ -219,7 +219,8 @@ func (g Graph) GetExtendedSpaceProperties(ctx context.Context, baseURL *url.URL, for _, itemName := range names { if itemID, ok := metadata[itemName]; ok { - spaceItem := g.getSpecialDriveItem(ctx, *resourceid.OwnCloudResourceIDUnwrap(string(itemID.Value)), itemName, baseURL, space) + rid, _ := storagespace.ParseID(string(itemID.Value)) + spaceItem := g.getSpecialDriveItem(ctx, rid, itemName, baseURL, space) if spaceItem != nil { spaceItems = append(spaceItems, *spaceItem) } diff --git a/extensions/graph/pkg/service/v0/drives.go b/extensions/graph/pkg/service/v0/drives.go index 821e664898e..e37302e8628 100644 --- a/extensions/graph/pkg/service/v0/drives.go +++ b/extensions/graph/pkg/service/v0/drives.go @@ -18,8 +18,8 @@ import ( storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" ctxpkg "github.com/cs3org/reva/v2/pkg/ctx" + "github.com/cs3org/reva/v2/pkg/storagespace" "github.com/cs3org/reva/v2/pkg/utils" - "github.com/cs3org/reva/v2/pkg/utils/resourceid" "github.com/go-chi/chi/v5" "github.com/go-chi/render" libregraph "github.com/owncloud/libre-graph-api-go" @@ -287,7 +287,7 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { identifierParts := strings.Split(driveID, "!") switch len(identifierParts) { case 1: - sID, _ := resourceid.StorageIDUnwrap(identifierParts[0]) + _, sID := storagespace.SplitStorageID(identifierParts[0]) root.StorageId, root.OpaqueId = identifierParts[0], sID case 2: root.StorageId, root.OpaqueId = identifierParts[0], identifierParts[1] @@ -453,7 +453,7 @@ func generateSpaceId(id *storageprovider.ResourceId) (spaceID string) { // 2nd ID to compare is the opaque ID of the Space Root spaceID2 := id.GetOpaqueId() if strings.Contains(spaceID, "$") { - spaceID2, _ = resourceid.StorageIDUnwrap(spaceID) + _, spaceID2 = storagespace.SplitStorageID(spaceID) } // Append opaqueID only if it is different from the spaceID2 if id.OpaqueId != spaceID2 { @@ -531,7 +531,7 @@ func (g Graph) cs3StorageSpaceToDrive(ctx context.Context, baseURL *url.URL, spa //"description": "string", // TODO read from StorageSpace ... needs Opaque for now DriveType: &space.SpaceType, Root: &libregraph.DriveItem{ - Id: libregraph.PtrString(resourceid.OwnCloudResourceIDWrap(space.Root)), + Id: libregraph.PtrString(storagespace.FormatResourceID(*space.Root)), Permissions: permissions, }, } @@ -764,7 +764,7 @@ func (g Graph) DeleteDrive(w http.ResponseWriter, r *http.Request) { root := &storageprovider.ResourceId{} identifierParts := strings.Split(driveID, "!") - sID, _ := resourceid.StorageIDUnwrap(identifierParts[0]) + _, sID := storagespace.SplitStorageID(identifierParts[0]) switch len(identifierParts) { case 1: root.StorageId, root.OpaqueId = identifierParts[0], sID diff --git a/extensions/thumbnails/pkg/service/grpc/v0/service.go b/extensions/thumbnails/pkg/service/grpc/v0/service.go index 22a3465c937..dc6faa31f88 100644 --- a/extensions/thumbnails/pkg/service/grpc/v0/service.go +++ b/extensions/thumbnails/pkg/service/grpc/v0/service.go @@ -12,6 +12,7 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" revactx "github.com/cs3org/reva/v2/pkg/ctx" + "github.com/cs3org/reva/v2/pkg/storagespace" "github.com/golang-jwt/jwt/v4" "github.com/owncloud/ocis/extensions/thumbnails/pkg/preprocessor" "github.com/owncloud/ocis/extensions/thumbnails/pkg/service/grpc/v0/decorators" @@ -257,15 +258,11 @@ func (g Thumbnail) stat(path, auth string) (*provider.StatResponse, error) { var ref *provider.Reference if strings.Contains(path, "!") { - parts := strings.Split(path, "!") - spaceID, path := parts[0], parts[1] - ref = &provider.Reference{ - ResourceId: &provider.ResourceId{ - StorageId: spaceID, - OpaqueId: spaceID, - }, - Path: path, + parsed, err := storagespace.ParseReference(path) + if err != nil { + return nil, err } + ref = &parsed } else { ref = &provider.Reference{ Path: path, diff --git a/extensions/thumbnails/pkg/thumbnail/imgsource/cs3.go b/extensions/thumbnails/pkg/thumbnail/imgsource/cs3.go index 9b0cdfa2589..9b38b7ba6c8 100644 --- a/extensions/thumbnails/pkg/thumbnail/imgsource/cs3.go +++ b/extensions/thumbnails/pkg/thumbnail/imgsource/cs3.go @@ -13,6 +13,7 @@ import ( provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" revactx "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/rhttp" + "github.com/cs3org/reva/v2/pkg/storagespace" "github.com/owncloud/ocis/extensions/thumbnails/pkg/config" "github.com/pkg/errors" "google.golang.org/grpc/metadata" @@ -45,16 +46,11 @@ func (s CS3) Get(ctx context.Context, path string) (io.ReadCloser, error) { } var ref *provider.Reference if strings.Contains(path, "!") { - parts := strings.Split(path, "!") - spaceID, path := parts[0], parts[1] - ref = &provider.Reference{ - ResourceId: &provider.ResourceId{ - StorageId: spaceID, - OpaqueId: spaceID, - }, - // Spaces requests need relative paths. - Path: "." + path, + parsed, err := storagespace.ParseReference(path) + if err != nil { + return nil, err } + ref = &parsed } else { ref = &provider.Reference{ Path: path, diff --git a/go.mod b/go.mod index 346f6127cea..03137074e9b 100644 --- a/go.mod +++ b/go.mod @@ -274,3 +274,5 @@ require ( // we need to use a fork to make the windows build pass replace github.com/pkg/xattr => github.com/micbar/xattr v0.4.6-0.20220215112335-88e74d648fb7 + +replace github.com/cs3org/reva/v2 => github.com/c0rby/reva/v2 v2.0.0-20220502181659-d28813e0cbed diff --git a/go.sum b/go.sum index 68f316b32f2..ec816e8a09e 100644 --- a/go.sum +++ b/go.sum @@ -236,6 +236,8 @@ github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBW github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs= github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= +github.com/c0rby/reva/v2 v2.0.0-20220502181659-d28813e0cbed h1:B5pJsx7QYoAZJX+aemQ1mQHHQUJPCwfCvF0h/SGfafg= +github.com/c0rby/reva/v2 v2.0.0-20220502181659-d28813e0cbed/go.mod h1:2e/4HcIy54Mic3V7Ow0bz4n5dkZU0dHIZSWomFe5vng= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= @@ -318,8 +320,6 @@ github.com/cs3org/go-cs3apis v0.0.0-20220412090512-93c5918b4bde h1:WrD9O8ZaWvsm0 github.com/cs3org/go-cs3apis v0.0.0-20220412090512-93c5918b4bde/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/cs3org/reva v1.18.0 h1:MbPS5ZAa8RzKcTxAVeSDdISB3XXqLIxqB03BTN5ReBY= github.com/cs3org/reva v1.18.0/go.mod h1:e5VDUDu4vVWIeVkZcW//n6UZzhGGMa+Tz/whCiX3N6o= -github.com/cs3org/reva/v2 v2.0.0-20220502122639-bfbf8690a043 h1:wAvf45pBDnWIN4kpyWpD9uRl9y147ioAXJkfztrMSCM= -github.com/cs3org/reva/v2 v2.0.0-20220502122639-bfbf8690a043/go.mod h1:2e/4HcIy54Mic3V7Ow0bz4n5dkZU0dHIZSWomFe5vng= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=