digitalhub 0.13.0b3__py3-none-any.whl → 0.14.9__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.
Files changed (139) hide show
  1. digitalhub/__init__.py +3 -8
  2. digitalhub/context/api.py +43 -6
  3. digitalhub/context/builder.py +1 -5
  4. digitalhub/context/context.py +28 -13
  5. digitalhub/entities/_base/_base/entity.py +0 -15
  6. digitalhub/entities/_base/context/entity.py +1 -4
  7. digitalhub/entities/_base/entity/builder.py +5 -5
  8. digitalhub/entities/_base/entity/entity.py +0 -8
  9. digitalhub/entities/_base/executable/entity.py +195 -87
  10. digitalhub/entities/_base/material/entity.py +11 -23
  11. digitalhub/entities/_base/material/utils.py +28 -4
  12. digitalhub/entities/_base/runtime_entity/builder.py +53 -18
  13. digitalhub/entities/_base/unversioned/entity.py +1 -1
  14. digitalhub/entities/_base/versioned/entity.py +1 -1
  15. digitalhub/entities/_commons/enums.py +1 -31
  16. digitalhub/entities/_commons/metrics.py +64 -30
  17. digitalhub/entities/_commons/utils.py +119 -30
  18. digitalhub/entities/_constructors/_resources.py +151 -0
  19. digitalhub/entities/{_base/entity/_constructors → _constructors}/name.py +18 -0
  20. digitalhub/entities/_processors/base/crud.py +381 -0
  21. digitalhub/entities/_processors/base/import_export.py +118 -0
  22. digitalhub/entities/_processors/base/processor.py +299 -0
  23. digitalhub/entities/_processors/base/special_ops.py +104 -0
  24. digitalhub/entities/_processors/context/crud.py +652 -0
  25. digitalhub/entities/_processors/context/import_export.py +242 -0
  26. digitalhub/entities/_processors/context/material.py +123 -0
  27. digitalhub/entities/_processors/context/processor.py +400 -0
  28. digitalhub/entities/_processors/context/special_ops.py +476 -0
  29. digitalhub/entities/_processors/processors.py +12 -0
  30. digitalhub/entities/_processors/utils.py +38 -102
  31. digitalhub/entities/artifact/crud.py +58 -22
  32. digitalhub/entities/artifact/utils.py +28 -13
  33. digitalhub/entities/builders.py +2 -0
  34. digitalhub/entities/dataitem/crud.py +63 -20
  35. digitalhub/entities/dataitem/table/entity.py +27 -22
  36. digitalhub/entities/dataitem/utils.py +82 -32
  37. digitalhub/entities/function/_base/entity.py +3 -6
  38. digitalhub/entities/function/crud.py +55 -24
  39. digitalhub/entities/model/_base/entity.py +62 -20
  40. digitalhub/entities/model/crud.py +59 -23
  41. digitalhub/entities/model/mlflow/utils.py +29 -20
  42. digitalhub/entities/model/utils.py +28 -13
  43. digitalhub/entities/project/_base/builder.py +0 -6
  44. digitalhub/entities/project/_base/entity.py +337 -164
  45. digitalhub/entities/project/_base/spec.py +4 -4
  46. digitalhub/entities/project/crud.py +28 -71
  47. digitalhub/entities/project/utils.py +7 -3
  48. digitalhub/entities/run/_base/builder.py +0 -4
  49. digitalhub/entities/run/_base/entity.py +70 -63
  50. digitalhub/entities/run/crud.py +79 -26
  51. digitalhub/entities/secret/_base/entity.py +1 -5
  52. digitalhub/entities/secret/crud.py +31 -28
  53. digitalhub/entities/task/_base/builder.py +0 -4
  54. digitalhub/entities/task/_base/entity.py +5 -5
  55. digitalhub/entities/task/_base/models.py +13 -16
  56. digitalhub/entities/task/crud.py +61 -29
  57. digitalhub/entities/trigger/_base/entity.py +1 -5
  58. digitalhub/entities/trigger/crud.py +89 -30
  59. digitalhub/entities/workflow/_base/entity.py +3 -8
  60. digitalhub/entities/workflow/crud.py +55 -24
  61. digitalhub/factory/entity.py +283 -0
  62. digitalhub/factory/enums.py +18 -0
  63. digitalhub/factory/registry.py +197 -0
  64. digitalhub/factory/runtime.py +44 -0
  65. digitalhub/factory/utils.py +3 -54
  66. digitalhub/runtimes/_base.py +2 -2
  67. digitalhub/stores/client/{dhcore/api_builder.py → api_builder.py} +3 -3
  68. digitalhub/stores/client/builder.py +19 -31
  69. digitalhub/stores/client/client.py +322 -0
  70. digitalhub/stores/client/configurator.py +408 -0
  71. digitalhub/stores/client/enums.py +50 -0
  72. digitalhub/stores/client/{dhcore/error_parser.py → error_parser.py} +0 -4
  73. digitalhub/stores/client/header_manager.py +61 -0
  74. digitalhub/stores/client/http_handler.py +152 -0
  75. digitalhub/stores/client/{_base/key_builder.py → key_builder.py} +14 -14
  76. digitalhub/stores/client/params_builder.py +330 -0
  77. digitalhub/stores/client/response_processor.py +102 -0
  78. digitalhub/stores/client/utils.py +35 -0
  79. digitalhub/stores/{credentials → configurator}/api.py +5 -9
  80. digitalhub/stores/configurator/configurator.py +123 -0
  81. digitalhub/stores/{credentials → configurator}/enums.py +27 -10
  82. digitalhub/stores/configurator/handler.py +213 -0
  83. digitalhub/stores/{credentials → configurator}/ini_module.py +31 -22
  84. digitalhub/stores/data/_base/store.py +0 -20
  85. digitalhub/stores/data/api.py +5 -7
  86. digitalhub/stores/data/builder.py +53 -27
  87. digitalhub/stores/data/local/store.py +0 -103
  88. digitalhub/stores/data/remote/store.py +0 -4
  89. digitalhub/stores/data/s3/configurator.py +39 -77
  90. digitalhub/stores/data/s3/store.py +57 -37
  91. digitalhub/stores/data/sql/configurator.py +66 -46
  92. digitalhub/stores/data/sql/store.py +171 -104
  93. digitalhub/stores/readers/data/factory.py +0 -8
  94. digitalhub/stores/readers/data/pandas/reader.py +9 -19
  95. digitalhub/utils/file_utils.py +0 -17
  96. digitalhub/utils/generic_utils.py +1 -14
  97. digitalhub/utils/git_utils.py +0 -8
  98. digitalhub/utils/io_utils.py +0 -12
  99. digitalhub/utils/store_utils.py +44 -0
  100. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/METADATA +5 -4
  101. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/RECORD +112 -113
  102. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/WHEEL +1 -1
  103. digitalhub/entities/_commons/types.py +0 -9
  104. digitalhub/entities/_processors/base.py +0 -531
  105. digitalhub/entities/_processors/context.py +0 -1299
  106. digitalhub/entities/task/_base/utils.py +0 -22
  107. digitalhub/factory/factory.py +0 -381
  108. digitalhub/stores/client/_base/api_builder.py +0 -34
  109. digitalhub/stores/client/_base/client.py +0 -243
  110. digitalhub/stores/client/_base/params_builder.py +0 -34
  111. digitalhub/stores/client/api.py +0 -36
  112. digitalhub/stores/client/dhcore/client.py +0 -613
  113. digitalhub/stores/client/dhcore/configurator.py +0 -675
  114. digitalhub/stores/client/dhcore/enums.py +0 -34
  115. digitalhub/stores/client/dhcore/key_builder.py +0 -62
  116. digitalhub/stores/client/dhcore/models.py +0 -40
  117. digitalhub/stores/client/dhcore/params_builder.py +0 -278
  118. digitalhub/stores/client/dhcore/utils.py +0 -94
  119. digitalhub/stores/client/local/api_builder.py +0 -116
  120. digitalhub/stores/client/local/client.py +0 -573
  121. digitalhub/stores/client/local/enums.py +0 -15
  122. digitalhub/stores/client/local/key_builder.py +0 -62
  123. digitalhub/stores/client/local/params_builder.py +0 -120
  124. digitalhub/stores/credentials/__init__.py +0 -3
  125. digitalhub/stores/credentials/configurator.py +0 -210
  126. digitalhub/stores/credentials/handler.py +0 -176
  127. digitalhub/stores/credentials/store.py +0 -81
  128. digitalhub/stores/data/enums.py +0 -15
  129. digitalhub/stores/data/s3/utils.py +0 -78
  130. /digitalhub/entities/{_base/entity/_constructors → _constructors}/__init__.py +0 -0
  131. /digitalhub/entities/{_base/entity/_constructors → _constructors}/metadata.py +0 -0
  132. /digitalhub/entities/{_base/entity/_constructors → _constructors}/spec.py +0 -0
  133. /digitalhub/entities/{_base/entity/_constructors → _constructors}/status.py +0 -0
  134. /digitalhub/entities/{_base/entity/_constructors → _constructors}/uuid.py +0 -0
  135. /digitalhub/{stores/client/_base → entities/_processors/base}/__init__.py +0 -0
  136. /digitalhub/{stores/client/dhcore → entities/_processors/context}/__init__.py +0 -0
  137. /digitalhub/stores/{client/local → configurator}/__init__.py +0 -0
  138. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/licenses/AUTHORS +0 -0
  139. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.9.dist-info}/licenses/LICENSE +0 -0
