Skip to content

Commit

Permalink
optionally split space id from endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Jul 14, 2022
1 parent 2bf00ed commit 29621c1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/core/cs3iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import http
import requests
import grpc
import string

import cs3.storage.provider.v1beta1.resources_pb2 as cs3spr
import cs3.storage.provider.v1beta1.provider_api_pb2 as cs3sp
Expand Down Expand Up @@ -53,15 +54,22 @@ def getuseridfromcreds(token, _wopiuser):
def _getcs3reference(endpoint, fileref):
'''Generates a CS3 reference for a given fileref, covering the following cases:
absolute path, relative hybrid path, fully opaque fileid'''
# try splitting endpoint
parts = endpoint.split("$", 2)
endpoint = parts[0]
space_id = ""
if len(parts) == 2:
space_id = parts[1]

if fileref.find('/') > 0:
# assume we have a relative path in the form `<parent_opaque_id>/<base_filename>`,
# also works if we get `<parent_opaque_id>/<path>/<filename>`
ref = cs3spr.Reference(resource_id=cs3spr.ResourceId(storage_id=endpoint,
ref = cs3spr.Reference(resource_id=cs3spr.ResourceId(storage_id=endpoint, space_id=space_id,
opaque_id=fileref[:fileref.find('/')]),
path='.' + fileref[fileref.find('/'):])
else:
# assume we have an opaque fileid
ref = cs3spr.Reference(resource_id=cs3spr.ResourceId(storage_id=endpoint, opaque_id=fileref), path='.')
ref = cs3spr.Reference(resource_id=cs3spr.ResourceId(storage_id=endpoint, space_id=space_id, opaque_id=fileref), path='.')
return ref


Expand Down

0 comments on commit 29621c1

Please sign in to comment.