@@ -37,8 +37,7 @@ Alternatively, you can clone this repository and install manually:
37
37
``` bash
38
38
git clone
[email protected] :cs3org/cs3-python-client.git
39
39
cd cs3-python-client
40
- pip install -e .
41
- export PYTHONPATH=" path/to/cs3-python-client/:$PYTHONPATH "
40
+ pip install .
42
41
```
43
42
44
43
@@ -112,129 +111,138 @@ lock_expiration = 1800
112
111
113
112
To use ` cs3client ` , you first need to import and configure it. Here's a simple example of how to set up and start using the client. For configuration see [ Configuration] ( #configuration ) . For more in depth examples see ` cs3-python-client/examples/ ` .
114
113
115
- ### Initilization
114
+ ### Initilization and Authentication
116
115
``` python
117
116
import logging
118
117
import configparser
119
118
from cs3client import CS3Client
120
- from cs3resource import Resource
119
+ from auth import Auth
121
120
122
121
config = configparser.ConfigParser()
123
122
with open (" default.conf" ) as fdef:
124
123
config.read_file(fdef)
125
-
126
124
log = logging.getLogger(__name__ )
127
125
128
126
client = CS3Client(config, " cs3client" , log)
129
- # client.auth.set_token("<your_token_here>")
130
- # OR
131
- client.auth.set_client_secret(" <your_client_secret_here>" )
127
+ auth = Auth(client)
128
+ # Set client secret (can also be set in config)
129
+ auth.set_client_secret(" <your_client_secret_here>" )
130
+ # Checks if token is expired if not return ('x-access-token', <token>)
131
+ # if expired, request a new token from reva
132
+ auth_token = auth.get_token()
133
+
134
+ # OR if you already have a reva token
135
+ # Checks if token is expired if not return (x-access-token', <token>)
136
+ # if expired, throws an AuthenticationException (so you can refresh your reva token)
137
+ token = " <your_reva_token>"
138
+ auth_token = Auth.check_token(token)
139
+
132
140
```
133
141
134
142
### File Example
135
143
``` python
136
144
# mkdir
137
145
directory_resource = Resource.from_file_ref_and_endpoint(f " /eos/user/r/rwelande/test_directory " )
138
- res = client.file.make_dir(directory_resource)
146
+ res = client.file.make_dir(client.auth.get_token(), directory_resource)
139
147
140
148
# touchfile
141
149
touch_resource = Resource.from_file_ref_and_endpoint(" /eos/user/r/rwelande/touch_file.txt" )
142
- res = client.file.touch_file(touch_resource)
150
+ res = client.file.touch_file(client.auth.get_token(), touch_resource)
143
151
144
152
# setxattr
145
153
resource = Resource.from_file_ref_and_endpoint(" /eos/user/r/rwelande/text_file.txt" )
146
- res = client.file.set_xattr(resource, " iop.wopi.lastwritetime" , str (1720696124 ))
154
+ res = client.file.set_xattr(client.auth.get_token(), resource, " iop.wopi.lastwritetime" , str (1720696124 ))
147
155
148
156
# rmxattr
149
- res = client.file.remove_xattr(resource, " iop.wopi.lastwritetime" )
157
+ res = client.file.remove_xattr(client.auth.get_token(), resource, " iop.wopi.lastwritetime" )
150
158
151
159
# stat
152
- res = client.file.stat(resource)
160
+ res = client.file.stat(client.auth.get_token(), resource)
153
161
154
162
# removefile
155
- res = client.file.remove_file(touch_resource)
163
+ res = client.file.remove_file(client.auth.get_token(), touch_resource)
156
164
157
165
# rename
158
166
rename_resource = Resource.from_file_ref_and_endpoint(" /eos/user/r/rwelande/rename_file.txt" )
159
- res = client.file.rename_file(resource, rename_resource)
167
+ res = client.file.rename_file(client.auth.get_token(), resource, rename_resource)
160
168
161
169
# writefile
162
170
content = b " Hello World"
163
171
size = len (content)
164
- res = client.file.write_file(rename_resource, content, size)
172
+ res = client.file.write_file(client.auth.get_token(), rename_resource, content, size)
165
173
166
174
# listdir
167
175
list_directory_resource = Resource.from_file_ref_and_endpoint(" /eos/user/r/rwelande" )
168
- res = client.file.list_dir(list_directory_resource)
176
+ res = client.file.list_dir(client.auth.get_token(), list_directory_resource)
169
177
170
178
171
179
# readfile
172
- file_res = client.file.read_file(rename_resource)
180
+ file_res = client.file.read_file(client.auth.get_token(), rename_resource)
173
181
```
174
182
175
183
### Share Example
176
184
``` python
177
185
# Create share #
178
186
resource = Resource.from_file_ref_and_endpoint(" /eos/user/r/<some_username>/text.txt" )
179
- resource_info = client.file.stat(resource)
187
+ resource_info = client.file.stat(client.auth.get_token(), resource)
180
188
user = client.user.get_user_by_claim(" username" , " <some_username>" )
181
- res = client.share.create_share(resource_info, user.id.opaque_id, user.id.idp, " EDITOR" , " USER" )
189
+ res = client.share.create_share(client.auth.get_token(), resource_info, user.id.opaque_id, user.id.idp, " EDITOR" , " USER" )
182
190
183
191
# List existing shares #
184
192
filter_list = []
185
193
filter = client.share.create_share_filter(resource_id = resource_info.id, filter_type = " TYPE_RESOURCE_ID" )
186
194
filter_list.append(filter )
187
195
filter = client.share.create_share_filter(share_state = " SHARE_STATE_PENDING" , filter_type = " TYPE_STATE" )
188
196
filter_list.append(filter )
189
- res, _ = client.share.list_existing_shares()
197
+ res, _ = client.share.list_existing_shares(client.auth.get_token(), )
190
198
191
199
# Get share #
192
200
share_id = " 58"
193
- res = client.share.get_share(opaque_id = share_id)
201
+ res = client.share.get_share(client.auth.get_token(), opaque_id = share_id)
194
202
195
203
# update share #
196
- res = client.share.update_share(opaque_id = share_id, role = " VIEWER" )
204
+ res = client.share.update_share(client.auth.get_token(), opaque_id = share_id, role = " VIEWER" )
197
205
198
206
# remove share #
199
- res = client.share.remove_share(opaque_id = share_id)
207
+ res = client.share.remove_share(client.auth.get_token(), opaque_id = share_id)
200
208
201
209
# List existing received shares #
202
210
filter_list = []
203
211
filter = client.share.create_share_filter(share_state = " SHARE_STATE_ACCEPTED" , filter_type = " TYPE_STATE" )
204
212
filter_list.append(filter )
205
- res, _ = client.share.list_received_existing_shares()
213
+ res, _ = client.share.list_received_existing_shares(client.auth.get_token() )
206
214
207
215
# get received share #
208
- received_share = client.share.get_received_share(opaque_id = share_id)
216
+ received_share = client.share.get_received_share(client.auth.get_token(), opaque_id = share_id)
209
217
210
218
# update recieved share #
211
- res = client.share.update_received_share(received_share = received_share, state = " SHARE_STATE_ACCEPTED" )
219
+ res = client.share.update_received_share(client.auth.get_token(), received_share = received_share, state = " SHARE_STATE_ACCEPTED" )
212
220
213
221
# create public share #
214
- res = client.share.create_public_share(resource_info, role = " VIEWER" )
222
+ res = client.share.create_public_share(client.auth.get_token(), resource_info, role = " VIEWER" )
215
223
216
224
# list existing public shares #
217
225
filter_list = []
218
226
filter = client.share.create_public_share_filter(resource_id = resource_info.id, filter_type = " TYPE_RESOURCE_ID" )
219
227
filter_list.append(filter )
220
228
res, _ = client.share.list_existing_public_shares(filter_list = filter_list)
221
229
222
- res = client.share.get_public_share(opaque_id = share_id, sign = True )
230
+ res = client.share.get_public_share(client.auth.get_token(), opaque_id = share_id, sign = True )
223
231
# OR token = "<token>"
224
232
# res = client.share.get_public_share(token=token, sign=True)
225
233
226
234
# update public share #
227
- res = client.share.update_public_share(type = " TYPE_PASSWORD" , token = token, role = " VIEWER" , password = " hello" )
235
+ res = client.share.update_public_share(client.auth.get_token(), type = " TYPE_PASSWORD" , token = token, role = " VIEWER" , password = " hello" )
228
236
229
237
# remove public share #
230
- res = client.share.remove_public_share(token = token)
238
+ res = client.share.remove_public_share(client.auth.get_token(), token = token)
231
239
232
240
```
233
241
234
242
### User Example
235
243
``` python
236
244
# find_user
237
- res = client.user.find_users(" rwel" )
245
+ res = client.user.find_users(client.auth.get_token(), " rwel" )
238
246
239
247
# get_user
240
248
res = client.user.get_user(" https://auth.cern.ch/auth/realms/cern" , " asdoiqwe" )
@@ -253,21 +261,21 @@ res = client.user.get_user_by_claim("username", "rwelande")
253
261
### App Example
254
262
``` python
255
263
# list_app_providers
256
- res = client.app.list_app_providers()
264
+ res = client.app.list_app_providers(client.auth.get_token() )
257
265
258
266
# open_in_app
259
267
resource = Resource.from_file_ref_and_endpoint(" /eos/user/r/rwelande/collabora.odt" )
260
- res = client.app.open_in_app(resource)
268
+ res = client.app.open_in_app(client.auth.get_token(), resource)
261
269
```
262
270
263
271
### Checkpoint Example
264
272
``` python
265
273
# list file versions
266
274
resource = Resource.from_file_ref_and_endpoint(" /eos/user/r/rwelande/test.md" )
267
- res = client.checkpoint.list_file_versions(resource)
275
+ res = client.checkpoint.list_file_versions(client.auth.get_token(), resource)
268
276
269
277
# restore file version
270
- res = client.checkpoint.restore_file_version(resource, " 1722936250.0569fa2f" )
278
+ res = client.checkpoint.restore_file_version(client.auth.get_token(), resource, " 1722936250.0569fa2f" )
271
279
```
272
280
273
281
## Documentation
0 commit comments