@@ -37,8 +37,7 @@ Alternatively, you can clone this repository and install manually:
3737``` bash
3838git clone
[email protected] :cs3org/cs3-python-client.git
3939cd cs3-python-client
40- pip install -e .
41- export PYTHONPATH=" path/to/cs3-python-client/:$PYTHONPATH "
40+ pip install .
4241```
4342
4443
@@ -112,129 +111,138 @@ lock_expiration = 1800
112111
113112To 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/ ` .
114113
115- ### Initilization
114+ ### Initilization and Authentication
116115``` python
117116import logging
118117import configparser
119118from cs3client import CS3Client
120- from cs3resource import Resource
119+ from auth import Auth
121120
122121config = configparser.ConfigParser()
123122with open (" default.conf" ) as fdef:
124123 config.read_file(fdef)
125-
126124log = logging.getLogger(__name__ )
127125
128126client = 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+
132140```
133141
134142### File Example
135143``` python
136144# mkdir
137145directory_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(auth.get_token(), directory_resource)
139147
140148# touchfile
141149touch_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(auth.get_token(), touch_resource)
143151
144152# setxattr
145153resource = 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(auth.get_token(), resource, " iop.wopi.lastwritetime" , str (1720696124 ))
147155
148156# rmxattr
149- res = client.file.remove_xattr(resource, " iop.wopi.lastwritetime" )
157+ res = client.file.remove_xattr(auth.get_token(), resource, " iop.wopi.lastwritetime" )
150158
151159# stat
152- res = client.file.stat(resource)
160+ res = client.file.stat(auth.get_token(), resource)
153161
154162# removefile
155- res = client.file.remove_file(touch_resource)
163+ res = client.file.remove_file(auth.get_token(), touch_resource)
156164
157165# rename
158166rename_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(auth.get_token(), resource, rename_resource)
160168
161169# writefile
162170content = b " Hello World"
163171size = len (content)
164- res = client.file.write_file(rename_resource, content, size)
172+ res = client.file.write_file(auth.get_token(), rename_resource, content, size)
165173
166174# listdir
167175list_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(auth.get_token(), list_directory_resource)
169177
170178
171179# readfile
172- file_res = client.file.read_file(rename_resource)
180+ file_res = client.file.read_file(auth.get_token(), rename_resource)
173181```
174182
175183### Share Example
176184``` python
177185# Create share #
178186resource = 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(auth.get_token(), resource)
180188user = 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(auth.get_token(), resource_info, user.id.opaque_id, user.id.idp, " EDITOR" , " USER" )
182190
183191# List existing shares #
184192filter_list = []
185193filter = client.share.create_share_filter(resource_id = resource_info.id, filter_type = " TYPE_RESOURCE_ID" )
186194filter_list.append(filter )
187195filter = client.share.create_share_filter(share_state = " SHARE_STATE_PENDING" , filter_type = " TYPE_STATE" )
188196filter_list.append(filter )
189- res, _ = client.share.list_existing_shares()
197+ res, _ = client.share.list_existing_shares(auth.get_token(), )
190198
191199# Get share #
192200share_id = " 58"
193- res = client.share.get_share(opaque_id = share_id)
201+ res = client.share.get_share(auth.get_token(), opaque_id = share_id)
194202
195203# update share #
196- res = client.share.update_share(opaque_id = share_id, role = " VIEWER" )
204+ res = client.share.update_share(auth.get_token(), opaque_id = share_id, role = " VIEWER" )
197205
198206# remove share #
199- res = client.share.remove_share(opaque_id = share_id)
207+ res = client.share.remove_share(auth.get_token(), opaque_id = share_id)
200208
201209# List existing received shares #
202210filter_list = []
203211filter = client.share.create_share_filter(share_state = " SHARE_STATE_ACCEPTED" , filter_type = " TYPE_STATE" )
204212filter_list.append(filter )
205- res, _ = client.share.list_received_existing_shares()
213+ res, _ = client.share.list_received_existing_shares(auth.get_token() )
206214
207215# get received share #
208- received_share = client.share.get_received_share(opaque_id = share_id)
216+ received_share = client.share.get_received_share(auth.get_token(), opaque_id = share_id)
209217
210218# 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(auth.get_token(), received_share = received_share, state = " SHARE_STATE_ACCEPTED" )
212220
213221# create public share #
214- res = client.share.create_public_share(resource_info, role = " VIEWER" )
222+ res = client.share.create_public_share(auth.get_token(), resource_info, role = " VIEWER" )
215223
216224# list existing public shares #
217225filter_list = []
218226filter = client.share.create_public_share_filter(resource_id = resource_info.id, filter_type = " TYPE_RESOURCE_ID" )
219227filter_list.append(filter )
220228res, _ = client.share.list_existing_public_shares(filter_list = filter_list)
221229
222- res = client.share.get_public_share(opaque_id = share_id, sign = True )
230+ res = client.share.get_public_share(auth.get_token(), opaque_id = share_id, sign = True )
223231# OR token = "<token>"
224232# res = client.share.get_public_share(token=token, sign=True)
225233
226234# 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(auth.get_token(), type = " TYPE_PASSWORD" , token = token, role = " VIEWER" , password = " hello" )
228236
229237# remove public share #
230- res = client.share.remove_public_share(token = token)
238+ res = client.share.remove_public_share(auth.get_token(), token = token)
231239
232240```
233241
234242### User Example
235243``` python
236244# find_user
237- res = client.user.find_users(" rwel" )
245+ res = client.user.find_users(auth.get_token(), " rwel" )
238246
239247# get_user
240248res = 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")
253261### App Example
254262``` python
255263# list_app_providers
256- res = client.app.list_app_providers()
264+ res = client.app.list_app_providers(auth.get_token() )
257265
258266# open_in_app
259267resource = 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(auth.get_token(), resource)
261269```
262270
263271### Checkpoint Example
264272``` python
265273# list file versions
266274resource = 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(auth.get_token(), resource)
268276
269277# restore file version
270- res = client.checkpoint.restore_file_version(resource, " 1722936250.0569fa2f" )
278+ res = client.checkpoint.restore_file_version(auth.get_token(), resource, " 1722936250.0569fa2f" )
271279```
272280
273281## Documentation
0 commit comments