diff --git a/changelog/unreleased/unify-file-ids.md b/changelog/unreleased/unify-file-ids.md new file mode 100644 index 0000000000..10f13a9dcf --- /dev/null +++ b/changelog/unreleased/unify-file-ids.md @@ -0,0 +1,5 @@ +Change: Unify file IDs + +We changed the file IDs to be consistent across all our APIs (WebDAV, LibreGraph, OCS). We removed the base64 encoding. Now they are formatted like !. They are using a reserved character ``!`` as a URL safe separator. + +https://github.com/owncloud/ocis/pull/3185 diff --git a/go.mod b/go.mod index a68352d4a9..1e290ad4e1 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/blevesearch/bleve/v2 v2.3.0 github.com/coreos/go-oidc/v3 v3.1.0 github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19 - github.com/cs3org/reva v1.16.1-0.20220215130802-df1264deff58 + github.com/cs3org/reva v1.16.1-0.20220216213129-67204fec6e50 github.com/disintegration/imaging v1.6.2 github.com/glauth/glauth/v2 v2.0.0-20211021011345-ef3151c28733 github.com/go-chi/chi/v5 v5.0.7 diff --git a/go.sum b/go.sum index 9227da0676..fc777cd440 100644 --- a/go.sum +++ b/go.sum @@ -337,10 +337,8 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19 h1:1jqPH58jCxvbaJ9WLIJ7W2/m622bWS6ChptzljSG6IQ= github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva v1.16.1-0.20220214105747-d217886c962b h1:E53EHbKiHIIJeZgDEx5tE3AflxgL1dHughNbBQU7Dfk= -github.com/cs3org/reva v1.16.1-0.20220214105747-d217886c962b/go.mod h1:gdKuhou74V47snANuHNIhGNJfCKUSCHPPvuhSx7nu5M= -github.com/cs3org/reva v1.16.1-0.20220215130802-df1264deff58 h1:CBSpClYZp8Q7Cl/xENW42Zy7M9+vqACAulqXFnWn3Ug= -github.com/cs3org/reva v1.16.1-0.20220215130802-df1264deff58/go.mod h1:gdKuhou74V47snANuHNIhGNJfCKUSCHPPvuhSx7nu5M= +github.com/cs3org/reva v1.16.1-0.20220216213129-67204fec6e50 h1:K5HI9Pyq7hF6FH5Sc4phrkgFtLNMo0NrEL8NoEjWU/E= +github.com/cs3org/reva v1.16.1-0.20220216213129-67204fec6e50/go.mod h1:gdKuhou74V47snANuHNIhGNJfCKUSCHPPvuhSx7nu5M= 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= diff --git a/graph/pkg/service/v0/driveitems.go b/graph/pkg/service/v0/driveitems.go index a698652b90..3b188a89d1 100644 --- a/graph/pkg/service/v0/driveitems.go +++ b/graph/pkg/service/v0/driveitems.go @@ -11,6 +11,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/pkg/utils/resourceid" "github.com/go-chi/render" libregraph "github.com/owncloud/libre-graph-api-go" "github.com/owncloud/ocis/graph/pkg/service/v0/errorcode" @@ -113,7 +114,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: &res.Id.OpaqueId, + Id: libregraph.PtrString(resourceid.OwnCloudResourceIDWrap(res.Id)), Size: size, } @@ -164,7 +165,7 @@ func (g Graph) GetExtendedSpaceProperties(ctx context.Context, baseURL *url.URL, for _, itemName := range names { if itemID, ok := metadata[itemName]; ok { - spaceItem := g.getSpecialDriveItem(ctx, string(itemID.Value), itemName, baseURL, space) + spaceItem := g.getSpecialDriveItem(ctx, resourceid.OwnCloudResourceIDUnwrap(string(itemID.Value)), itemName, baseURL, space) if spaceItem != nil { spaceItems = append(spaceItems, *spaceItem) } @@ -173,20 +174,20 @@ func (g Graph) GetExtendedSpaceProperties(ctx context.Context, baseURL *url.URL, return spaceItems } -func (g Graph) getSpecialDriveItem(ctx context.Context, itemID string, itemName string, baseURL *url.URL, space *storageprovider.StorageSpace) *libregraph.DriveItem { +func (g Graph) getSpecialDriveItem(ctx context.Context, ID *storageprovider.ResourceId, itemName string, baseURL *url.URL, space *storageprovider.StorageSpace) *libregraph.DriveItem { var spaceItem *libregraph.DriveItem - if itemID == "" { + if ID == nil { return nil } - spaceItem, err := g.getDriveItem(ctx, &storageprovider.ResourceId{StorageId: space.Root.StorageId, OpaqueId: itemID}) + spaceItem, err := g.getDriveItem(ctx, ID) if err != nil { - g.logger.Error().Err(err).Str("ID", itemID).Msg("Could not get readme Item") + g.logger.Error().Err(err).Str("ID", ID.OpaqueId).Msg("Could not get readme Item") return nil } - itemPath, err := g.getPathForDriveItem(ctx, &storageprovider.ResourceId{StorageId: space.Root.StorageId, OpaqueId: itemID}) + itemPath, err := g.getPathForDriveItem(ctx, ID) if err != nil { - g.logger.Error().Err(err).Str("ID", itemID).Msg("Could not get readme path") + g.logger.Error().Err(err).Str("ID", ID.OpaqueId).Msg("Could not get readme path") return nil } spaceItem.SpecialFolder = &libregraph.SpecialFolder{Name: libregraph.PtrString(itemName)} diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index 58daa2c697..24104af77e 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -18,6 +18,7 @@ import ( types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" ctxpkg "github.com/cs3org/reva/pkg/ctx" "github.com/cs3org/reva/pkg/utils" + "github.com/cs3org/reva/pkg/utils/resourceid" "github.com/go-chi/chi/v5" "github.com/go-chi/render" libregraph "github.com/owncloud/libre-graph-api-go" @@ -329,7 +330,7 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { if resp.GetStatus().GetCode() != cs3rpc.Code_CODE_OK { switch resp.Status.GetCode() { case cs3rpc.Code_CODE_NOT_FOUND: - errorcode.ItemNotFound.Render(w, r, http.StatusNotFound, "Space not found") + errorcode.ItemNotFound.Render(w, r, http.StatusNotFound, resp.GetStatus().GetMessage()) return case cs3rpc.Code_CODE_PERMISSION_DENIED: errorcode.NotAllowed.Render(w, r, http.StatusForbidden, resp.GetStatus().GetMessage()) @@ -409,11 +410,7 @@ func (g Graph) ListStorageSpacesWithFilters(ctx context.Context, filters []*stor } func (g Graph) cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.StorageSpace) (*libregraph.Drive, error) { - rootID := space.Root.StorageId + "!" + space.Root.OpaqueId - if space.Root.StorageId == space.Root.OpaqueId { - // omit opaqueid - rootID = space.Root.StorageId - } + rootID := resourceid.OwnCloudResourceIDWrap(space.Root) var permissions []libregraph.Permission if space.Opaque != nil { @@ -472,7 +469,7 @@ func (g Graph) cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.S } drive := &libregraph.Drive{ - Id: &rootID, + Id: &space.Root.StorageId, Name: &space.Name, //"createdDateTime": "string (timestamp)", // TODO read from StorageSpace ... needs Opaque for now //"description": "string", // TODO read from StorageSpace ... needs Opaque for now @@ -501,7 +498,7 @@ func (g Graph) cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.S // TODO read from StorageSpace ... needs Opaque for now // TODO how do we build the url? // for now: read from request - webDavURL := baseURL.String() + rootID + webDavURL := baseURL.String() + space.Root.StorageId drive.Root.WebDavUrl = &webDavURL } diff --git a/graph/pkg/service/v0/graph_test.go b/graph/pkg/service/v0/graph_test.go index 2c751b55b6..976f4509aa 100644 --- a/graph/pkg/service/v0/graph_test.go +++ b/graph/pkg/service/v0/graph_test.go @@ -90,11 +90,11 @@ var _ = Describe("Graph", func() { "value":[ { "driveType":"aspacetype", - "id":"aspaceid!anopaqueid", + "id":"aspaceid", "name":"aspacename", "root":{ "id":"aspaceid!anopaqueid", - "webDavUrl":"https://localhost:9200/dav/spaces/aspaceid!anopaqueid" + "webDavUrl":"https://localhost:9200/dav/spaces/aspaceid" } } ]