terrakio-core 0.3.4__py3-none-any.whl → 0.3.7__py3-none-any.whl
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.
Potentially problematic release.
This version of terrakio-core might be problematic. Click here for more details.
- terrakio_core/__init__.py +10 -1
- terrakio_core/async_client.py +304 -0
- terrakio_core/client.py +22 -1713
- terrakio_core/config.py +8 -15
- terrakio_core/convenience_functions/convenience_functions.py +296 -0
- terrakio_core/endpoints/auth.py +180 -0
- terrakio_core/endpoints/dataset_management.py +371 -0
- terrakio_core/endpoints/group_management.py +228 -0
- terrakio_core/endpoints/mass_stats.py +594 -0
- terrakio_core/endpoints/model_management.py +790 -0
- terrakio_core/endpoints/space_management.py +72 -0
- terrakio_core/endpoints/user_management.py +131 -0
- terrakio_core/exceptions.py +4 -2
- terrakio_core/helper/bounded_taskgroup.py +20 -0
- terrakio_core/helper/decorators.py +58 -0
- terrakio_core/{generation → helper}/tiles.py +1 -12
- terrakio_core/sync_client.py +370 -0
- {terrakio_core-0.3.4.dist-info → terrakio_core-0.3.7.dist-info}/METADATA +7 -1
- terrakio_core-0.3.7.dist-info/RECORD +21 -0
- terrakio_core/auth.py +0 -223
- terrakio_core/dataset_management.py +0 -287
- terrakio_core/decorators.py +0 -18
- terrakio_core/group_access_management.py +0 -232
- terrakio_core/mass_stats.py +0 -504
- terrakio_core/space_management.py +0 -101
- terrakio_core/user_management.py +0 -227
- terrakio_core-0.3.4.dist-info/RECORD +0 -16
- {terrakio_core-0.3.4.dist-info → terrakio_core-0.3.7.dist-info}/WHEEL +0 -0
- {terrakio_core-0.3.4.dist-info → terrakio_core-0.3.7.dist-info}/top_level.txt +0 -0
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
from typing import Dict, Any, List, Optional
|
|
3
|
-
from .exceptions import APIError
|
|
4
|
-
|
|
5
|
-
class DatasetManagement:
|
|
6
|
-
def __init__(self, api_url: str, api_key: str, verify: bool = True, timeout: int = 60):
|
|
7
|
-
"""
|
|
8
|
-
Initialize the Dataset Management client.
|
|
9
|
-
|
|
10
|
-
Args:
|
|
11
|
-
api_url: API base URL
|
|
12
|
-
api_key: API key for authentication
|
|
13
|
-
verify: Verify SSL certificates
|
|
14
|
-
timeout: Request timeout in seconds
|
|
15
|
-
"""
|
|
16
|
-
self.api_url = api_url.rstrip('/')
|
|
17
|
-
self.api_key = api_key
|
|
18
|
-
self.verify = verify
|
|
19
|
-
self.timeout = timeout
|
|
20
|
-
self.session = requests.Session()
|
|
21
|
-
self.session.headers.update({
|
|
22
|
-
'x-api-key': self.api_key,
|
|
23
|
-
'Content-Type': 'application/json'
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
def get_dataset(self, name: str, collection: str = "terrakio-datasets") -> Dict[str, Any]:
|
|
27
|
-
"""
|
|
28
|
-
Retrieve dataset info by dataset name.
|
|
29
|
-
|
|
30
|
-
Args:
|
|
31
|
-
name: The name of the dataset (required)
|
|
32
|
-
collection: The dataset collection (default: 'terrakio-datasets')
|
|
33
|
-
|
|
34
|
-
Returns:
|
|
35
|
-
Dataset information as a dictionary
|
|
36
|
-
|
|
37
|
-
Raises:
|
|
38
|
-
APIError: If the API request fails
|
|
39
|
-
"""
|
|
40
|
-
endpoint = f"{self.api_url}/datasets/{name}"
|
|
41
|
-
params = {"collection": collection} if collection else {}
|
|
42
|
-
try:
|
|
43
|
-
response = self.session.get(
|
|
44
|
-
endpoint,
|
|
45
|
-
params=params,
|
|
46
|
-
timeout=self.timeout,
|
|
47
|
-
verify=self.verify
|
|
48
|
-
)
|
|
49
|
-
if not response.ok:
|
|
50
|
-
raise APIError(f"API request failed: {response.status_code} {response.reason}")
|
|
51
|
-
return response.json()
|
|
52
|
-
except requests.RequestException as e:
|
|
53
|
-
raise APIError(f"Request failed: {str(e)}")
|
|
54
|
-
|
|
55
|
-
def list_datasets(self, substring: Optional[str] = None, collection: str = "terrakio-datasets") -> List[Dict[str, Any]]:
|
|
56
|
-
"""
|
|
57
|
-
List datasets, optionally filtering by a substring and collection.
|
|
58
|
-
|
|
59
|
-
Args:
|
|
60
|
-
substring: Substring to filter by (optional)
|
|
61
|
-
collection: Dataset collection (default: 'terrakio-datasets')
|
|
62
|
-
|
|
63
|
-
Returns:
|
|
64
|
-
List of datasets matching the criteria
|
|
65
|
-
|
|
66
|
-
Raises:
|
|
67
|
-
APIError: If the API request fails
|
|
68
|
-
"""
|
|
69
|
-
endpoint = f"{self.api_url}/datasets"
|
|
70
|
-
params = {"collection": collection}
|
|
71
|
-
if substring:
|
|
72
|
-
params["substring"] = substring
|
|
73
|
-
try:
|
|
74
|
-
response = self.session.get(
|
|
75
|
-
endpoint,
|
|
76
|
-
params=params,
|
|
77
|
-
timeout=self.timeout,
|
|
78
|
-
verify=self.verify
|
|
79
|
-
)
|
|
80
|
-
if not response.ok:
|
|
81
|
-
raise APIError(f"API request failed: {response.status_code} {response.reason}")
|
|
82
|
-
return response.json()
|
|
83
|
-
except requests.RequestException as e:
|
|
84
|
-
raise APIError(f"Request failed: {str(e)}")
|
|
85
|
-
|
|
86
|
-
# def create_dataset(self, name: str, collection: str = "terrakio-datasets", **kwargs) -> Dict[str, Any]:
|
|
87
|
-
# """
|
|
88
|
-
# Create a new dataset.
|
|
89
|
-
|
|
90
|
-
# Args:
|
|
91
|
-
# name: Name of the dataset (required)
|
|
92
|
-
# collection: Dataset collection (default: 'terrakio-datasets')
|
|
93
|
-
# **kwargs: Additional dataset parameters including:
|
|
94
|
-
# - products: List of products
|
|
95
|
-
# - dates_iso8601: List of dates
|
|
96
|
-
# - bucket: Storage bucket
|
|
97
|
-
# - path: Storage path
|
|
98
|
-
# - data_type: Data type
|
|
99
|
-
# - no_data: No data value
|
|
100
|
-
# - l_max: Maximum level
|
|
101
|
-
# - y_size: Y size
|
|
102
|
-
# - x_size: X size
|
|
103
|
-
# - proj4: Projection string
|
|
104
|
-
# - abstract: Dataset abstract
|
|
105
|
-
# - geotransform: Geotransform parameters
|
|
106
|
-
|
|
107
|
-
# Returns:
|
|
108
|
-
# Created dataset information
|
|
109
|
-
|
|
110
|
-
# Raises:
|
|
111
|
-
# APIError: If the API request fails
|
|
112
|
-
# """
|
|
113
|
-
# endpoint = f"{self.api_url}/datasets"
|
|
114
|
-
# params = {"collection": collection}
|
|
115
|
-
# # Create payload with required name parameter
|
|
116
|
-
# payload = {"name": name}
|
|
117
|
-
|
|
118
|
-
# # Add optional parameters if provided
|
|
119
|
-
# for param in ["products", "dates_iso8601", "bucket", "path", "data_type",
|
|
120
|
-
# "no_data", "l_max", "y_size", "x_size", "proj4", "abstract", "geotransform", "input"]:
|
|
121
|
-
# if param in kwargs:
|
|
122
|
-
# payload[param] = kwargs[param]
|
|
123
|
-
|
|
124
|
-
# try:
|
|
125
|
-
# response = self.session.post(
|
|
126
|
-
# endpoint,
|
|
127
|
-
# params=params,
|
|
128
|
-
# json=payload,
|
|
129
|
-
# timeout=self.timeout,
|
|
130
|
-
# verify=self.verify
|
|
131
|
-
# )
|
|
132
|
-
|
|
133
|
-
# if not response.ok:
|
|
134
|
-
# raise APIError(f"API request failed: {response.status_code} {response.reason}")
|
|
135
|
-
# return response.json()
|
|
136
|
-
# except requests.RequestException as e:
|
|
137
|
-
# raise APIError(f"Request failed: {str(e)}")
|
|
138
|
-
|
|
139
|
-
def create_dataset(self, name: str, collection: str = "terrakio-datasets", **kwargs) -> Dict[str, Any]:
|
|
140
|
-
"""
|
|
141
|
-
Create a new dataset.
|
|
142
|
-
|
|
143
|
-
Args:
|
|
144
|
-
name: Name of the dataset (required)
|
|
145
|
-
collection: Dataset collection (default: 'terrakio-datasets')
|
|
146
|
-
**kwargs: Additional dataset parameters including:
|
|
147
|
-
- products: List of products
|
|
148
|
-
- dates_iso8601: List of dates
|
|
149
|
-
- bucket: Storage bucket
|
|
150
|
-
- path: Storage path
|
|
151
|
-
- data_type: Data type
|
|
152
|
-
- no_data: No data value
|
|
153
|
-
- l_max: Maximum level
|
|
154
|
-
- y_size: Y size
|
|
155
|
-
- x_size: X size
|
|
156
|
-
- proj4: Projection string
|
|
157
|
-
- abstract: Dataset abstract
|
|
158
|
-
- geotransform: Geotransform parameters
|
|
159
|
-
- padding: Padding value
|
|
160
|
-
|
|
161
|
-
Returns:
|
|
162
|
-
Created dataset information
|
|
163
|
-
|
|
164
|
-
Raises:
|
|
165
|
-
APIError: If the API request fails
|
|
166
|
-
"""
|
|
167
|
-
endpoint = f"{self.api_url}/datasets"
|
|
168
|
-
params = {"collection": collection}
|
|
169
|
-
payload = {"name": name}
|
|
170
|
-
|
|
171
|
-
for param in ["products", "dates_iso8601", "bucket", "path", "data_type",
|
|
172
|
-
"no_data", "l_max", "y_size", "x_size", "proj4", "abstract", "geotransform", "input", "padding"]:
|
|
173
|
-
if param in kwargs:
|
|
174
|
-
payload[param] = kwargs[param]
|
|
175
|
-
|
|
176
|
-
try:
|
|
177
|
-
response = self.session.post(
|
|
178
|
-
endpoint,
|
|
179
|
-
params=params,
|
|
180
|
-
json=payload,
|
|
181
|
-
timeout=self.timeout,
|
|
182
|
-
verify=self.verify
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
if not response.ok:
|
|
186
|
-
raise APIError(f"API request failed: {response.status_code} {response.reason}")
|
|
187
|
-
return response.json()
|
|
188
|
-
except requests.RequestException as e:
|
|
189
|
-
raise APIError(f"Request failed: {str(e)}")
|
|
190
|
-
|
|
191
|
-
def update_dataset(self, name: str, append: bool = True, collection: str = "terrakio-datasets", **kwargs) -> Dict[str, Any]:
|
|
192
|
-
"""
|
|
193
|
-
Update a dataset. By default, values are appended unless append is set to False.
|
|
194
|
-
|
|
195
|
-
Args:
|
|
196
|
-
name: Name of the dataset (required)
|
|
197
|
-
append: Whether to append values (default: True)
|
|
198
|
-
collection: Dataset collection (default: 'terrakio-datasets')
|
|
199
|
-
**kwargs: Additional dataset parameters to update
|
|
200
|
-
|
|
201
|
-
Returns:
|
|
202
|
-
Updated dataset information
|
|
203
|
-
|
|
204
|
-
Raises:
|
|
205
|
-
APIError: If the API request fails
|
|
206
|
-
"""
|
|
207
|
-
endpoint = f"{self.api_url}/datasets"
|
|
208
|
-
params = {"append": str(append).lower(), "collection": collection}
|
|
209
|
-
payload = {"name": name}
|
|
210
|
-
payload.update(kwargs)
|
|
211
|
-
try:
|
|
212
|
-
response = self.session.patch(
|
|
213
|
-
endpoint,
|
|
214
|
-
params=params,
|
|
215
|
-
json=payload,
|
|
216
|
-
timeout=self.timeout,
|
|
217
|
-
verify=self.verify
|
|
218
|
-
)
|
|
219
|
-
if not response.ok:
|
|
220
|
-
raise APIError(f"API request failed: {response.status_code} {response.reason}")
|
|
221
|
-
return response.json()
|
|
222
|
-
except requests.RequestException as e:
|
|
223
|
-
raise APIError(f"Request failed: {str(e)}")
|
|
224
|
-
|
|
225
|
-
def overwrite_dataset(self, name: str, collection: str = "terrakio-datasets", **kwargs) -> Dict[str, Any]:
|
|
226
|
-
"""
|
|
227
|
-
Overwrite a dataset (replace all values).
|
|
228
|
-
|
|
229
|
-
Args:
|
|
230
|
-
name: Name of the dataset (required)
|
|
231
|
-
collection: Dataset collection (default: 'terrakio-datasets')
|
|
232
|
-
**kwargs: New dataset parameters
|
|
233
|
-
|
|
234
|
-
Returns:
|
|
235
|
-
Updated dataset information
|
|
236
|
-
|
|
237
|
-
Raises:
|
|
238
|
-
APIError: If the API request fails
|
|
239
|
-
"""
|
|
240
|
-
endpoint = f"{self.api_url}/datasets"
|
|
241
|
-
params = {"collection": collection}
|
|
242
|
-
payload = {"name": name}
|
|
243
|
-
payload.update(kwargs)
|
|
244
|
-
try:
|
|
245
|
-
response = self.session.put(
|
|
246
|
-
endpoint,
|
|
247
|
-
params=params,
|
|
248
|
-
json=payload,
|
|
249
|
-
timeout=self.timeout,
|
|
250
|
-
verify=self.verify
|
|
251
|
-
)
|
|
252
|
-
if not response.ok:
|
|
253
|
-
raise APIError(f"API request failed: {response.status_code} {response.reason}")
|
|
254
|
-
return response.json()
|
|
255
|
-
except requests.RequestException as e:
|
|
256
|
-
raise APIError(f"Request failed: {str(e)}")
|
|
257
|
-
|
|
258
|
-
def delete_dataset(self, name: str, collection: str = "terrakio-datasets") -> Dict[str, Any]:
|
|
259
|
-
"""
|
|
260
|
-
Delete a dataset by name.
|
|
261
|
-
|
|
262
|
-
Args:
|
|
263
|
-
name: The name of the dataset (required)
|
|
264
|
-
collection: Dataset collection (default: 'terrakio-datasets')
|
|
265
|
-
|
|
266
|
-
Returns:
|
|
267
|
-
API response as a dictionary
|
|
268
|
-
|
|
269
|
-
Raises:
|
|
270
|
-
APIError: If the API request fails
|
|
271
|
-
"""
|
|
272
|
-
endpoint = f"{self.api_url}/datasets/{name}"
|
|
273
|
-
params = {"collection": collection}
|
|
274
|
-
try:
|
|
275
|
-
response = self.session.delete(
|
|
276
|
-
endpoint,
|
|
277
|
-
params=params,
|
|
278
|
-
timeout=self.timeout,
|
|
279
|
-
verify=self.verify
|
|
280
|
-
)
|
|
281
|
-
if response.status_code == 404:
|
|
282
|
-
return {"status": "error", "message": f"Dataset '{name}' does not exist in collection '{collection}'"}
|
|
283
|
-
if not response.ok:
|
|
284
|
-
raise APIError(f"API request failed: {response.status_code} {response.reason}")
|
|
285
|
-
return response.json()
|
|
286
|
-
except requests.RequestException as e:
|
|
287
|
-
raise APIError(f"Request failed: {str(e)}")
|
terrakio_core/decorators.py
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# terrakio_core/decorators.py
|
|
2
|
-
def admin_only_params(*restricted_params):
|
|
3
|
-
"""
|
|
4
|
-
Decorator factory for restricting method parameters to admin users only.
|
|
5
|
-
"""
|
|
6
|
-
def decorator(func):
|
|
7
|
-
def wrapper(self, *args, **kwargs):
|
|
8
|
-
if hasattr(self, '_is_admin') and self._is_admin:
|
|
9
|
-
return func(self, *args, **kwargs)
|
|
10
|
-
|
|
11
|
-
admin_params_used = set(kwargs.keys()) & set(restricted_params)
|
|
12
|
-
if admin_params_used:
|
|
13
|
-
raise PermissionError(f"Parameters {admin_params_used} are only available to admin users")
|
|
14
|
-
|
|
15
|
-
filtered_kwargs = {k: v for k, v in kwargs.items() if k not in restricted_params}
|
|
16
|
-
return func(self, *args, **filtered_kwargs)
|
|
17
|
-
return wrapper
|
|
18
|
-
return decorator
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
from typing import Dict, Any, List
|
|
3
|
-
from .exceptions import APIError
|
|
4
|
-
|
|
5
|
-
class GroupAccessManagement:
|
|
6
|
-
def __init__(self, api_url: str, api_key: str, verify: bool = True, timeout: int = 60):
|
|
7
|
-
"""
|
|
8
|
-
Initialize the Group Access Management client.
|
|
9
|
-
|
|
10
|
-
Args:
|
|
11
|
-
api_url: API base URL
|
|
12
|
-
api_key: API key for authentication
|
|
13
|
-
verify: Verify SSL certificates
|
|
14
|
-
timeout: Request timeout in seconds
|
|
15
|
-
"""
|
|
16
|
-
self.api_url = api_url.rstrip('/')
|
|
17
|
-
self.api_key = api_key
|
|
18
|
-
self.verify = verify
|
|
19
|
-
self.timeout = timeout
|
|
20
|
-
self.session = requests.Session()
|
|
21
|
-
self.session.headers.update({
|
|
22
|
-
'x-api-key': self.api_key,
|
|
23
|
-
'Content-Type': 'application/json'
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
def get_group_users_and_datasets(self, group_name: str) -> Dict[str, Any]:
|
|
27
|
-
"""
|
|
28
|
-
Get users and datasets of a group.
|
|
29
|
-
|
|
30
|
-
Args:
|
|
31
|
-
group_name: Name of the group
|
|
32
|
-
|
|
33
|
-
Returns:
|
|
34
|
-
Dictionary containing lists of users and datasets associated with the group
|
|
35
|
-
{
|
|
36
|
-
"users": [UID, ...],
|
|
37
|
-
"datasets": [DATASET_NAME, ...]
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
Raises:
|
|
41
|
-
APIError: If the API request fails
|
|
42
|
-
"""
|
|
43
|
-
endpoint = f"https://dev-au.terrak.io/groups/{group_name}"
|
|
44
|
-
print("the endpoint is ", endpoint)
|
|
45
|
-
print
|
|
46
|
-
try:
|
|
47
|
-
response = self.session.get(
|
|
48
|
-
endpoint,
|
|
49
|
-
timeout=self.timeout,
|
|
50
|
-
verify=self.verify
|
|
51
|
-
)
|
|
52
|
-
print("the response is ", response.text)
|
|
53
|
-
if not response.ok:
|
|
54
|
-
error_msg = f"API request failed: {response.status_code} {response.reason}"
|
|
55
|
-
try:
|
|
56
|
-
error_data = response.json()
|
|
57
|
-
if "detail" in error_data:
|
|
58
|
-
error_msg += f" - {error_data['detail']}"
|
|
59
|
-
except:
|
|
60
|
-
pass
|
|
61
|
-
raise APIError(error_msg)
|
|
62
|
-
|
|
63
|
-
return response.json()
|
|
64
|
-
|
|
65
|
-
except requests.RequestException as e:
|
|
66
|
-
raise APIError(f"Request failed: {str(e)}")
|
|
67
|
-
|
|
68
|
-
def add_group_to_dataset(self, dataset: str, group: str) -> Dict[str, Any]:
|
|
69
|
-
"""
|
|
70
|
-
Add a group to a dataset.
|
|
71
|
-
|
|
72
|
-
Args:
|
|
73
|
-
dataset: Name of the dataset
|
|
74
|
-
group: Name of the group to add to the dataset
|
|
75
|
-
|
|
76
|
-
Returns:
|
|
77
|
-
API response data
|
|
78
|
-
|
|
79
|
-
Raises:
|
|
80
|
-
APIError: If the API request fails
|
|
81
|
-
"""
|
|
82
|
-
endpoint = f"{self.api_url}/groups/dataset/{dataset}"
|
|
83
|
-
print("hello")
|
|
84
|
-
print("the endpoint is ", endpoint)
|
|
85
|
-
params = {"group": group}
|
|
86
|
-
print("the endpoint is ", endpoint)
|
|
87
|
-
print("!!!!!!!!!!!")
|
|
88
|
-
print("the params are ", params)
|
|
89
|
-
try:
|
|
90
|
-
response = self.session.post(
|
|
91
|
-
endpoint,
|
|
92
|
-
params=params,
|
|
93
|
-
timeout=self.timeout,
|
|
94
|
-
verify=self.verify
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
if not response.ok:
|
|
98
|
-
error_msg = f"API request failed: {response.status_code} {response.reason}"
|
|
99
|
-
try:
|
|
100
|
-
error_data = response.json()
|
|
101
|
-
if "detail" in error_data:
|
|
102
|
-
error_msg += f" - {error_data['detail']}"
|
|
103
|
-
except:
|
|
104
|
-
pass
|
|
105
|
-
raise APIError(error_msg)
|
|
106
|
-
|
|
107
|
-
return response.json()
|
|
108
|
-
|
|
109
|
-
except requests.RequestException as e:
|
|
110
|
-
raise APIError(f"Request failed: {str(e)}")
|
|
111
|
-
|
|
112
|
-
def add_group_to_user(self, uid: str, group: str) -> Dict[str, Any]:
|
|
113
|
-
"""
|
|
114
|
-
Add a group to a user.
|
|
115
|
-
|
|
116
|
-
Args:
|
|
117
|
-
uid: User UID
|
|
118
|
-
group: Name of the group to add to the user
|
|
119
|
-
|
|
120
|
-
Returns:
|
|
121
|
-
API response data
|
|
122
|
-
|
|
123
|
-
Raises:
|
|
124
|
-
APIError: If the API request fails
|
|
125
|
-
"""
|
|
126
|
-
endpoint = f"{self.api_url}/groups/users/{uid}"
|
|
127
|
-
params = {"group": group}
|
|
128
|
-
print("the endpoint is ", endpoint)
|
|
129
|
-
print("the params are ", params)
|
|
130
|
-
try:
|
|
131
|
-
response = self.session.post(
|
|
132
|
-
endpoint,
|
|
133
|
-
params=params,
|
|
134
|
-
timeout=self.timeout,
|
|
135
|
-
verify=self.verify
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
if not response.ok:
|
|
139
|
-
error_msg = f"API request failed: {response.status_code} {response.reason}"
|
|
140
|
-
try:
|
|
141
|
-
error_data = response.json()
|
|
142
|
-
if "detail" in error_data:
|
|
143
|
-
error_msg += f" - {error_data['detail']}"
|
|
144
|
-
except:
|
|
145
|
-
pass
|
|
146
|
-
raise APIError(error_msg)
|
|
147
|
-
|
|
148
|
-
return response.json()
|
|
149
|
-
|
|
150
|
-
except requests.RequestException as e:
|
|
151
|
-
raise APIError(f"Request failed: {str(e)}")
|
|
152
|
-
|
|
153
|
-
def delete_group_from_user(self, uid: str, group: str) -> Dict[str, Any]:
|
|
154
|
-
"""
|
|
155
|
-
Delete a group from a user.
|
|
156
|
-
|
|
157
|
-
Args:
|
|
158
|
-
uid: User UID
|
|
159
|
-
group: Name of the group to remove from the user
|
|
160
|
-
|
|
161
|
-
Returns:
|
|
162
|
-
API response data
|
|
163
|
-
|
|
164
|
-
Raises:
|
|
165
|
-
APIError: If the API request fails
|
|
166
|
-
"""
|
|
167
|
-
endpoint = f"{self.api_url}/groups/users/{uid}"
|
|
168
|
-
params = {"group": group}
|
|
169
|
-
|
|
170
|
-
try:
|
|
171
|
-
response = self.session.delete(
|
|
172
|
-
endpoint,
|
|
173
|
-
params=params,
|
|
174
|
-
timeout=self.timeout,
|
|
175
|
-
verify=self.verify
|
|
176
|
-
)
|
|
177
|
-
|
|
178
|
-
if not response.ok:
|
|
179
|
-
error_msg = f"API request failed: {response.status_code} {response.reason}"
|
|
180
|
-
try:
|
|
181
|
-
error_data = response.json()
|
|
182
|
-
if "detail" in error_data:
|
|
183
|
-
error_msg += f" - {error_data['detail']}"
|
|
184
|
-
except:
|
|
185
|
-
pass
|
|
186
|
-
raise APIError(error_msg)
|
|
187
|
-
|
|
188
|
-
return response.json()
|
|
189
|
-
|
|
190
|
-
except requests.RequestException as e:
|
|
191
|
-
raise APIError(f"Request failed: {str(e)}")
|
|
192
|
-
|
|
193
|
-
def delete_group_from_dataset(self, dataset: str, group: str) -> Dict[str, Any]:
|
|
194
|
-
"""
|
|
195
|
-
Delete a group from a dataset.
|
|
196
|
-
|
|
197
|
-
Args:
|
|
198
|
-
dataset: Name of the dataset
|
|
199
|
-
group: Name of the group to remove from the dataset
|
|
200
|
-
|
|
201
|
-
Returns:
|
|
202
|
-
API response data
|
|
203
|
-
|
|
204
|
-
Raises:
|
|
205
|
-
APIError: If the API request fails
|
|
206
|
-
"""
|
|
207
|
-
endpoint = f"{self.api_url}/groups/datasets/{dataset}"
|
|
208
|
-
params = {"group": group}
|
|
209
|
-
|
|
210
|
-
try:
|
|
211
|
-
response = self.session.delete(
|
|
212
|
-
endpoint,
|
|
213
|
-
params=params,
|
|
214
|
-
timeout=self.timeout,
|
|
215
|
-
verify=self.verify
|
|
216
|
-
)
|
|
217
|
-
|
|
218
|
-
if not response.ok:
|
|
219
|
-
error_msg = f"API request failed: {response.status_code} {response.reason}"
|
|
220
|
-
try:
|
|
221
|
-
error_data = response.json()
|
|
222
|
-
if "detail" in error_data:
|
|
223
|
-
error_msg += f" - {error_data['detail']}"
|
|
224
|
-
except:
|
|
225
|
-
pass
|
|
226
|
-
raise APIError(error_msg)
|
|
227
|
-
|
|
228
|
-
return response.json()
|
|
229
|
-
|
|
230
|
-
except requests.RequestException as e:
|
|
231
|
-
raise APIError(f"Request failed: {str(e)}")
|
|
232
|
-
|