11
11
import cs3 .storage .provider .v1beta1 .resources_pb2 as cs3spr
12
12
import cs3 .gateway .v1beta1 .gateway_api_pb2 as cs3gw
13
13
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
16
17
import core .commoniface as common
17
18
18
19
# 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):
117
118
118
119
def setxattr (endpoint , filepath , userid , key , value , lockmd ):
119
120
"""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 )
123
124
124
125
125
126
def rmxattr (endpoint , filepath , userid , key , lockmd ):
126
127
"""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 )
130
131
131
132
132
133
def readfile (endpoint , filepath , userid , lockid ):
133
134
"""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 )
137
137
for chunk in data :
138
138
yield chunk
139
139
@@ -143,51 +143,46 @@ def writefile(endpoint, filepath, userid, content, size, lockmd):
143
143
and any pre-existing file is deleted (or moved to the previous version if supported).
144
144
The islock flag is currently not supported. The backend should at least support
145
145
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 )
149
148
150
149
151
150
def renamefile (endpoint , filepath , newfilepath , userid , lockmd ):
152
151
"""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 )
157
156
158
157
159
158
def removefile (endpoint , filepath , userid ):
160
159
"""Remove a file using the given userid as access token.
161
160
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 )
165
163
166
164
167
165
def setlock (endpoint , filepath , userid , appname , value ):
168
166
"""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 )
172
169
173
170
174
171
def refreshlock (endpoint , filepath , userid , appname , value , oldvalue = None ):
175
172
"""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
+ )
179
177
180
178
181
179
def getlock (endpoint , filepath , userid ):
182
180
"""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 )
187
183
188
184
189
185
def unlock (endpoint , filepath , userid , appname , value ):
190
186
"""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