digitalhub 0.11.0b1__py3-none-any.whl → 0.11.0b3__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 digitalhub might be problematic. Click here for more details.
- digitalhub/stores/client/dhcore/configurator.py +60 -10
- digitalhub/stores/configurator/ini_module.py +3 -3
- digitalhub/stores/data/s3/configurator.py +0 -3
- digitalhub/stores/data/s3/utils.py +13 -18
- digitalhub/stores/data/sql/configurator.py +0 -3
- digitalhub/stores/data/utils.py +1 -1
- {digitalhub-0.11.0b1.dist-info → digitalhub-0.11.0b3.dist-info}/METADATA +1 -1
- {digitalhub-0.11.0b1.dist-info → digitalhub-0.11.0b3.dist-info}/RECORD +10 -12
- digitalhub/stores/data/s3/models.py +0 -21
- digitalhub/stores/data/sql/models.py +0 -24
- {digitalhub-0.11.0b1.dist-info → digitalhub-0.11.0b3.dist-info}/WHEEL +0 -0
- {digitalhub-0.11.0b1.dist-info → digitalhub-0.11.0b3.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -22,8 +22,8 @@ AUTH_KEY = "_auth"
|
|
|
22
22
|
|
|
23
23
|
# API levels that are supported
|
|
24
24
|
MAX_API_LEVEL = 20
|
|
25
|
-
MIN_API_LEVEL =
|
|
26
|
-
LIB_VERSION =
|
|
25
|
+
MIN_API_LEVEL = 11
|
|
26
|
+
LIB_VERSION = 11
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
class ClientDHCoreConfigurator:
|
|
@@ -159,10 +159,10 @@ class ClientDHCoreConfigurator:
|
|
|
159
159
|
None
|
|
160
160
|
"""
|
|
161
161
|
# Give priority to access token
|
|
162
|
-
access_token =
|
|
162
|
+
access_token = self._load_dhcore_oauth_vars(DhcoreEnvVar.ACCESS_TOKEN.value)
|
|
163
163
|
if access_token is not None:
|
|
164
164
|
configurator.set_credential(AUTH_KEY, AuthType.OAUTH2.value)
|
|
165
|
-
configurator.set_credential(DhcoreEnvVar.ACCESS_TOKEN.value, access_token)
|
|
165
|
+
configurator.set_credential(DhcoreEnvVar.ACCESS_TOKEN.value.removeprefix("DHCORE_"), access_token)
|
|
166
166
|
|
|
167
167
|
# Fallback to basic
|
|
168
168
|
else:
|
|
@@ -223,7 +223,7 @@ class ClientDHCoreConfigurator:
|
|
|
223
223
|
elif self.oauth2_auth():
|
|
224
224
|
if "headers" not in kwargs:
|
|
225
225
|
kwargs["headers"] = {}
|
|
226
|
-
access_token = creds[DhcoreEnvVar.ACCESS_TOKEN.value]
|
|
226
|
+
access_token = creds[DhcoreEnvVar.ACCESS_TOKEN.value.removeprefix("DHCORE_")]
|
|
227
227
|
kwargs["headers"]["Authorization"] = f"Bearer {access_token}"
|
|
228
228
|
return kwargs
|
|
229
229
|
|
|
@@ -246,7 +246,7 @@ class ClientDHCoreConfigurator:
|
|
|
246
246
|
|
|
247
247
|
# Otherwise try token from file
|
|
248
248
|
if response.status_code in (400, 401, 403):
|
|
249
|
-
refresh_token = configurator.load_from_file(DhcoreEnvVar.REFRESH_TOKEN.value)
|
|
249
|
+
refresh_token = configurator.load_from_file(DhcoreEnvVar.REFRESH_TOKEN.value.removeprefix("DHCORE_"))
|
|
250
250
|
response = self._call_refresh_token_endpoint(url, refresh_token)
|
|
251
251
|
|
|
252
252
|
response.raise_for_status()
|
|
@@ -267,12 +267,42 @@ class ClientDHCoreConfigurator:
|
|
|
267
267
|
-------
|
|
268
268
|
None
|
|
269
269
|
"""
|
|
270
|
-
keys =
|
|
270
|
+
keys = [
|
|
271
|
+
*self._remove_prefix_dhcore(list_enum(DhcoreEnvVar)),
|
|
272
|
+
*list_enum(S3StoreEnv),
|
|
273
|
+
*list_enum(SqlStoreEnv),
|
|
274
|
+
]
|
|
271
275
|
for key in keys:
|
|
272
|
-
if (value := response.get(key.lower()
|
|
276
|
+
if (value := response.get(key.lower())) is not None:
|
|
273
277
|
configurator.set_credential(key, value)
|
|
274
278
|
configurator.write_env(keys)
|
|
275
279
|
|
|
280
|
+
def _remove_prefix_dhcore(self, keys: list[str]) -> list[str]:
|
|
281
|
+
"""
|
|
282
|
+
Remove prefix from selected keys. (Compatibility with CLI)
|
|
283
|
+
|
|
284
|
+
Parameters
|
|
285
|
+
----------
|
|
286
|
+
keys : list[str]
|
|
287
|
+
List of keys.
|
|
288
|
+
|
|
289
|
+
Returns
|
|
290
|
+
-------
|
|
291
|
+
list[str]
|
|
292
|
+
List of keys without prefix.
|
|
293
|
+
"""
|
|
294
|
+
new_list = []
|
|
295
|
+
for key in keys:
|
|
296
|
+
if key in (DhcoreEnvVar.REFRESH_TOKEN.value,
|
|
297
|
+
DhcoreEnvVar.ACCESS_TOKEN.value,
|
|
298
|
+
DhcoreEnvVar.ISSUER.value,
|
|
299
|
+
#DhcoreEnvVar.CLIENT_ID.value,
|
|
300
|
+
):
|
|
301
|
+
new_list.append(key.removeprefix("DHCORE_"))
|
|
302
|
+
else:
|
|
303
|
+
new_list.append(key)
|
|
304
|
+
return new_list
|
|
305
|
+
|
|
276
306
|
def _get_refresh_endpoint(self) -> str:
|
|
277
307
|
"""
|
|
278
308
|
Get the refresh endpoint.
|
|
@@ -283,11 +313,11 @@ class ClientDHCoreConfigurator:
|
|
|
283
313
|
Refresh endpoint.
|
|
284
314
|
"""
|
|
285
315
|
# Get issuer endpoint
|
|
286
|
-
endpoint_issuer =
|
|
316
|
+
endpoint_issuer = self._load_dhcore_oauth_vars(DhcoreEnvVar.ISSUER.value)
|
|
287
317
|
if endpoint_issuer is None:
|
|
288
318
|
raise ClientError("Issuer endpoint not set.")
|
|
289
319
|
endpoint_issuer = self._sanitize_endpoint(endpoint_issuer)
|
|
290
|
-
configurator.set_credential(DhcoreEnvVar.ISSUER.value, endpoint_issuer)
|
|
320
|
+
configurator.set_credential(DhcoreEnvVar.ISSUER.value.removeprefix("DHCORE_"), endpoint_issuer)
|
|
291
321
|
|
|
292
322
|
# Standard issuer endpoint path
|
|
293
323
|
url = endpoint_issuer + "/.well-known/openid-configuration"
|
|
@@ -315,6 +345,7 @@ class ClientDHCoreConfigurator:
|
|
|
315
345
|
"""
|
|
316
346
|
# Get client id
|
|
317
347
|
client_id = configurator.load_var(DhcoreEnvVar.CLIENT_ID.value)
|
|
348
|
+
#client_id = self._load_dhcore_oauth_vars(DhcoreEnvVar.CLIENT_ID.value)
|
|
318
349
|
if client_id is None:
|
|
319
350
|
raise ClientError("Client id not set.")
|
|
320
351
|
|
|
@@ -327,3 +358,22 @@ class ClientDHCoreConfigurator:
|
|
|
327
358
|
}
|
|
328
359
|
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
|
329
360
|
return request("POST", url, data=payload, headers=headers, timeout=60)
|
|
361
|
+
|
|
362
|
+
def _load_dhcore_oauth_vars(self, oauth_var: str) -> str | None:
|
|
363
|
+
"""
|
|
364
|
+
Load DHCore oauth variables.
|
|
365
|
+
|
|
366
|
+
Parameters
|
|
367
|
+
----------
|
|
368
|
+
oauth_var : str
|
|
369
|
+
The oauth variable to load.
|
|
370
|
+
|
|
371
|
+
Returns
|
|
372
|
+
-------
|
|
373
|
+
str
|
|
374
|
+
The oauth variable.
|
|
375
|
+
"""
|
|
376
|
+
read_var = configurator.load_from_env(oauth_var)
|
|
377
|
+
if read_var is None:
|
|
378
|
+
read_var = configurator.load_from_file(oauth_var.removeprefix("DHCORE_"))
|
|
379
|
+
return read_var
|
|
@@ -112,7 +112,7 @@ def set_current_env(environment: str) -> None:
|
|
|
112
112
|
raise ClientError(f"Failed to write env file: {e}")
|
|
113
113
|
|
|
114
114
|
|
|
115
|
-
def read_env_from_file() -> str:
|
|
115
|
+
def read_env_from_file() -> str | None:
|
|
116
116
|
"""
|
|
117
117
|
Read the current credentials set from the .dhcore.ini file.
|
|
118
118
|
|
|
@@ -124,5 +124,5 @@ def read_env_from_file() -> str:
|
|
|
124
124
|
try:
|
|
125
125
|
cfg = load_file()
|
|
126
126
|
return cfg["DEFAULT"]["current_environment"]
|
|
127
|
-
except Exception
|
|
128
|
-
|
|
127
|
+
except Exception:
|
|
128
|
+
return None
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
3
|
from pathlib import Path
|
|
5
4
|
from urllib.parse import urlparse
|
|
6
5
|
|
|
7
6
|
from boto3 import client as boto3_client
|
|
8
7
|
|
|
9
|
-
from digitalhub.stores.
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
from digitalhub.stores.configurator.enums import CredsOrigin
|
|
9
|
+
from digitalhub.stores.data.s3.configurator import S3StoreConfigurator
|
|
10
|
+
from digitalhub.utils.exceptions import StoreError
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
def get_bucket_name(path: str) -> str:
|
|
@@ -63,17 +62,13 @@ def get_s3_source(bucket: str, key: str, filename: Path) -> None:
|
|
|
63
62
|
-------
|
|
64
63
|
None
|
|
65
64
|
"""
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
str
|
|
77
|
-
The S3 bucket name.
|
|
78
|
-
"""
|
|
79
|
-
return os.getenv(S3StoreEnv.BUCKET_NAME.value, DEFAULT_BUCKET)
|
|
65
|
+
# Try to get client from environment variables
|
|
66
|
+
try:
|
|
67
|
+
cfg = S3StoreConfigurator().get_boto3_client_config(CredsOrigin.ENV.value)
|
|
68
|
+
s3 = boto3_client("s3", **cfg)
|
|
69
|
+
s3.download_file(bucket, key, filename)
|
|
70
|
+
|
|
71
|
+
# Fallback to file
|
|
72
|
+
except StoreError:
|
|
73
|
+
cfg = S3StoreConfigurator().get_boto3_client_config(CredsOrigin.FILE.value)
|
|
74
|
+
s3.download_file(bucket, key, filename)
|
digitalhub/stores/data/utils.py
CHANGED
|
@@ -20,7 +20,7 @@ def get_default_store(project: str) -> str:
|
|
|
20
20
|
Default store URI.
|
|
21
21
|
"""
|
|
22
22
|
context = get_context(project)
|
|
23
|
-
store = context.config.get(
|
|
23
|
+
store = context.config.get(StoreEnv.DEFAULT_FILES_STORE.value.lower())
|
|
24
24
|
if store is not None:
|
|
25
25
|
return store
|
|
26
26
|
store = configurator.load_var(StoreEnv.DEFAULT_FILES_STORE.value)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: digitalhub
|
|
3
|
-
Version: 0.11.
|
|
3
|
+
Version: 0.11.0b3
|
|
4
4
|
Summary: Python SDK for Digitalhub
|
|
5
5
|
Project-URL: Homepage, https://github.com/scc-digitalhub/digitalhub-sdk
|
|
6
6
|
Author-email: Fondazione Bruno Kessler <dslab@fbk.eu>, Matteo Martini <mmartini@fbk.eu>
|
|
@@ -190,7 +190,7 @@ digitalhub/stores/client/_base/params_builder.py,sha256=lCk4WE6DqvGP7-cx0anZEC8G
|
|
|
190
190
|
digitalhub/stores/client/dhcore/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
191
191
|
digitalhub/stores/client/dhcore/api_builder.py,sha256=J1kOMw4B4_PZKkEs7GPNcEkd1w-ZyJeB9G1UBZiMbl0,3975
|
|
192
192
|
digitalhub/stores/client/dhcore/client.py,sha256=SdwtCZ3HsQIxzYGUI3BPbwDEeRbcdpMliQNMWMEV4MA,9890
|
|
193
|
-
digitalhub/stores/client/dhcore/configurator.py,sha256=
|
|
193
|
+
digitalhub/stores/client/dhcore/configurator.py,sha256=_U4AjS7KKEixOjaRnSfIOIbHVWa00d8BXBwBjh9ptE4,11286
|
|
194
194
|
digitalhub/stores/client/dhcore/enums.py,sha256=kaVXZTTa2WmsFbcc1CKWNLOM0JtUtcjL-KpspnTOhEE,523
|
|
195
195
|
digitalhub/stores/client/dhcore/error_parser.py,sha256=GJUUkhp12cvC_LBIrC0teh4msmyb5WFxY2g4WNOkUwM,3305
|
|
196
196
|
digitalhub/stores/client/dhcore/key_builder.py,sha256=YuSS5tRNRJTYlH14buetFSCU_bLuBBKLqMFO3MQ6r4g,1324
|
|
@@ -208,12 +208,12 @@ digitalhub/stores/configurator/api.py,sha256=-dRdkXh99SztWaeRfqztVXhT8f95aVBjDK7
|
|
|
208
208
|
digitalhub/stores/configurator/configurator.py,sha256=z9RaQ_xKm_d1S3GdrSqfbV3ikEfHg6XogQMWDL7xc84,4762
|
|
209
209
|
digitalhub/stores/configurator/credentials_store.py,sha256=kiaCm37Sl1SN9OaMbsfZA1l1a9Xg6R6a00H7Upcf8Vg,1508
|
|
210
210
|
digitalhub/stores/configurator/enums.py,sha256=3Sf6UbYWYiJK4LaDzfgS2ay8Jxh-jIzR_3WRLt6m9do,288
|
|
211
|
-
digitalhub/stores/configurator/ini_module.py,sha256=
|
|
211
|
+
digitalhub/stores/configurator/ini_module.py,sha256=VfBPFo-EVrFokDk2j9CtzstlKuxTXtsG1ro-nfTPSfs,2923
|
|
212
212
|
digitalhub/stores/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
213
213
|
digitalhub/stores/data/api.py,sha256=R-yBTWpLDrFfcFAju0PJVl0_CDROM8lV2QHKtIMwGrI,543
|
|
214
214
|
digitalhub/stores/data/builder.py,sha256=fh1JFFos7TpfgWlEWL9WmIEdrpt4t1dQU2Ivq8qE4QE,2291
|
|
215
215
|
digitalhub/stores/data/enums.py,sha256=dqDRDnLVK55jiWyg_L-aeTwu3JBo4EcN5epxzdS_ARs,190
|
|
216
|
-
digitalhub/stores/data/utils.py,sha256=
|
|
216
|
+
digitalhub/stores/data/utils.py,sha256=Fy-OSy9m2LdbN4EF0J_cyhJS7SikzICEdyJv5HwPcI8,933
|
|
217
217
|
digitalhub/stores/data/_base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
218
218
|
digitalhub/stores/data/_base/store.py,sha256=VC1r7b9EIoObuG2DiqtFk2DQDSOgaS9jYL_UmiOTMHg,5241
|
|
219
219
|
digitalhub/stores/data/local/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -221,15 +221,13 @@ digitalhub/stores/data/local/store.py,sha256=lzagCi_3-bvH5IaMNMNnGGT2mNE-KG_F-CM
|
|
|
221
221
|
digitalhub/stores/data/remote/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
222
222
|
digitalhub/stores/data/remote/store.py,sha256=9KCFk8Fz1Mr7AK8gEITMh2sMw_jQldNPaVpk5_Oko9w,6098
|
|
223
223
|
digitalhub/stores/data/s3/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
224
|
-
digitalhub/stores/data/s3/configurator.py,sha256=
|
|
224
|
+
digitalhub/stores/data/s3/configurator.py,sha256=QowR285g3FBY6IktTLq0e8Y3XJdXL_eutzfM2mumLY8,3648
|
|
225
225
|
digitalhub/stores/data/s3/enums.py,sha256=tmSavz83jr6SBW-Gqn4D21TJpFytxvbtbW63htmZG2A,392
|
|
226
|
-
digitalhub/stores/data/s3/models.py,sha256=qeXeL7iP76EBO35wzP6bYeMj-sBOY634Tjwx8h3Di2g,371
|
|
227
226
|
digitalhub/stores/data/s3/store.py,sha256=BXyMdDjF_bj2TqAx5RSXrzWKIGE7PMObFSqEp1n-ZPo,19664
|
|
228
|
-
digitalhub/stores/data/s3/utils.py,sha256=
|
|
227
|
+
digitalhub/stores/data/s3/utils.py,sha256=vkgYL9auoyvPtWay50biIfSJ1T4gZT4CmpJdq83L4t8,1650
|
|
229
228
|
digitalhub/stores/data/sql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
230
|
-
digitalhub/stores/data/sql/configurator.py,sha256=
|
|
229
|
+
digitalhub/stores/data/sql/configurator.py,sha256=VCGukcuVpHDWHdL-hv4aPzyOXlhk-4tkjgIcfEIPXDM,3230
|
|
231
230
|
digitalhub/stores/data/sql/enums.py,sha256=FCpmIXxef6SQIX_564a1hYvaSVrpvld8gi7YAv25H-o,284
|
|
232
|
-
digitalhub/stores/data/sql/models.py,sha256=_itIXoCfRLzUpG0OaM44qbv2u87Lyl5e0tmAXNTvfjQ,349
|
|
233
231
|
digitalhub/stores/data/sql/store.py,sha256=FnT4C1n7M3DM1i6LccGcEBq9_YNLtVhm__6_L2eQgvI,11701
|
|
234
232
|
digitalhub/stores/readers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
235
233
|
digitalhub/stores/readers/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -252,7 +250,7 @@ digitalhub/utils/io_utils.py,sha256=8jD4Rp_b7LZEpY5JSMxVUowZsnifKnbGpHT5Hijx9-g,
|
|
|
252
250
|
digitalhub/utils/logger.py,sha256=ml3ne6D8wuRdNZ4F6ywmvWotSxjmZWnmKgNiuHb4R5M,437
|
|
253
251
|
digitalhub/utils/types.py,sha256=x8zXsbivD8vdaNeNRZLKOPvGbz6d-59nncuvO0FsueY,109
|
|
254
252
|
digitalhub/utils/uri_utils.py,sha256=wVkA2OcfHG5EcQOr9YxLJzo--VV6sjFjgXDNx-gP94I,4021
|
|
255
|
-
digitalhub-0.11.
|
|
256
|
-
digitalhub-0.11.
|
|
257
|
-
digitalhub-0.11.
|
|
258
|
-
digitalhub-0.11.
|
|
253
|
+
digitalhub-0.11.0b3.dist-info/METADATA,sha256=aaqK7yjXNErABxVJh3OMUYtufydkfo0JMljz4MYcp2E,15037
|
|
254
|
+
digitalhub-0.11.0b3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
255
|
+
digitalhub-0.11.0b3.dist-info/licenses/LICENSE.txt,sha256=qmrTTXPlgU0kSRlRVbjhlyGs1IXs2QPxo_Y-Mn06J0k,11589
|
|
256
|
+
digitalhub-0.11.0b3.dist-info/RECORD,,
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from pydantic import BaseModel
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class S3StoreConfig(BaseModel):
|
|
7
|
-
"""
|
|
8
|
-
S3 store configuration class.
|
|
9
|
-
"""
|
|
10
|
-
|
|
11
|
-
endpoint_url: str
|
|
12
|
-
"""S3 endpoint URL."""
|
|
13
|
-
|
|
14
|
-
aws_access_key_id: str
|
|
15
|
-
"""AWS access key ID."""
|
|
16
|
-
|
|
17
|
-
aws_secret_access_key: str
|
|
18
|
-
"""AWS secret access key."""
|
|
19
|
-
|
|
20
|
-
bucket_name: str
|
|
21
|
-
"""S3 bucket name."""
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from pydantic import BaseModel
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class SqlStoreConfig(BaseModel):
|
|
7
|
-
"""
|
|
8
|
-
SQL store configuration class.
|
|
9
|
-
"""
|
|
10
|
-
|
|
11
|
-
host: str
|
|
12
|
-
"""SQL host."""
|
|
13
|
-
|
|
14
|
-
port: int
|
|
15
|
-
"""SQL port."""
|
|
16
|
-
|
|
17
|
-
user: str
|
|
18
|
-
"""SQL user."""
|
|
19
|
-
|
|
20
|
-
password: str
|
|
21
|
-
"""SQL password."""
|
|
22
|
-
|
|
23
|
-
database: str
|
|
24
|
-
"""SQL database name."""
|
|
File without changes
|
|
File without changes
|