cs3client 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cs3client-0.0.1/LICENSE +175 -0
- cs3client-0.0.1/PKG-INFO +368 -0
- cs3client-0.0.1/README.md +342 -0
- cs3client-0.0.1/cs3client/__init__.py +0 -0
- cs3client-0.0.1/cs3client/app.py +84 -0
- cs3client-0.0.1/cs3client/auth.py +141 -0
- cs3client-0.0.1/cs3client/checkpoint.py +86 -0
- cs3client-0.0.1/cs3client/config.py +198 -0
- cs3client-0.0.1/cs3client/cs3client.py +73 -0
- cs3client-0.0.1/cs3client/cs3resource.py +207 -0
- cs3client-0.0.1/cs3client/exceptions/__init__.py +0 -0
- cs3client-0.0.1/cs3client/exceptions/exceptions.py +73 -0
- cs3client-0.0.1/cs3client/file.py +628 -0
- cs3client-0.0.1/cs3client/share.py +734 -0
- cs3client-0.0.1/cs3client/statuscodehandler.py +105 -0
- cs3client-0.0.1/cs3client/user.py +108 -0
- cs3client-0.0.1/cs3client.egg-info/PKG-INFO +368 -0
- cs3client-0.0.1/cs3client.egg-info/SOURCES.txt +28 -0
- cs3client-0.0.1/cs3client.egg-info/dependency_links.txt +1 -0
- cs3client-0.0.1/cs3client.egg-info/requires.txt +8 -0
- cs3client-0.0.1/cs3client.egg-info/top_level.txt +1 -0
- cs3client-0.0.1/setup.cfg +4 -0
- cs3client-0.0.1/setup.py +49 -0
- cs3client-0.0.1/tests/test_app.py +86 -0
- cs3client-0.0.1/tests/test_checkpoint.py +90 -0
- cs3client-0.0.1/tests/test_cs3client.py +82 -0
- cs3client-0.0.1/tests/test_file.py +329 -0
- cs3client-0.0.1/tests/test_resource.py +138 -0
- cs3client-0.0.1/tests/test_share.py +637 -0
- cs3client-0.0.1/tests/test_user.py +141 -0
cs3client-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
cs3client-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cs3client
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: CS3 client for Python
|
|
5
|
+
Home-page: https://github.com/cs3org/cs3-python-client
|
|
6
|
+
Author: Rasmus Welander, Diogo Castro, Giuseppe Lo Presti
|
|
7
|
+
License: Apache 2.0
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: grpcio>=1.47.0
|
|
19
|
+
Requires-Dist: grpcio-tools>=1.47.0
|
|
20
|
+
Requires-Dist: pyOpenSSL
|
|
21
|
+
Requires-Dist: requests
|
|
22
|
+
Requires-Dist: cs3apis
|
|
23
|
+
Requires-Dist: PyJWT
|
|
24
|
+
Requires-Dist: protobuf
|
|
25
|
+
Requires-Dist: cryptography
|
|
26
|
+
|
|
27
|
+
# CS3Client
|
|
28
|
+
|
|
29
|
+
`CS3Client` is a Python client for interacting with the CS3 (Cloud Storage Services for Science) API. It allows users to seamlessly communicate with cloud storage services that support CS3 protocols, enabling file management, data transfer, and other cloud-based operations.
|
|
30
|
+
|
|
31
|
+
## Table of Contents
|
|
32
|
+
|
|
33
|
+
- [Features](#features)
|
|
34
|
+
- [Installation](#installation)
|
|
35
|
+
- [Usage](#usage)
|
|
36
|
+
- [Configuration](#configuration)
|
|
37
|
+
- [Examples](#examples)
|
|
38
|
+
- [Documentation](#documentation)
|
|
39
|
+
- [License](#license)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
- Simple and easy-to-use API client for CS3 services.
|
|
45
|
+
- Support for common file operations (read, write, delete, rename, ...).
|
|
46
|
+
- Support for common lock operations (set lock, get lock, unlock, ...).
|
|
47
|
+
- Support for common share operations (create share, update share, delete share, ...).
|
|
48
|
+
- Support for common user operations (get user, find users, get user groups, ...).
|
|
49
|
+
- Support for restoring files through checkpoints (restore file version, list checkpoints).
|
|
50
|
+
- Support for applications (open in app, list app providers).
|
|
51
|
+
- Authentication and authorization handling.
|
|
52
|
+
- Cross-platform compatibility.
|
|
53
|
+
- Detailed error handling and logging.
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
To install `cs3client`, you need to have Python 3.7+ installed. You can install the package via `pip`:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install cs3client
|
|
61
|
+
```
|
|
62
|
+
Alternatively, you can clone this repository and install manually:
|
|
63
|
+
```bash
|
|
64
|
+
git clone git@github.com:cs3org/cs3-python-client.git
|
|
65
|
+
cd cs3-python-client
|
|
66
|
+
pip install .
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## Configuration
|
|
71
|
+
|
|
72
|
+
`CS3Client` can be configured by passing specific parameters when initializing the client through a ConfigParser instance.
|
|
73
|
+
|
|
74
|
+
### Parameters:
|
|
75
|
+
|
|
76
|
+
#### Required
|
|
77
|
+
- `host`
|
|
78
|
+
|
|
79
|
+
#### Optional (parameter - default)
|
|
80
|
+
- `chunk_size` - 4194384
|
|
81
|
+
- `grpc_timeout` - 10
|
|
82
|
+
- `http_timeout` - 10
|
|
83
|
+
- `tus_enabled` - False
|
|
84
|
+
- `ssl_enabled` - False
|
|
85
|
+
- `ssl_client_cert` - None
|
|
86
|
+
- `ssl_client_key` - None
|
|
87
|
+
- `ssl_ca_cert` - None
|
|
88
|
+
- `auth_client_id` - None
|
|
89
|
+
- `auth_login_type` - "basic"
|
|
90
|
+
- `lock_by_setting_attr` - False
|
|
91
|
+
- `lock_not_impl` - False
|
|
92
|
+
- `lock_expiration` - 1800
|
|
93
|
+
|
|
94
|
+
#### Example configuration
|
|
95
|
+
```yaml
|
|
96
|
+
[cs3client]
|
|
97
|
+
|
|
98
|
+
# Required
|
|
99
|
+
host = localhost:19000
|
|
100
|
+
# Optional, defaults to 4194304
|
|
101
|
+
chunk_size = 4194304
|
|
102
|
+
# Optional, defaults to 10
|
|
103
|
+
grpc_timeout = 10
|
|
104
|
+
# Optional, defaults to 10
|
|
105
|
+
http_timeout = 10
|
|
106
|
+
|
|
107
|
+
# Optional, defaults to True
|
|
108
|
+
tus_enabled = False
|
|
109
|
+
|
|
110
|
+
# Optional, defaults to True
|
|
111
|
+
ssl_enabled = False
|
|
112
|
+
# Optional, defaults to True
|
|
113
|
+
ssl_verify = False
|
|
114
|
+
# Optional, defaults to an empty string
|
|
115
|
+
ssl_client_cert = test_client_cert
|
|
116
|
+
# Optional, defaults to an empty string
|
|
117
|
+
ssl_client_key = test_client_key
|
|
118
|
+
# Optional, defaults to an empty string
|
|
119
|
+
ssl_ca_cert = test_ca_cert
|
|
120
|
+
|
|
121
|
+
# Optinal, defaults to an empty string
|
|
122
|
+
auth_client_id = einstein
|
|
123
|
+
# Optional (can also be set when instansiating the class)
|
|
124
|
+
auth_client_secret = relativity
|
|
125
|
+
# Optional, defaults to basic
|
|
126
|
+
auth_login_type = basic
|
|
127
|
+
|
|
128
|
+
# Optional, defaults to False
|
|
129
|
+
lock_by_setting_attr = False
|
|
130
|
+
# Optional, defaults to False
|
|
131
|
+
lock_not_impl = False
|
|
132
|
+
# Optional, defaults to 1800
|
|
133
|
+
lock_expiration = 1800
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Usage
|
|
139
|
+
|
|
140
|
+
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/`.
|
|
141
|
+
|
|
142
|
+
### Initilization and Authentication
|
|
143
|
+
```python
|
|
144
|
+
import logging
|
|
145
|
+
import configparser
|
|
146
|
+
from cs3client.cs3client import CS3Client
|
|
147
|
+
from cs3client.auth import Auth
|
|
148
|
+
|
|
149
|
+
config = configparser.ConfigParser()
|
|
150
|
+
with open("default.conf") as fdef:
|
|
151
|
+
config.read_file(fdef)
|
|
152
|
+
log = logging.getLogger(__name__)
|
|
153
|
+
|
|
154
|
+
client = CS3Client(config, "cs3client", log)
|
|
155
|
+
auth = Auth(client)
|
|
156
|
+
# Set the client id (can also be set in the config)
|
|
157
|
+
auth.set_client_id("<your_client_id_here>")
|
|
158
|
+
# Set client secret (can also be set in config)
|
|
159
|
+
auth.set_client_secret("<your_client_secret_here>")
|
|
160
|
+
# Checks if token is expired if not return ('x-access-token', <token>)
|
|
161
|
+
# if expired, request a new token from reva
|
|
162
|
+
auth_token = auth.get_token()
|
|
163
|
+
|
|
164
|
+
# OR if you already have a reva token
|
|
165
|
+
# Checks if token is expired if not return (x-access-token', <token>)
|
|
166
|
+
# if expired, throws an AuthenticationException (so you can refresh your reva token)
|
|
167
|
+
token = "<your_reva_token>"
|
|
168
|
+
auth_token = Auth.check_token(token)
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### File Example
|
|
173
|
+
```python
|
|
174
|
+
# mkdir
|
|
175
|
+
directory_resource = Resource(abs_path=f"/eos/user/r/rwelande/test_directory")
|
|
176
|
+
res = client.file.make_dir(auth.get_token(), directory_resource)
|
|
177
|
+
|
|
178
|
+
# touchfile
|
|
179
|
+
touch_resource = Resource(abs_path="/eos/user/r/rwelande/touch_file.txt")
|
|
180
|
+
res = client.file.touch_file(auth.get_token(), touch_resource)
|
|
181
|
+
|
|
182
|
+
# setxattr
|
|
183
|
+
resource = Resource(abs_path="/eos/user/r/rwelande/text_file.txt")
|
|
184
|
+
res = client.file.set_xattr(auth.get_token(), resource, "iop.wopi.lastwritetime", str(1720696124))
|
|
185
|
+
|
|
186
|
+
# rmxattr
|
|
187
|
+
res = client.file.remove_xattr(auth.get_token(), resource, "iop.wopi.lastwritetime")
|
|
188
|
+
|
|
189
|
+
# stat
|
|
190
|
+
res = client.file.stat(auth.get_token(), resource)
|
|
191
|
+
|
|
192
|
+
# removefile
|
|
193
|
+
res = client.file.remove_file(auth.get_token(), touch_resource)
|
|
194
|
+
|
|
195
|
+
# rename
|
|
196
|
+
rename_resource = Resource(abs_path="/eos/user/r/rwelande/rename_file.txt")
|
|
197
|
+
res = client.file.rename_file(auth.get_token(), resource, rename_resource)
|
|
198
|
+
|
|
199
|
+
# writefile
|
|
200
|
+
content = b"Hello World"
|
|
201
|
+
size = len(content)
|
|
202
|
+
res = client.file.write_file(auth.get_token(), rename_resource, content, size)
|
|
203
|
+
|
|
204
|
+
# listdir
|
|
205
|
+
list_directory_resource = Resource(abs_path="/eos/user/r/rwelande")
|
|
206
|
+
res = client.file.list_dir(auth.get_token(), list_directory_resource)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
# readfile
|
|
210
|
+
file_res = client.file.read_file(auth.get_token(), rename_resource)
|
|
211
|
+
```
|
|
212
|
+
### Lock Example
|
|
213
|
+
```python
|
|
214
|
+
|
|
215
|
+
WEBDAV_LOCK_PREFIX = 'opaquelocktoken:797356a8-0500-4ceb-a8a0-c94c8cde7eba'
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def encode_lock(lock):
|
|
219
|
+
'''Generates the lock payload for the storage given the raw metadata'''
|
|
220
|
+
if lock:
|
|
221
|
+
return WEBDAV_LOCK_PREFIX + ' ' + b64encode(lock.encode()).decode()
|
|
222
|
+
return None
|
|
223
|
+
|
|
224
|
+
resource = Resource(abs_path="/eos/user/r/rwelande/lock_test.txt")
|
|
225
|
+
|
|
226
|
+
# Set lock
|
|
227
|
+
client.file.set_lock(auth_token, resource, app_name="a", lock_id=encode_lock("some_lock"))
|
|
228
|
+
|
|
229
|
+
# Get lock
|
|
230
|
+
res = client.file.get_lock(auth_token, resource)
|
|
231
|
+
if res is not None:
|
|
232
|
+
lock_id = res["lock_id"]
|
|
233
|
+
print(res)
|
|
234
|
+
|
|
235
|
+
# Unlock
|
|
236
|
+
res = client.file.unlock(auth_token, resource, app_name="a", lock_id=lock_id)
|
|
237
|
+
|
|
238
|
+
# Refresh lock
|
|
239
|
+
client.file.set_lock(auth_token, resource, app_name="a", lock_id=encode_lock("some_lock"))
|
|
240
|
+
res = client.file.refresh_lock(
|
|
241
|
+
auth_token, resource, app_name="a", lock_id=encode_lock("new_lock"), existing_lock_id=lock_id
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
if res is not None:
|
|
245
|
+
print(res)
|
|
246
|
+
|
|
247
|
+
res = client.file.get_lock(auth_token, resource)
|
|
248
|
+
if res is not None:
|
|
249
|
+
print(res)
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Share Example
|
|
254
|
+
```python
|
|
255
|
+
# Create share #
|
|
256
|
+
resource = Resource(abs_path="/eos/user/r/<some_username>/text.txt")
|
|
257
|
+
resource_info = client.file.stat(auth.get_token(), resource)
|
|
258
|
+
user = client.user.get_user_by_claim("username", "<some_username>")
|
|
259
|
+
res = client.share.create_share(auth.get_token(), resource_info, user.id.opaque_id, user.id.idp, "EDITOR", "USER")
|
|
260
|
+
|
|
261
|
+
# List existing shares #
|
|
262
|
+
filter_list = []
|
|
263
|
+
filter = client.share.create_share_filter(resource_id=resource_info.id, filter_type="TYPE_RESOURCE_ID")
|
|
264
|
+
filter_list.append(filter)
|
|
265
|
+
filter = client.share.create_share_filter(share_state="SHARE_STATE_PENDING", filter_type="TYPE_STATE")
|
|
266
|
+
filter_list.append(filter)
|
|
267
|
+
res, _ = client.share.list_existing_shares(auth.get_token(), )
|
|
268
|
+
|
|
269
|
+
# Get share #
|
|
270
|
+
share_id = "58"
|
|
271
|
+
res = client.share.get_share(auth.get_token(), opaque_id=share_id)
|
|
272
|
+
|
|
273
|
+
# update share #
|
|
274
|
+
res = client.share.update_share(auth.get_token(), opaque_id=share_id, role="VIEWER")
|
|
275
|
+
|
|
276
|
+
# remove share #
|
|
277
|
+
res = client.share.remove_share(auth.get_token(), opaque_id=share_id)
|
|
278
|
+
|
|
279
|
+
# List existing received shares #
|
|
280
|
+
filter_list = []
|
|
281
|
+
filter = client.share.create_share_filter(share_state="SHARE_STATE_ACCEPTED", filter_type="TYPE_STATE")
|
|
282
|
+
filter_list.append(filter)
|
|
283
|
+
res, _ = client.share.list_received_existing_shares(auth.get_token())
|
|
284
|
+
|
|
285
|
+
# get received share #
|
|
286
|
+
received_share = client.share.get_received_share(auth.get_token(), opaque_id=share_id)
|
|
287
|
+
|
|
288
|
+
# update recieved share #
|
|
289
|
+
res = client.share.update_received_share(auth.get_token(), received_share=received_share, state="SHARE_STATE_ACCEPTED")
|
|
290
|
+
|
|
291
|
+
# create public share #
|
|
292
|
+
res = client.share.create_public_share(auth.get_token(), resource_info, role="VIEWER")
|
|
293
|
+
|
|
294
|
+
# list existing public shares #
|
|
295
|
+
filter_list = []
|
|
296
|
+
filter = client.share.create_public_share_filter(resource_id=resource_info.id, filter_type="TYPE_RESOURCE_ID")
|
|
297
|
+
filter_list.append(filter)
|
|
298
|
+
res, _ = client.share.list_existing_public_shares(filter_list=filter_list)
|
|
299
|
+
|
|
300
|
+
res = client.share.get_public_share(auth.get_token(), opaque_id=share_id, sign=True)
|
|
301
|
+
# OR token = "<token>"
|
|
302
|
+
# res = client.share.get_public_share(token=token, sign=True)
|
|
303
|
+
|
|
304
|
+
# update public share #
|
|
305
|
+
res = client.share.update_public_share(auth.get_token(), type="TYPE_PASSWORD", token=token, role="VIEWER", password="hello")
|
|
306
|
+
|
|
307
|
+
# remove public share #
|
|
308
|
+
res = client.share.remove_public_share(auth.get_token(), token=token)
|
|
309
|
+
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### User Example
|
|
313
|
+
```python
|
|
314
|
+
# find_user
|
|
315
|
+
res = client.user.find_users(auth.get_token(), "rwel")
|
|
316
|
+
|
|
317
|
+
# get_user
|
|
318
|
+
res = client.user.get_user("https://auth.cern.ch/auth/realms/cern", "asdoiqwe")
|
|
319
|
+
|
|
320
|
+
# get_user_groups
|
|
321
|
+
res = client.user.get_user_groups("https://auth.cern.ch/auth/realms/cern", "rwelande")
|
|
322
|
+
|
|
323
|
+
# get_user_by_claim (mail)
|
|
324
|
+
res = client.user.get_user_by_claim("mail", "rasmus.oscar.welander@cern.ch")
|
|
325
|
+
|
|
326
|
+
# get_user_by_claim (username)
|
|
327
|
+
res = client.user.get_user_by_claim("username", "rwelande")
|
|
328
|
+
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### App Example
|
|
332
|
+
```python
|
|
333
|
+
# list_app_providers
|
|
334
|
+
res = client.app.list_app_providers(auth.get_token())
|
|
335
|
+
|
|
336
|
+
# open_in_app
|
|
337
|
+
resource = Resource(abs_path="/eos/user/r/rwelande/collabora.odt")
|
|
338
|
+
res = client.app.open_in_app(auth.get_token(), resource)
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Checkpoint Example
|
|
342
|
+
```python
|
|
343
|
+
# list file versions
|
|
344
|
+
resource = Resource(abs_path="/eos/user/r/rwelande/test.md")
|
|
345
|
+
res = client.checkpoint.list_file_versions(auth.get_token(), resource)
|
|
346
|
+
|
|
347
|
+
# restore file version
|
|
348
|
+
res = client.checkpoint.restore_file_version(auth.get_token(), resource, "1722936250.0569fa2f")
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## Documentation
|
|
352
|
+
The documentation can be generated using sphinx
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
pip install sphinx
|
|
356
|
+
cd docs
|
|
357
|
+
make html
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## Unit tests
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
pytest --cov-report term --cov=serc tests/
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## License
|
|
367
|
+
|
|
368
|
+
This project is licensed under the Apache 2.0 License. See the LICENSE file for more details.
|