digitalhub 0.14.0b5__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.
- digitalhub/__init__.py +2 -2
- digitalhub/context/api.py +43 -6
- digitalhub/context/builder.py +1 -1
- digitalhub/context/context.py +3 -6
- digitalhub/entities/_base/context/entity.py +0 -3
- digitalhub/entities/_base/executable/entity.py +29 -11
- digitalhub/entities/_base/material/entity.py +2 -2
- digitalhub/entities/_base/material/utils.py +0 -4
- digitalhub/entities/_commons/enums.py +1 -0
- digitalhub/entities/_commons/utils.py +19 -0
- digitalhub/entities/_processors/base/crud.py +15 -24
- digitalhub/entities/_processors/base/import_export.py +3 -7
- digitalhub/entities/_processors/base/processor.py +4 -7
- digitalhub/entities/_processors/base/special_ops.py +4 -8
- digitalhub/entities/_processors/context/crud.py +27 -29
- digitalhub/entities/_processors/context/import_export.py +7 -7
- digitalhub/entities/_processors/context/material.py +2 -2
- digitalhub/entities/_processors/context/special_ops.py +25 -25
- digitalhub/entities/_processors/utils.py +7 -116
- digitalhub/entities/artifact/crud.py +3 -3
- digitalhub/entities/artifact/utils.py +2 -2
- digitalhub/entities/builders.py +2 -0
- digitalhub/entities/dataitem/crud.py +3 -3
- digitalhub/entities/dataitem/utils.py +10 -14
- digitalhub/entities/function/_base/entity.py +0 -3
- digitalhub/entities/function/crud.py +3 -3
- digitalhub/entities/model/crud.py +3 -3
- digitalhub/entities/model/mlflow/utils.py +29 -20
- digitalhub/entities/model/utils.py +2 -2
- digitalhub/entities/project/_base/builder.py +0 -6
- digitalhub/entities/project/_base/entity.py +264 -114
- digitalhub/entities/project/_base/spec.py +4 -4
- digitalhub/entities/project/crud.py +16 -51
- digitalhub/entities/project/utils.py +7 -3
- digitalhub/entities/secret/crud.py +2 -2
- digitalhub/entities/task/_base/models.py +13 -16
- digitalhub/entities/trigger/crud.py +28 -9
- digitalhub/entities/workflow/_base/entity.py +0 -5
- digitalhub/entities/workflow/crud.py +3 -6
- digitalhub/stores/client/{dhcore/api_builder.py → api_builder.py} +2 -3
- digitalhub/stores/client/builder.py +20 -32
- digitalhub/stores/client/client.py +322 -0
- digitalhub/stores/client/{dhcore/configurator.py → configurator.py} +148 -195
- digitalhub/stores/client/{_base/enums.py → enums.py} +11 -0
- digitalhub/stores/client/header_manager.py +61 -0
- digitalhub/stores/client/http_handler.py +152 -0
- digitalhub/stores/client/{_base/key_builder.py → key_builder.py} +14 -14
- digitalhub/stores/client/{dhcore/params_builder.py → params_builder.py} +51 -12
- digitalhub/stores/client/response_processor.py +102 -0
- digitalhub/stores/client/utils.py +35 -0
- digitalhub/stores/{credentials → configurator}/api.py +5 -9
- digitalhub/stores/configurator/configurator.py +123 -0
- digitalhub/stores/{credentials → configurator}/enums.py +26 -10
- digitalhub/stores/configurator/handler.py +213 -0
- digitalhub/stores/{credentials → configurator}/ini_module.py +31 -6
- digitalhub/stores/data/_base/store.py +0 -4
- digitalhub/stores/data/api.py +4 -6
- digitalhub/stores/data/builder.py +6 -38
- digitalhub/stores/data/s3/configurator.py +30 -114
- digitalhub/stores/data/s3/store.py +9 -22
- digitalhub/stores/data/sql/configurator.py +49 -71
- digitalhub/stores/data/sql/store.py +26 -61
- digitalhub/utils/generic_utils.py +0 -12
- digitalhub/utils/git_utils.py +0 -8
- digitalhub/utils/io_utils.py +0 -8
- digitalhub/utils/store_utils.py +1 -1
- {digitalhub-0.14.0b5.dist-info → digitalhub-0.14.9.dist-info}/METADATA +3 -3
- {digitalhub-0.14.0b5.dist-info → digitalhub-0.14.9.dist-info}/RECORD +73 -86
- {digitalhub-0.14.0b5.dist-info → digitalhub-0.14.9.dist-info}/WHEEL +1 -1
- digitalhub/stores/client/_base/api_builder.py +0 -34
- digitalhub/stores/client/_base/client.py +0 -243
- digitalhub/stores/client/_base/params_builder.py +0 -82
- digitalhub/stores/client/api.py +0 -32
- digitalhub/stores/client/dhcore/__init__.py +0 -3
- digitalhub/stores/client/dhcore/client.py +0 -553
- digitalhub/stores/client/dhcore/enums.py +0 -18
- digitalhub/stores/client/dhcore/key_builder.py +0 -62
- digitalhub/stores/client/dhcore/utils.py +0 -86
- digitalhub/stores/client/local/__init__.py +0 -3
- digitalhub/stores/client/local/api_builder.py +0 -116
- digitalhub/stores/client/local/client.py +0 -605
- digitalhub/stores/client/local/enums.py +0 -15
- digitalhub/stores/client/local/key_builder.py +0 -62
- digitalhub/stores/client/local/params_builder.py +0 -97
- digitalhub/stores/credentials/__init__.py +0 -3
- digitalhub/stores/credentials/configurator.py +0 -185
- digitalhub/stores/credentials/handler.py +0 -164
- digitalhub/stores/credentials/store.py +0 -77
- digitalhub/stores/data/enums.py +0 -15
- /digitalhub/stores/client/{dhcore/error_parser.py → error_parser.py} +0 -0
- /digitalhub/stores/{client/_base → configurator}/__init__.py +0 -0
- {digitalhub-0.14.0b5.dist-info → digitalhub-0.14.9.dist-info}/licenses/AUTHORS +0 -0
- {digitalhub-0.14.0b5.dist-info → digitalhub-0.14.9.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,97 +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.stores.client._base.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._ensure_params(**kwargs)
|
|
55
|
-
|
|
56
|
-
# Handle delete
|
|
57
|
-
if operation == BackendOperations.DELETE.value:
|
|
58
|
-
if (cascade := kwargs.pop("cascade", None)) is not None:
|
|
59
|
-
kwargs = self._add_param("cascade", str(cascade).lower(), **kwargs)
|
|
60
|
-
|
|
61
|
-
return kwargs
|
|
62
|
-
|
|
63
|
-
def build_parameters_context(self, operation: str, **kwargs) -> dict:
|
|
64
|
-
"""
|
|
65
|
-
Build the context parameters for the client call.
|
|
66
|
-
|
|
67
|
-
Parameters
|
|
68
|
-
----------
|
|
69
|
-
operation : str
|
|
70
|
-
API operation.
|
|
71
|
-
**kwargs : dict
|
|
72
|
-
Parameters to build.
|
|
73
|
-
|
|
74
|
-
Returns
|
|
75
|
-
-------
|
|
76
|
-
dict
|
|
77
|
-
Parameters formatted.
|
|
78
|
-
"""
|
|
79
|
-
kwargs = self._ensure_params(**kwargs)
|
|
80
|
-
|
|
81
|
-
# Handle read all versions
|
|
82
|
-
if operation == BackendOperations.READ_ALL_VERSIONS.value:
|
|
83
|
-
kwargs = self._add_param("versions", "all", **kwargs)
|
|
84
|
-
kwargs = self._add_param("name", kwargs.pop("name"), **kwargs)
|
|
85
|
-
|
|
86
|
-
# Handle delete
|
|
87
|
-
elif operation == BackendOperations.DELETE.value:
|
|
88
|
-
if (cascade := kwargs.pop("cascade", None)) is not None:
|
|
89
|
-
kwargs = self._add_param("cascade", str(cascade).lower(), **kwargs)
|
|
90
|
-
|
|
91
|
-
# Handle delete all versions
|
|
92
|
-
elif operation == BackendOperations.DELETE_ALL_VERSIONS.value:
|
|
93
|
-
if (cascade := kwargs.pop("cascade", None)) is not None:
|
|
94
|
-
kwargs = self._add_param("cascade", str(cascade).lower(), **kwargs)
|
|
95
|
-
kwargs = self._add_param("name", kwargs.pop("name"), **kwargs)
|
|
96
|
-
|
|
97
|
-
return kwargs
|
|
@@ -1,185 +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
|
-
self.load_env_vars()
|
|
58
|
-
self.load_file_vars()
|
|
59
|
-
|
|
60
|
-
@abstractmethod
|
|
61
|
-
def load_env_vars(self) -> None: ...
|
|
62
|
-
|
|
63
|
-
@abstractmethod
|
|
64
|
-
def load_file_vars(self) -> None: ...
|
|
65
|
-
|
|
66
|
-
def check_config(self) -> None:
|
|
67
|
-
"""
|
|
68
|
-
Check if the current profile has changed and reload
|
|
69
|
-
the file credentials if needed.
|
|
70
|
-
"""
|
|
71
|
-
if (current := self._creds_handler.get_current_profile()) != self._current_profile:
|
|
72
|
-
self.load_file_vars()
|
|
73
|
-
self._current_profile = current
|
|
74
|
-
|
|
75
|
-
def set_origin(self) -> str:
|
|
76
|
-
"""
|
|
77
|
-
Determine the default origin for credentials (env or file).
|
|
78
|
-
|
|
79
|
-
Returns
|
|
80
|
-
-------
|
|
81
|
-
str
|
|
82
|
-
The selected origin ('env' or 'file').
|
|
83
|
-
|
|
84
|
-
Raises
|
|
85
|
-
------
|
|
86
|
-
ConfigError
|
|
87
|
-
If required credentials are missing in both sources.
|
|
88
|
-
"""
|
|
89
|
-
origin = self._env
|
|
90
|
-
|
|
91
|
-
env_creds = self._creds_handler.get_credentials(self._env)
|
|
92
|
-
missing_env = self._check_credentials(env_creds)
|
|
93
|
-
|
|
94
|
-
file_creds = self._creds_handler.get_credentials(self._file)
|
|
95
|
-
missing_file = self._check_credentials(file_creds)
|
|
96
|
-
|
|
97
|
-
msg = ""
|
|
98
|
-
if missing_env:
|
|
99
|
-
msg = f"Missing required vars in env: {', '.join(missing_env)}"
|
|
100
|
-
origin = self._file
|
|
101
|
-
self._changed_origin = True
|
|
102
|
-
elif missing_file:
|
|
103
|
-
msg += f"Missing required vars in .dhcore.ini file: {', '.join(missing_file)}"
|
|
104
|
-
|
|
105
|
-
if missing_env and missing_file:
|
|
106
|
-
raise ConfigError(msg)
|
|
107
|
-
|
|
108
|
-
return origin
|
|
109
|
-
|
|
110
|
-
def eval_change_origin(self) -> None:
|
|
111
|
-
"""
|
|
112
|
-
Attempt to change the origin of credentials.
|
|
113
|
-
Raise error if already evaluated.
|
|
114
|
-
"""
|
|
115
|
-
try:
|
|
116
|
-
self.change_origin()
|
|
117
|
-
except ConfigError:
|
|
118
|
-
raise ConfigError("Credentials origin already evaluated. Please check your credentials.")
|
|
119
|
-
|
|
120
|
-
def change_origin(self) -> None:
|
|
121
|
-
"""
|
|
122
|
-
Change the origin of credentials from env to file or vice versa.
|
|
123
|
-
"""
|
|
124
|
-
if self._changed_origin:
|
|
125
|
-
raise ConfigError("Origin has already been changed.")
|
|
126
|
-
if self._origin == self._env:
|
|
127
|
-
self.change_to_file()
|
|
128
|
-
else:
|
|
129
|
-
self.change_to_env()
|
|
130
|
-
|
|
131
|
-
def change_to_file(self) -> None:
|
|
132
|
-
"""
|
|
133
|
-
Set the credentials origin to file.
|
|
134
|
-
"""
|
|
135
|
-
if self._origin == self._env:
|
|
136
|
-
self._changed_origin = True
|
|
137
|
-
self._origin = CredsOrigin.FILE.value
|
|
138
|
-
|
|
139
|
-
def change_to_env(self) -> None:
|
|
140
|
-
"""
|
|
141
|
-
Set the credentials origin to environment.
|
|
142
|
-
"""
|
|
143
|
-
if self._origin == self._file:
|
|
144
|
-
self._changed_origin = True
|
|
145
|
-
self._origin = CredsOrigin.ENV.value
|
|
146
|
-
|
|
147
|
-
##############################
|
|
148
|
-
# Credentials
|
|
149
|
-
##############################
|
|
150
|
-
|
|
151
|
-
def get_credentials(self, origin: str) -> dict:
|
|
152
|
-
"""
|
|
153
|
-
Retrieve credentials for the specified origin.
|
|
154
|
-
|
|
155
|
-
Parameters
|
|
156
|
-
----------
|
|
157
|
-
origin : str
|
|
158
|
-
The origin to retrieve credentials from ('env' or 'file').
|
|
159
|
-
|
|
160
|
-
Returns
|
|
161
|
-
-------
|
|
162
|
-
dict
|
|
163
|
-
Dictionary of credentials.
|
|
164
|
-
"""
|
|
165
|
-
return self._creds_handler.get_credentials(origin)
|
|
166
|
-
|
|
167
|
-
def _check_credentials(self, creds: dict) -> list[str]:
|
|
168
|
-
"""
|
|
169
|
-
Check for missing required credentials in a dictionary.
|
|
170
|
-
|
|
171
|
-
Parameters
|
|
172
|
-
----------
|
|
173
|
-
creds : dict
|
|
174
|
-
Dictionary of credentials to check.
|
|
175
|
-
|
|
176
|
-
Returns
|
|
177
|
-
-------
|
|
178
|
-
list of str
|
|
179
|
-
List of missing required credential keys.
|
|
180
|
-
"""
|
|
181
|
-
missing_keys = []
|
|
182
|
-
for k, v in creds.items():
|
|
183
|
-
if v is None and k in self.required_keys:
|
|
184
|
-
missing_keys.append(k)
|
|
185
|
-
return missing_keys
|
|
@@ -1,164 +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
|
-
self._profile = creds_set
|
|
69
|
-
set_current_profile(creds_set)
|
|
70
|
-
|
|
71
|
-
def get_current_profile(self) -> str:
|
|
72
|
-
"""
|
|
73
|
-
Get the current credentials profile name.
|
|
74
|
-
|
|
75
|
-
Returns
|
|
76
|
-
-------
|
|
77
|
-
str
|
|
78
|
-
Name of the current credentials profile.
|
|
79
|
-
"""
|
|
80
|
-
return self._profile
|
|
81
|
-
|
|
82
|
-
def load_from_env(self, vars: list[str]) -> dict:
|
|
83
|
-
"""
|
|
84
|
-
Load variables from environment.
|
|
85
|
-
|
|
86
|
-
Parameters
|
|
87
|
-
----------
|
|
88
|
-
vars : list of str
|
|
89
|
-
List of environment variable names to load.
|
|
90
|
-
|
|
91
|
-
Returns
|
|
92
|
-
-------
|
|
93
|
-
dict
|
|
94
|
-
Dictionary of environment variable values.
|
|
95
|
-
"""
|
|
96
|
-
return {var: os.getenv(var) for var in vars}
|
|
97
|
-
|
|
98
|
-
def load_from_file(self, vars: list[str]) -> dict:
|
|
99
|
-
"""
|
|
100
|
-
Load variables from credentials config file.
|
|
101
|
-
|
|
102
|
-
Parameters
|
|
103
|
-
----------
|
|
104
|
-
vars : list of str
|
|
105
|
-
List of variable names to load from file.
|
|
106
|
-
|
|
107
|
-
Returns
|
|
108
|
-
-------
|
|
109
|
-
dict
|
|
110
|
-
Dictionary of variable values from file.
|
|
111
|
-
"""
|
|
112
|
-
file = load_file()
|
|
113
|
-
profile = load_profile(file)
|
|
114
|
-
if profile is not None:
|
|
115
|
-
self._profile = profile
|
|
116
|
-
return {var: load_key(file, self._profile, var) for var in vars}
|
|
117
|
-
|
|
118
|
-
def write_env(self, creds: dict) -> None:
|
|
119
|
-
"""
|
|
120
|
-
Write credentials to the .dhcore file for the current profile.
|
|
121
|
-
|
|
122
|
-
Parameters
|
|
123
|
-
----------
|
|
124
|
-
creds : dict
|
|
125
|
-
Credentials to write.
|
|
126
|
-
"""
|
|
127
|
-
write_config(creds, self._profile)
|
|
128
|
-
|
|
129
|
-
##############################
|
|
130
|
-
# Credentials store methods
|
|
131
|
-
##############################
|
|
132
|
-
|
|
133
|
-
def set_credentials(self, origin: str, creds: dict) -> None:
|
|
134
|
-
"""
|
|
135
|
-
Set credentials for the current profile and origin.
|
|
136
|
-
|
|
137
|
-
Parameters
|
|
138
|
-
----------
|
|
139
|
-
origin : str
|
|
140
|
-
The origin of the credentials ('env' or 'file').
|
|
141
|
-
creds : dict
|
|
142
|
-
Credentials to set.
|
|
143
|
-
"""
|
|
144
|
-
self._creds_store.set_credentials(self._profile, origin, creds)
|
|
145
|
-
|
|
146
|
-
def get_credentials(self, origin: str) -> dict:
|
|
147
|
-
"""
|
|
148
|
-
Get credentials for the current profile from the specified origin.
|
|
149
|
-
|
|
150
|
-
Parameters
|
|
151
|
-
----------
|
|
152
|
-
origin : str
|
|
153
|
-
The origin to get credentials from ('env' or 'file').
|
|
154
|
-
|
|
155
|
-
Returns
|
|
156
|
-
-------
|
|
157
|
-
dict
|
|
158
|
-
Dictionary of credentials.
|
|
159
|
-
"""
|
|
160
|
-
return self._creds_store.get_credentials(self._profile, origin)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
# Define global credential handler
|
|
164
|
-
creds_handler = CredentialHandler()
|
|
@@ -1,77 +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
|
-
if origin == CredsOrigin.ENV.value:
|
|
47
|
-
for key, value in credentials.items():
|
|
48
|
-
self._env_creds[key] = value
|
|
49
|
-
return
|
|
50
|
-
if profile not in self._file_creds:
|
|
51
|
-
self._file_creds[profile] = {}
|
|
52
|
-
for key, value in credentials.items():
|
|
53
|
-
self._file_creds[profile][key] = value
|
|
54
|
-
|
|
55
|
-
def get_credentials(
|
|
56
|
-
self,
|
|
57
|
-
profile: str,
|
|
58
|
-
origin: str,
|
|
59
|
-
) -> dict[str, Any]:
|
|
60
|
-
"""
|
|
61
|
-
Get all credentials for a given profile and origin.
|
|
62
|
-
|
|
63
|
-
Parameters
|
|
64
|
-
----------
|
|
65
|
-
profile : str
|
|
66
|
-
Name of the credentials profile.
|
|
67
|
-
origin : str
|
|
68
|
-
Origin of the credentials ('env' or 'file').
|
|
69
|
-
|
|
70
|
-
Returns
|
|
71
|
-
-------
|
|
72
|
-
dict of str to Any
|
|
73
|
-
Dictionary of credentials for the profile and origin.
|
|
74
|
-
"""
|
|
75
|
-
if origin == CredsOrigin.ENV.value:
|
|
76
|
-
return self._env_creds
|
|
77
|
-
return self._file_creds[profile]
|
digitalhub/stores/data/enums.py
DELETED
|
@@ -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"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|