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