@@ -1,120 +0,0 @@
1
- # SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
4
-
5
- from __future__ import annotations
6
-
7
- from digitalhub.entities._commons.enums import ApiCategories, BackendOperations
8
- from digitalhub.stores.client._base.params_builder import ClientParametersBuilder
9
-
10
-
11
- class ClientLocalParametersBuilder(ClientParametersBuilder):
12
- """
13
- This class is used to build the parameters for the Local client calls.
14
- """
15
-
16
- def build_parameters(self, category: str, operation: str, **kwargs) -> dict:
17
- """
18
- Build the parameters for the client call.
19
-
20
- Parameters
21
- ----------
22
- category : str
23
- API category.
24
- operation : str
25
- API operation.
26
- **kwargs : dict
27
- Parameters to build.
28
-
29
- Returns
30
- -------
31
- dict
32
- Parameters formatted.
33
- """
34
- if category == ApiCategories.BASE.value:
35
- return self.build_parameters_base(operation, **kwargs)
36
- return self.build_parameters_context(operation, **kwargs)
37
-
38
- def build_parameters_base(self, operation: str, **kwargs) -> dict:
39
- """
40
- Build the base parameters for the client call.
41
-
42
- Parameters
43
- ----------
44
- operation : str
45
- API operation.
46
- **kwargs : dict
47
- Parameters to build.
48
-
49
- Returns
50
- -------
51
- dict
52
- Parameters formatted.
53
- """
54
- kwargs = self._set_params(**kwargs)
55
- if operation == BackendOperations.DELETE.value:
56
- if (cascade := kwargs.pop("cascade", None)) is not None:
57
- kwargs["params"]["cascade"] = str(cascade).lower()
58
- return kwargs
59
-
60
- def build_parameters_context(self, operation: str, **kwargs) -> dict:
61
- """
62
- Build the context parameters for the client call.
63
-
64
- Parameters
65
- ----------
66
- operation : str
67
- API operation.
68
- **kwargs : dict
69
- Parameters to build.
70
-
71
- Returns
72
- -------
73
- dict
74
- Parameters formatted.
75
- """
76
- kwargs = self._set_params(**kwargs)
77
-
78
- # Handle read
79
- if operation == BackendOperations.READ_ALL_VERSIONS.value:
80
- kwargs["params"]["versions"] = "all"
81
- kwargs["params"]["name"] = kwargs.pop("entity_name")
82
- # Handle delete
83
- elif operation == BackendOperations.DELETE.value:
84
- # Handle cascade
85
- if cascade := kwargs.pop("cascade", None) is not None:
86
- kwargs["params"]["cascade"] = str(cascade).lower()
87
-
88
- # Handle delete all versions
89
- entity_id = kwargs.pop("entity_id")
90
- entity_name = kwargs.pop("entity_name")
91
- if not kwargs.pop("delete_all_versions", False):
92
- if entity_id is None:
93
- raise ValueError(
94
- "If `delete_all_versions` is False, `entity_id` must be provided,"
95
- " either as an argument or in key `identifier`.",
96
- )
97
- else:
98
- kwargs["params"]["name"] = entity_name
99
- return kwargs
100
-
101
- @staticmethod
102
- def _set_params(**kwargs) -> dict:
103
- """
104
- Format params parameter.
105
-
106
- Parameters
107
- ----------
108
- **kwargs : dict
109
- Keyword arguments.
110
-
111
- Returns
112
- -------
113
- dict
114
- Parameters with initialized params.
115
- """
116
- if not kwargs:
117
- kwargs = {}
118
- if "params" not in kwargs:
119
- kwargs["params"] = {}
120
- return kwargs
@@ -1,3 +0,0 @@
1
- # SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
@@ -1,210 +0,0 @@
1
- # SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
4
-
5
- from __future__ import annotations
6
-
7
- from abc import abstractmethod
8
-
9
- from digitalhub.stores.credentials.enums import CredsOrigin
10
- from digitalhub.stores.credentials.handler import creds_handler
11
- from digitalhub.utils.exceptions import ConfigError
12
-
13
-
14
- class Configurator:
15
- """
16
- Base configurator for credentials management.
17
-
18
- Attributes
19
- ----------
20
- keys : list of str
21
- List of credential keys to manage.
22
- required_keys : list of str
23
- List of required credential keys.
24
- _env : str
25
- Environment origin identifier.
26
- _file : str
27
- File origin identifier.
28
- _creds_handler : object
29
- Credentials handler instance.
30
- """
31
-
32
- # Must be set in implementing class
33
- keys: list[str] = []
34
- required_keys: list[str] = []
35
-
36
- # Origin of the credentials
37
- _env = CredsOrigin.ENV.value
38
- _file = CredsOrigin.FILE.value
39
-
40
- # Credentials handler
41
- _creds_handler = creds_handler
42
-
43
- def __init__(self):
44
- self._current_profile = self._creds_handler.get_current_profile()
45
- self.load_configs()
46
- self._changed_origin = False
47
- self._origin = self.set_origin()
48
-
49
- ##############################
50
- # Configuration
51
- ##############################
52
-
53
- def load_configs(self) -> None:
54
- """
55
- Load the configuration from both environment and file sources.
56
-
57
- Returns
58
- -------
59
- None
60
- """
61
- self.load_env_vars()
62
- self.load_file_vars()
63
-
64
- @abstractmethod
65
- def load_env_vars(self) -> None:
66
- ...
67
-
68
- @abstractmethod
69
- def load_file_vars(self) -> None:
70
- ...
71
-
72
- def check_config(self) -> None:
73
- """
74
- Check if the current profile has changed and reload
75
- the file credentials if needed.
76
-
77
- Returns
78
- -------
79
- None
80
- """
81
- if (current := self._creds_handler.get_current_profile()) != self._current_profile:
82
- self.load_file_vars()
83
- self._current_profile = current
84
-
85
- def set_origin(self) -> str:
86
- """
87
- Determine the default origin for credentials (env or file).
88
-
89
- Returns
90
- -------
91
- str
92
- The selected origin ('env' or 'file').
93
-
94
- Raises
95
- ------
96
- ConfigError
97
- If required credentials are missing in both sources.
98
- """
99
- origin = self._env
100
-
101
- env_creds = self._creds_handler.get_credentials(self._env)
102
- missing_env = self._check_credentials(env_creds)
103
-
104
- file_creds = self._creds_handler.get_credentials(self._file)
105
- missing_file = self._check_credentials(file_creds)
106
-
107
- msg = ""
108
- if missing_env:
109
- msg = f"Missing required vars in env: {', '.join(missing_env)}"
110
- origin = self._file
111
- self._changed_origin = True
112
- elif missing_file:
113
- msg += f"Missing required vars in .dhcore.ini file: {', '.join(missing_file)}"
114
-
115
- if missing_env and missing_file:
116
- raise ConfigError(msg)
117
-
118
- return origin
119
-
120
- def eval_change_origin(self) -> None:
121
- """
122
- Attempt to change the origin of credentials.
123
- Raise error if already evaluated.
124
-
125
- Returns
126
- -------
127
- None
128
- """
129
- try:
130
- self.change_origin()
131
- except ConfigError:
132
- raise ConfigError("Credentials origin already evaluated. Please check your credentials.")
133
-
134
- def change_origin(self) -> None:
135
- """
136
- Change the origin of credentials from env to file or vice versa.
137
-
138
- Returns
139
- -------
140
- None
141
- """
142
- if self._changed_origin:
143
- raise ConfigError("Origin has already been changed.")
144
- if self._origin == self._env:
145
- self.change_to_file()
146
- self.change_to_env()
147
-
148
- def change_to_file(self) -> None:
149
- """
150
- Set the credentials origin to file.
151
-
152
- Returns
153
- -------
154
- None
155
- """
156
- if self._origin == self._env:
157
- self._changed_origin = True
158
- self._origin = CredsOrigin.FILE.value
159
-
160
- def change_to_env(self) -> None:
161
- """
162
- Set the credentials origin to environment.
163
-
164
- Returns
165
- -------
166
- None
167
- """
168
- if self._origin == self._file:
169
- self._changed_origin = True
170
- self._origin = CredsOrigin.ENV.value
171
-
172
- ##############################
173
- # Credentials
174
- ##############################
175
-
176
- def get_credentials(self, origin: str) -> dict:
177
- """
178
- Retrieve credentials for the specified origin.
179
-
180
- Parameters
181
- ----------
182
- origin : str
183
- The origin to retrieve credentials from ('env' or 'file').
184
-
185
- Returns
186
- -------
187
- dict
188
- Dictionary of credentials.
189
- """
190
- return self._creds_handler.get_credentials(origin)
191
-
192
- def _check_credentials(self, creds: dict) -> list[str]:
193
- """
194
- Check for missing required credentials in a dictionary.
195
-
196
- Parameters
197
- ----------
198
- creds : dict
199
- Dictionary of credentials to check.
200
-
201
- Returns
202
- -------
203
- list of str
204
- List of missing required credential keys.
205
- """
206
- missing_keys = []
207
- for k, v in creds.items():
208
- if v is None and k in self.required_keys:
209
- missing_keys.append(k)
210
- return missing_keys
@@ -1,176 +0,0 @@
1
- # SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
4
-
5
- from __future__ import annotations
6
-
7
- import os
8
-
9
- from digitalhub.stores.credentials.enums import SetCreds
10
- from digitalhub.stores.credentials.ini_module import (
11
- load_file,
12
- load_key,
13
- load_profile,
14
- set_current_profile,
15
- write_config,
16
- )
17
- from digitalhub.stores.credentials.store import CredentialsStore
18
-
19
-
20
- class CredentialHandler:
21
- """
22
- Handler for configuring clients and managing credentials.
23
-
24
- Attributes
25
- ----------
26
- _creds_store : CredentialsStore
27
- Store for credentials.
28
- _profile : str
29
- Current credentials profile name.
30
- """
31
-
32
- def __init__(self) -> None:
33
- self._creds_store = CredentialsStore()
34
- self._profile = self._read_current_profile()
35
-
36
- @staticmethod
37
- def _read_current_profile() -> str:
38
- """
39
- Read the current credentials profile name.
40
-
41
- Returns
42
- -------
43
- str
44
- Name of the credentials profile.
45
- """
46
- profile = os.getenv(SetCreds.DH_PROFILE.value)
47
- if profile is not None:
48
- return profile
49
- file = load_file()
50
- profile = load_profile(file)
51
- if profile is not None:
52
- return profile
53
- return SetCreds.DEFAULT.value
54
-
55
- ##############################
56
- # Public methods
57
- ##############################
58
-
59
- def set_current_profile(self, creds_set: str) -> None:
60
- """
61
- Set the current credentials profile name.
62
-
63
- Parameters
64
- ----------
65
- creds_set : str
66
- Name of the credentials profile to set.
67
-
68
- Returns
69
- -------
70
- None
71
- """
72
- self._profile = creds_set
73
- set_current_profile(creds_set)
74
-
75
- def get_current_profile(self) -> str:
76
- """
77
- Get the current credentials profile name.
78
-
79
- Returns
80
- -------
81
- str
82
- Name of the current credentials profile.
83
- """
84
- return self._profile
85
-
86
- def load_from_env(self, vars: list[str]) -> dict:
87
- """
88
- Load variables from environment.
89
-
90
- Parameters
91
- ----------
92
- vars : list of str
93
- List of environment variable names to load.
94
-
95
- Returns
96
- -------
97
- dict
98
- Dictionary of environment variable values.
99
- """
100
- return {var: os.getenv(var) for var in vars}
101
-
102
- def load_from_file(self, vars: list[str]) -> dict:
103
- """
104
- Load variables from credentials config file.
105
-
106
- Parameters
107
- ----------
108
- vars : list of str
109
- List of variable names to load from file.
110
-
111
- Returns
112
- -------
113
- dict
114
- Dictionary of variable values from file.
115
- """
116
- file = load_file()
117
- profile = load_profile(file)
118
- if profile is not None:
119
- self._profile = profile
120
- return {var: load_key(file, self._profile, var) for var in vars}
121
-
122
- def write_env(self, creds: dict) -> None:
123
- """
124
- Write credentials to the .dhcore file for the current profile.
125
-
126
- Parameters
127
- ----------
128
- creds : dict
129
- Credentials to write.
130
-
131
- Returns
132
- -------
133
- None
134
- """
135
- write_config(creds, self._profile)
136
-
137
- ##############################
138
- # Credentials store methods
139
- ##############################
140
-
141
- def set_credentials(self, origin: str, creds: dict) -> None:
142
- """
143
- Set credentials for the current profile and origin.
144
-
145
- Parameters
146
- ----------
147
- origin : str
148
- The origin of the credentials ('env' or 'file').
149
- creds : dict
150
- Credentials to set.
151
-
152
- Returns
153
- -------
154
- None
155
- """
156
- self._creds_store.set_credentials(self._profile, origin, creds)
157
-
158
- def get_credentials(self, origin: str) -> dict:
159
- """
160
- Get credentials for the current profile from the specified origin.
161
-
162
- Parameters
163
- ----------
164
- origin : str
165
- The origin to get credentials from ('env' or 'file').
166
-
167
- Returns
168
- -------
169
- dict
170
- Dictionary of credentials.
171
- """
172
- return self._creds_store.get_credentials(self._profile, origin)
173
-
174
-
175
- # Define global credential handler
176
- creds_handler = CredentialHandler()
@@ -1,81 +0,0 @@
1
- # SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
4
-
5
- from __future__ import annotations
6
-
7
- from typing import Any
8
-
9
- from digitalhub.stores.credentials.enums import CredsOrigin
10
-
11
-
12
- class CredentialsStore:
13
- """
14
- Store and retrieve credentials for different profiles and origins.
15
-
16
- Attributes
17
- ----------
18
- _file_creds : dict of str to dict
19
- Credentials stored by profile from file origin.
20
- _env_creds : dict of str to Any
21
- Credentials stored from environment origin.
22
- """
23
-
24
- def __init__(self) -> None:
25
- self._file_creds: dict[str, dict[str, Any]] = {}
26
- self._env_creds: dict[str, Any] = {}
27
-
28
- def set_credentials(
29
- self,
30
- profile: str,
31
- origin: str,
32
- credentials: dict[str, Any],
33
- ) -> None:
34
- """
35
- Set all credentials for a given profile and origin.
36
-
37
- Parameters
38
- ----------
39
- profile : str
40
- Name of the credentials profile.
41
- origin : str
42
- Origin of the credentials ('env' or 'file').
43
- credentials : dict of str to Any
44
- Dictionary of credentials to set.
45
-
46
- Returns
47
- -------
48
- None
49
- """
50
- if origin == CredsOrigin.ENV.value:
51
- for key, value in credentials.items():
52
- self._env_creds[key] = value
53
- return
54
- if profile not in self._file_creds:
55
- self._file_creds[profile] = {}
56
- for key, value in credentials.items():
57
- self._file_creds[profile][key] = value
58
-
59
- def get_credentials(
60
- self,
61
- profile: str,
62
- origin: str,
63
- ) -> dict[str, Any]:
64
- """
65
- Get all credentials for a given profile and origin.
66
-
67
- Parameters
68
- ----------
69
- profile : str
70
- Name of the credentials profile.
71
- origin : str
72
- Origin of the credentials ('env' or 'file').
73
-
74
- Returns
75
- -------
76
- dict of str to Any
77
- Dictionary of credentials for the profile and origin.
78
- """
79
- if origin == CredsOrigin.ENV.value:
80
- return self._env_creds
81
- return self._file_creds[profile]
@@ -1,15 +0,0 @@
1
- # SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
4
-
5
- from __future__ import annotations
6
-
7
- from enum import Enum
8
-
9
-
10
- class StoreEnv(Enum):
11
- """
12
- Environment variables for data stores.
13
- """
14
-
15
- DEFAULT_FILES_STORE = "DHCORE_DEFAULT_FILES_STORE"
@@ -1,78 +0,0 @@
1
- # SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
4
-
5
- from __future__ import annotations
6
-
7
- from pathlib import Path
8
- from urllib.parse import urlparse
9
-
10
- from boto3 import client as boto3_client
11
-
12
- from digitalhub.stores.credentials.enums import CredsOrigin
13
- from digitalhub.stores.data.s3.configurator import S3StoreConfigurator
14
- from digitalhub.utils.exceptions import StoreError
15
-
16
-
17
- def get_bucket_name(path: str) -> str:
18
- """
19
- Extract the bucket name from an S3 path.
20
-
21
- Parameters
22
- ----------
23
- path : str
24
- S3 URI (e.g., 's3://bucket/key').
25
-
26
- Returns
27
- -------
28
- str
29
- The bucket name extracted from the URI.
30
- """
31
- return urlparse(path).netloc
32
-
33
-
34
- def get_bucket_and_key(path: str) -> tuple[str, str]:
35
- """
36
- Extract the bucket name and key from an S3 path.
37
-
38
- Parameters
39
- ----------
40
- path : str
41
- S3 URI (e.g., 's3://bucket/key').
42
-
43
- Returns
44
- -------
45
- tuple of str
46
- Tuple containing (bucket, key) extracted from the URI.
47
- """
48
- parsed = urlparse(path)
49
- return parsed.netloc, parsed.path
50
-
51
-
52
- def get_s3_source(bucket: str, key: str, filename: Path) -> None:
53
- """
54
- Download an object from S3 and save it to a local file.
55
-
56
- Parameters
57
- ----------
58
- bucket : str
59
- S3 bucket name.
60
- key : str
61
- S3 object key.
62
- filename : Path
63
- Local path where the downloaded object will be saved.
64
-
65
- Returns
66
- -------
67
- None
68
- """
69
- # Try to get client from environment variables
70
- try:
71
- cfg = S3StoreConfigurator().get_boto3_client_config(CredsOrigin.ENV.value)
72
- s3 = boto3_client("s3", **cfg)
73
- s3.download_file(bucket, key, filename)
74
-
75
- # Fallback to file
76
- except StoreError:
77
- cfg = S3StoreConfigurator().get_boto3_client_config(CredsOrigin.FILE.value)
78
- s3.download_file(bucket, key, filename)