Skip to content

Commit 2f02e28

Browse files
author
Rasmus Oscar Welander
committed
Authentication in cs3client is handled externally now, fixed
1 parent 0d2e488 commit 2f02e28

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

src/core/cs3iface.py

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
import cs3.storage.provider.v1beta1.resources_pb2 as cs3spr
1212
import cs3.gateway.v1beta1.gateway_api_pb2 as cs3gw
1313
import cs3.rpc.v1beta1.code_pb2 as cs3code
14-
from cs3client import CS3Client
15-
from cs3resource import Resource
14+
from cs3client.cs3client import CS3Client
15+
from cs3client.cs3resource import Resource
16+
from cs3client.auth import Auth
1617
import core.commoniface as common
1718

1819
# key used if the `lockasattr` option is true, in order to store the lock payload without ensuring any lock semantic
@@ -117,23 +118,20 @@ def statx(endpoint, fileref, userid):
117118

118119
def setxattr(endpoint, filepath, userid, key, value, lockmd):
119120
"""Set the extended attribute <key> to <value> using the given userid as access token"""
120-
resource = Resource(endpoint, filepath)
121-
client.auth.set_token(userid)
122-
client.file.set_xattr(resource, key, value, lockmd)
121+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
122+
client.file.set_xattr(Auth.check_token(userid), resource, key, value, lockmd)
123123

124124

125125
def rmxattr(endpoint, filepath, userid, key, lockmd):
126126
"""Remove the extended attribute <key> using the given userid as access token"""
127-
resource = Resource(endpoint, filepath)
128-
client.auth.set_token(userid)
129-
client.file.remove_xattr(resource, key, lockmd)
127+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
128+
client.file.remove_xattr(Auth.check_token(userid), resource, key, lockmd)
130129

131130

132131
def readfile(endpoint, filepath, userid, lockid):
133132
"""Read a file using the given userid as access token. Note that the function is a generator, managed by the app server."""
134-
resource = Resource(endpoint, filepath)
135-
client.auth.set_token(userid)
136-
data = client.file.read_file(resource, lockid)
133+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
134+
data = client.file.read_file(Auth.check_token(userid), resource, lockid)
137135
for chunk in data:
138136
yield chunk
139137

@@ -143,51 +141,45 @@ def writefile(endpoint, filepath, userid, content, size, lockmd):
143141
and any pre-existing file is deleted (or moved to the previous version if supported).
144142
The islock flag is currently not supported. The backend should at least support
145143
writing the file with O_CREAT|O_EXCL flags to prevent races."""
146-
resource = Resource(endpoint, filepath)
147-
client.auth.set_token(userid)
148-
client.file.write_file(resource, content, size, lockmd)
144+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
145+
client.file.write_file(Auth.check_token(userid), resource, content, size, lockmd)
149146

150147

151148
def renamefile(endpoint, filepath, newfilepath, userid, lockmd):
152149
"""Rename a file from origfilepath to newfilepath using the given userid as access token."""
153-
resource = Resource(endpoint, filepath)
154-
new_resource = Resource(endpoint, newfilepath)
155-
client.auth.set_token(userid)
156-
client.file.rename_file(resource, new_resource, lockmd)
150+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
151+
new_resource = Resource.from_file_ref_and_endpoint(newfilepath, endpoint)
152+
client.file.rename_file(Auth.check_token(userid), resource, new_resource, lockmd)
157153

158154

159155
def removefile(endpoint, filepath, userid):
160156
"""Remove a file using the given userid as access token.
161157
The force argument is ignored for now for CS3 storage."""
162-
resource = Resource(endpoint, filepath)
163-
client.auth.set_token(userid)
164-
client.file.remove_file(resource)
158+
resource = Resource.from_file_ref_and_endpoint(endpoint, filepath)
159+
client.file.remove_file(Auth.check_token(userid), resource)
165160

166161

167162
def setlock(endpoint, filepath, userid, appname, value):
168163
"""Set a lock to filepath with the given value metadata and appname as holder"""
169-
resource = Resource(endpoint, filepath)
170-
client.auth.set_token(userid)
171-
client.file.set_lock(resource, app_name=appname, value=value)
164+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
165+
client.file.set_lock(Auth.check_token(userid), resource, app_name=appname, lock_id=value)
172166

173167

174168
def refreshlock(endpoint, filepath, userid, appname, value, oldvalue=None):
175169
"""Refresh the lock metadata for the given filepath"""
176-
resource = Resource(endpoint, filepath)
177-
client.auth.set_token(userid)
178-
client.file.refresh_lock(resource, app_name=appname, value=value, old_value=oldvalue)
170+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
171+
client.file.refresh_lock(
172+
Auth.check_token(userid), resource, app_name=appname, lock_id=value, existing_lock_id=oldvalue
173+
)
179174

180175

181176
def getlock(endpoint, filepath, userid):
182177
"""Get the lock metadata for the given filepath"""
183-
resource = Resource(endpoint, filepath)
184-
client.auth.set_token(userid)
185-
lock = client.file.get_lock(resource)
186-
return lock
178+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
179+
return client.file.get_lock(Auth.check_token(userid), resource)
187180

188181

189182
def unlock(endpoint, filepath, userid, appname, value):
190183
"""Remove the lock for the given filepath"""
191-
resource = Resource(endpoint, filepath)
192-
client.auth.set_token(userid)
193-
client.file.unlock(resource, app_name=appname, value=value)
184+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
185+
client.file.unlock(Auth.check_token(userid), resource, app_name=appname, lock_id=value)

0 commit comments

Comments
 (0)