digitalhub 0.11.0b2__py3-none-any.whl → 0.11.0b4__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.

@@ -56,6 +56,7 @@ class State(Enum):
56
56
  STOPPED = "STOPPED"
57
57
  SUCCESS = "SUCCESS"
58
58
  UNKNOWN = "UNKNOWN"
59
+ UPLOADING = "UPLOADING"
59
60
 
60
61
 
61
62
  class ApiCategories(Enum):
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  import typing
4
4
  from typing import Any
5
5
 
6
- from digitalhub.entities._commons.enums import ApiCategories, BackendOperations, Relationship
6
+ from digitalhub.entities._commons.enums import ApiCategories, BackendOperations, Relationship, State
7
7
  from digitalhub.entities._processors.utils import (
8
8
  get_context_from_identifier,
9
9
  get_context_from_project,
@@ -120,7 +120,25 @@ class ContextEntityOperationsProcessor:
120
120
 
121
121
  new_obj: MaterialEntity = self._create_context_entity(context, obj.ENTITY_TYPE, obj.to_dict())
122
122
  new_obj = factory.build_entity_from_dict(new_obj)
123
- new_obj.upload(source)
123
+
124
+ new_obj.status.state = State.UPLOADING.value
125
+ new_obj = self._update_material_entity(new_obj)
126
+
127
+ # Handle file upload
128
+ try:
129
+ new_obj.upload(source)
130
+ uploaded = True
131
+ except Exception:
132
+ uploaded = False
133
+
134
+ # Update status after upload
135
+ if uploaded:
136
+ new_obj.status.state = State.READY.value
137
+ new_obj = self._update_material_entity(new_obj)
138
+ else:
139
+ new_obj.status.state = State.ERROR.value
140
+ new_obj = self._update_material_entity(new_obj)
141
+
124
142
  return new_obj
125
143
 
126
144
  def _read_context_entity(
@@ -554,6 +572,30 @@ class ContextEntityOperationsProcessor:
554
572
  objects.append(entity)
555
573
  return objects
556
574
 
575
+ def _update_material_entity(
576
+ self,
577
+ new_obj: MaterialEntity,
578
+ ) -> dict:
579
+ """
580
+ Update material object shortcut.
581
+
582
+ Parameters
583
+ ----------
584
+ new_obj : MaterialEntity
585
+ Object instance.
586
+
587
+ Returns
588
+ -------
589
+ dict
590
+ Response from backend.
591
+ """
592
+ return self.update_context_entity(
593
+ new_obj.project,
594
+ new_obj.ENTITY_TYPE,
595
+ new_obj.id,
596
+ new_obj.to_dict(),
597
+ )
598
+
557
599
  def _update_context_entity(
558
600
  self,
559
601
  context: Context,
@@ -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 = 10
26
- LIB_VERSION = 10
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 = configurator.load_var(DhcoreEnvVar.ACCESS_TOKEN.value)
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,43 @@ class ClientDHCoreConfigurator:
267
267
  -------
268
268
  None
269
269
  """
270
- keys = list_enum(DhcoreEnvVar) + list_enum(S3StoreEnv) + list_enum(SqlStoreEnv)
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().removeprefix("dhcore_"))) is not None:
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 (
297
+ DhcoreEnvVar.REFRESH_TOKEN.value,
298
+ DhcoreEnvVar.ACCESS_TOKEN.value,
299
+ DhcoreEnvVar.ISSUER.value,
300
+ # DhcoreEnvVar.CLIENT_ID.value,
301
+ ):
302
+ new_list.append(key.removeprefix("DHCORE_"))
303
+ else:
304
+ new_list.append(key)
305
+ return new_list
306
+
276
307
  def _get_refresh_endpoint(self) -> str:
277
308
  """
278
309
  Get the refresh endpoint.
@@ -283,11 +314,11 @@ class ClientDHCoreConfigurator:
283
314
  Refresh endpoint.
284
315
  """
285
316
  # Get issuer endpoint
286
- endpoint_issuer = configurator.load_var(DhcoreEnvVar.ISSUER.value)
317
+ endpoint_issuer = self._load_dhcore_oauth_vars(DhcoreEnvVar.ISSUER.value)
287
318
  if endpoint_issuer is None:
288
319
  raise ClientError("Issuer endpoint not set.")
289
320
  endpoint_issuer = self._sanitize_endpoint(endpoint_issuer)
290
- configurator.set_credential(DhcoreEnvVar.ISSUER.value, endpoint_issuer)
321
+ configurator.set_credential(DhcoreEnvVar.ISSUER.value.removeprefix("DHCORE_"), endpoint_issuer)
291
322
 
292
323
  # Standard issuer endpoint path
293
324
  url = endpoint_issuer + "/.well-known/openid-configuration"
@@ -315,6 +346,7 @@ class ClientDHCoreConfigurator:
315
346
  """
316
347
  # Get client id
317
348
  client_id = configurator.load_var(DhcoreEnvVar.CLIENT_ID.value)
349
+ # client_id = self._load_dhcore_oauth_vars(DhcoreEnvVar.CLIENT_ID.value)
318
350
  if client_id is None:
319
351
  raise ClientError("Client id not set.")
320
352
 
@@ -327,3 +359,22 @@ class ClientDHCoreConfigurator:
327
359
  }
328
360
  headers = {"Content-Type": "application/x-www-form-urlencoded"}
329
361
  return request("POST", url, data=payload, headers=headers, timeout=60)
362
+
363
+ def _load_dhcore_oauth_vars(self, oauth_var: str) -> str | None:
364
+ """
365
+ Load DHCore oauth variables.
366
+
367
+ Parameters
368
+ ----------
369
+ oauth_var : str
370
+ The oauth variable to load.
371
+
372
+ Returns
373
+ -------
374
+ str
375
+ The oauth variable.
376
+ """
377
+ read_var = configurator.load_from_env(oauth_var)
378
+ if read_var is None:
379
+ read_var = configurator.load_from_file(oauth_var.removeprefix("DHCORE_"))
380
+ 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 as e:
128
- raise ClientError(f"Failed to read env file: {e}")
127
+ except Exception:
128
+ return None
@@ -8,4 +8,4 @@ class StoreEnv(Enum):
8
8
  Environment variables for data stores.
9
9
  """
10
10
 
11
- DEFAULT_FILES_STORE = "DEFAULT_FILES_STORE"
11
+ DEFAULT_FILES_STORE = "DHCORE_DEFAULT_FILES_STORE"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: digitalhub
3
- Version: 0.11.0b2
3
+ Version: 0.11.0b4
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>
@@ -37,13 +37,13 @@ digitalhub/entities/_base/versioned/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQ
37
37
  digitalhub/entities/_base/versioned/builder.py,sha256=0niRbqpCnHqBK0hTQxdrtUl43BbJuGXMLVbruhpUUuU,1896
38
38
  digitalhub/entities/_base/versioned/entity.py,sha256=h4YX6smpPjIVW8DOVdRYW-abOcoJ_F0OkozLhLxpjWI,899
39
39
  digitalhub/entities/_commons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
- digitalhub/entities/_commons/enums.py,sha256=GJnVOPCPZKL1f53e7SvKi9n76k4Y4TfMmXcLzr62mg0,1989
40
+ digitalhub/entities/_commons/enums.py,sha256=KUzaKLUz31qW2QTT8lZ3tP6nbjJZvkw_vTzSrH9iS30,2017
41
41
  digitalhub/entities/_commons/metrics.py,sha256=SYb980t9smzJVUWGqE4Ug0t-0wPXYJZ_nJRi_9bhcpw,3405
42
42
  digitalhub/entities/_commons/types.py,sha256=bwK-2iQHL2gdtOPfRcXWBRWqqS1Tic6ywRQsJSocn9c,118
43
43
  digitalhub/entities/_commons/utils.py,sha256=354ZL5wKvijJ2A25pM0xK5JMhgTyZF6urjHZNjosINI,1846
44
44
  digitalhub/entities/_processors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
45
  digitalhub/entities/_processors/base.py,sha256=K_XfwgzsYWKMQ5Que1C_oTwQU67jQJPbA98g26OND58,13440
46
- digitalhub/entities/_processors/context.py,sha256=y7TYLANbH88mFsZdt77B-1NKTzpd_rpN06JceKSjtVc,33385
46
+ digitalhub/entities/_processors/context.py,sha256=D6X9l6ZSnsqi94h93IiyyCLahayUcvYAEXaqlfu6SUA,34445
47
47
  digitalhub/entities/_processors/utils.py,sha256=byhWUv3CfaS-RNPu5FdOdNNCakaKh5zNQFziJvwZdkY,3791
48
48
  digitalhub/entities/artifact/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
49
  digitalhub/entities/artifact/crud.py,sha256=smyZLWfkBEH1pxwFJXhoqfFpLrKeeWTqXmahyPj8QAY,7983
@@ -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=kLly2-87YAylsAZ8vhnTHmbfOhUSfn39Rl8M9n8Pc5g,9760
193
+ digitalhub/stores/client/dhcore/configurator.py,sha256=3j2170XaLqApZvzBx9MzzbFrAuBDpw8SD_OwImZMfNI,11269
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,11 +208,11 @@ 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=fGMQ8n28wXqmDCnk6x_VCE99KWqa7qU1OmQEEfWhQa8,2960
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
- digitalhub/stores/data/enums.py,sha256=dqDRDnLVK55jiWyg_L-aeTwu3JBo4EcN5epxzdS_ARs,190
215
+ digitalhub/stores/data/enums.py,sha256=8KyVhA5jTffomloR9pwR9FX21Dd3e9h2_qFCsVfd9yo,197
216
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
@@ -250,7 +250,7 @@ digitalhub/utils/io_utils.py,sha256=8jD4Rp_b7LZEpY5JSMxVUowZsnifKnbGpHT5Hijx9-g,
250
250
  digitalhub/utils/logger.py,sha256=ml3ne6D8wuRdNZ4F6ywmvWotSxjmZWnmKgNiuHb4R5M,437
251
251
  digitalhub/utils/types.py,sha256=x8zXsbivD8vdaNeNRZLKOPvGbz6d-59nncuvO0FsueY,109
252
252
  digitalhub/utils/uri_utils.py,sha256=wVkA2OcfHG5EcQOr9YxLJzo--VV6sjFjgXDNx-gP94I,4021
253
- digitalhub-0.11.0b2.dist-info/METADATA,sha256=ZEdvCZlv8Gh7AfR2ppDjJvKhfqUL7yMN5UHtP5vmL-s,15037
254
- digitalhub-0.11.0b2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
255
- digitalhub-0.11.0b2.dist-info/licenses/LICENSE.txt,sha256=qmrTTXPlgU0kSRlRVbjhlyGs1IXs2QPxo_Y-Mn06J0k,11589
256
- digitalhub-0.11.0b2.dist-info/RECORD,,
253
+ digitalhub-0.11.0b4.dist-info/METADATA,sha256=CjnTKib8SudfAZ7uZDTzLvHd8kFAHBHaR81PbnVUxkI,15037
254
+ digitalhub-0.11.0b4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
255
+ digitalhub-0.11.0b4.dist-info/licenses/LICENSE.txt,sha256=qmrTTXPlgU0kSRlRVbjhlyGs1IXs2QPxo_Y-Mn06J0k,11589
256
+ digitalhub-0.11.0b4.dist-info/RECORD,,