Skip to content

Commit 9f46cb2

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

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

src/core/cs3iface.py

Lines changed: 29 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,22 @@ 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+
_, lock_id = lockmd
122+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
123+
client.file.set_xattr(Auth.check_token(userid), resource, key, value, lock_id)
123124

124125

125126
def rmxattr(endpoint, filepath, userid, key, lockmd):
126127
"""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)
128+
_, lock_id = lockmd
129+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
130+
client.file.remove_xattr(Auth.check_token(userid), resource, key, lock_id)
130131

131132

132133
def readfile(endpoint, filepath, userid, lockid):
133134
"""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)
135+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
136+
data = client.file.read_file(Auth.check_token(userid), resource, lockid)
137137
for chunk in data:
138138
yield chunk
139139

@@ -143,51 +143,46 @@ def writefile(endpoint, filepath, userid, content, size, lockmd):
143143
and any pre-existing file is deleted (or moved to the previous version if supported).
144144
The islock flag is currently not supported. The backend should at least support
145145
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)
146+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
147+
client.file.write_file(Auth.check_token(userid), resource, content, size, lockmd)
149148

150149

151150
def renamefile(endpoint, filepath, newfilepath, userid, lockmd):
152151
"""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)
152+
_, lock_id = lockmd
153+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
154+
new_resource = Resource.from_file_ref_and_endpoint(newfilepath, endpoint)
155+
client.file.rename_file(Auth.check_token(userid), resource, new_resource, lock_id)
157156

158157

159158
def removefile(endpoint, filepath, userid):
160159
"""Remove a file using the given userid as access token.
161160
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)
161+
resource = Resource.from_file_ref_and_endpoint(endpoint, filepath)
162+
client.file.remove_file(Auth.check_token(userid), resource)
165163

166164

167165
def setlock(endpoint, filepath, userid, appname, value):
168166
"""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)
167+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
168+
client.file.set_lock(Auth.check_token(userid), resource, app_name=appname, lock_id=value)
172169

173170

174171
def refreshlock(endpoint, filepath, userid, appname, value, oldvalue=None):
175172
"""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)
173+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
174+
client.file.refresh_lock(
175+
Auth.check_token(userid), resource, app_name=appname, lock_id=value, existing_lock_id=oldvalue
176+
)
179177

180178

181179
def getlock(endpoint, filepath, userid):
182180
"""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
181+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
182+
return client.file.get_lock(Auth.check_token(userid), resource)
187183

188184

189185
def unlock(endpoint, filepath, userid, appname, value):
190186
"""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)
187+
resource = Resource.from_file_ref_and_endpoint(filepath, endpoint)
188+
client.file.unlock(Auth.check_token(userid), resource, app_name=appname, lock_id=value)

0 commit comments

Comments
 (0)