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,20 @@ 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
+ resource = Resource .from_file_ref_and_endpoint (filepath , endpoint )
122
+ client .file .set_xattr (Auth .check_token (userid ), resource , key , value , lockmd )
123
123
124
124
125
125
def rmxattr (endpoint , filepath , userid , key , lockmd ):
126
126
"""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 )
130
129
131
130
132
131
def readfile (endpoint , filepath , userid , lockid ):
133
132
"""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 )
137
135
for chunk in data :
138
136
yield chunk
139
137
@@ -143,51 +141,45 @@ def writefile(endpoint, filepath, userid, content, size, lockmd):
143
141
and any pre-existing file is deleted (or moved to the previous version if supported).
144
142
The islock flag is currently not supported. The backend should at least support
145
143
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 )
149
146
150
147
151
148
def renamefile (endpoint , filepath , newfilepath , userid , lockmd ):
152
149
"""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 )
157
153
158
154
159
155
def removefile (endpoint , filepath , userid ):
160
156
"""Remove a file using the given userid as access token.
161
157
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 )
165
160
166
161
167
162
def setlock (endpoint , filepath , userid , appname , value ):
168
163
"""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 )
172
166
173
167
174
168
def refreshlock (endpoint , filepath , userid , appname , value , oldvalue = None ):
175
169
"""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
+ )
179
174
180
175
181
176
def getlock (endpoint , filepath , userid ):
182
177
"""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 )
187
180
188
181
189
182
def unlock (endpoint , filepath , userid , appname , value ):
190
183
"""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