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,62 +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.key_builder import ClientKeyBuilder
8
-
9
-
10
- class ClientDHCoreKeyBuilder(ClientKeyBuilder):
11
- """
12
- Class that build the key of entities.
13
- """
14
-
15
- def base_entity_key(self, entity_id: str) -> str:
16
- """
17
- Build for base entity key.
18
-
19
- Parameters
20
- ----------
21
- entity_id : str
22
- Entity id.
23
-
24
- Returns
25
- -------
26
- str
27
- Key.
28
- """
29
- return f"store://{entity_id}"
30
-
31
- def context_entity_key(
32
- self,
33
- project: str,
34
- entity_type: str,
35
- entity_kind: str,
36
- entity_name: str,
37
- entity_id: str | None = None,
38
- ) -> str:
39
- """
40
- Build for context entity key.
41
-
42
- Parameters
43
- ----------
44
- project : str
45
- Project name.
46
- entity_type : str
47
- Entity type.
48
- entity_kind : str
49
- Entity kind.
50
- entity_name : str
51
- Entity name.
52
- entity_id : str
53
- Entity ID.
54
-
55
- Returns
56
- -------
57
- str
58
- Key.
59
- """
60
- if entity_id is None:
61
- return f"store://{project}/{entity_type}/{entity_kind}/{entity_name}"
62
- return f"store://{project}/{entity_type}/{entity_kind}/{entity_name}:{entity_id}"
@@ -1,40 +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 pydantic import BaseModel
8
-
9
-
10
- class ClientConfig(BaseModel):
11
- """Client configuration model."""
12
-
13
- endpoint: str
14
- """API endpoint."""
15
-
16
-
17
- class BasicAuth(ClientConfig):
18
- """Basic authentication model."""
19
-
20
- user: str
21
- """Username."""
22
-
23
- password: str
24
- """Basic authentication password."""
25
-
26
-
27
- class OAuth2TokenAuth(ClientConfig):
28
- """OAuth2 token authentication model."""
29
-
30
- access_token: str
31
- """OAuth2 token."""
32
-
33
- refresh_token: str
34
- """OAuth2 refresh token."""
35
-
36
- client_id: str
37
- """OAuth2 client id."""
38
-
39
- issuer_endpoint: str
40
- """OAuth2 issuer endpoint."""
@@ -1,278 +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 ClientDHCoreParametersBuilder(ClientParametersBuilder):
12
- """
13
- Parameter builder for DHCore client API calls.
14
-
15
- This class constructs HTTP request parameters for different DHCore API
16
- operations, handling the specific parameter formats and query structures
17
- required by the DigitalHub Core backend. It supports both base-level
18
- operations (like project management) and context-level operations
19
- (entity operations within projects).
20
-
21
- The builder handles various parameter transformations including:
22
- - Query parameter formatting for different operations
23
- - Search filter construction for Solr-based searches
24
- - Cascade deletion options
25
- - Versioning parameters
26
- - Entity sharing parameters
27
-
28
- Methods
29
- -------
30
- build_parameters(category, operation, **kwargs)
31
- Main entry point for parameter building based on API category.
32
- build_parameters_base(operation, **kwargs)
33
- Builds parameters for base-level API operations.
34
- build_parameters_context(operation, **kwargs)
35
- Builds parameters for context-level API operations.
36
- """
37
-
38
- def build_parameters(self, category: str, operation: str, **kwargs) -> dict:
39
- """
40
- Build HTTP request parameters for DHCore API calls.
41
-
42
- Routes parameter building to the appropriate method based on the
43
- API category (base or context operations) and applies operation-specific
44
- parameter transformations.
45
-
46
- Parameters
47
- ----------
48
- category : str
49
- The API category, either 'base' for project-level operations
50
- or 'context' for entity operations within projects.
51
- operation : str
52
- The specific API operation being performed (create, read, update,
53
- delete, list, search, etc.).
54
- **kwargs : dict
55
- Raw parameters to be transformed into proper HTTP request format.
56
- May include entity identifiers, filter criteria, pagination
57
- options, etc.
58
-
59
- Returns
60
- -------
61
- dict
62
- Formatted parameters dictionary ready for HTTP request, typically
63
- containing a 'params' key with query parameters and other
64
- request-specific parameters.
65
-
66
- Notes
67
- -----
68
- This method acts as a dispatcher, routing to either base or context
69
- parameter building based on the category. All parameter dictionaries
70
- are initialized with a 'params' key for query parameters if not
71
- already present.
72
- """
73
- if category == ApiCategories.BASE.value:
74
- return self.build_parameters_base(operation, **kwargs)
75
- return self.build_parameters_context(operation, **kwargs)
76
-
77
- def build_parameters_base(self, operation: str, **kwargs) -> dict:
78
- """
79
- Build parameters for base-level API operations.
80
-
81
- Constructs HTTP request parameters for operations that work at the
82
- base level of the API, typically project-level operations and
83
- entity sharing functionality.
84
-
85
- Parameters
86
- ----------
87
- operation : str
88
- The API operation being performed. Supported operations:
89
- - DELETE: Project deletion with optional cascade
90
- - SHARE: Entity sharing/unsharing with users
91
- **kwargs : dict
92
- Operation-specific parameters including:
93
- - cascade (bool): For DELETE, whether to cascade delete
94
- - user (str): For SHARE, target user for sharing
95
- - unshare (bool): For SHARE, whether to unshare instead
96
- - id (str): For SHARE unshare, entity ID to unshare
97
-
98
- Returns
99
- -------
100
- dict
101
- Formatted parameters with 'params' containing query parameters
102
- and other request-specific parameters.
103
-
104
- Notes
105
- -----
106
- Parameter transformations:
107
- - CASCADE: Boolean values are converted to lowercase strings
108
- - SHARE: User parameter is moved to query params
109
- - UNSHARE: Requires both unshare=True and entity id
110
- """
111
- kwargs = self._set_params(**kwargs)
112
- if operation == BackendOperations.DELETE.value:
113
- if (cascade := kwargs.pop("cascade", None)) is not None:
114
- kwargs["params"]["cascade"] = str(cascade).lower()
115
- elif operation == BackendOperations.SHARE.value:
116
- kwargs["params"]["user"] = kwargs.pop("user")
117
- if kwargs.pop("unshare", False):
118
- kwargs["params"]["id"] = kwargs.pop("id")
119
-
120
- return kwargs
121
-
122
- def build_parameters_context(self, operation: str, **kwargs) -> dict:
123
- """
124
- Build parameters for context-level API operations.
125
-
126
- Constructs HTTP request parameters for operations that work within
127
- a specific context (project), including entity management and
128
- search functionality.
129
-
130
- Parameters
131
- ----------
132
- operation : str
133
- The API operation being performed. Supported operations:
134
- - SEARCH: Search entities with filtering and pagination
135
- - READ_MANY: Retrieve multiple entities with pagination
136
- - DELETE: Delete specific entity by ID
137
- - READ: Read specific entity by ID (with optional embedded)
138
- **kwargs : dict
139
- Operation-specific parameters including:
140
- - params (dict): Search filters and conditions
141
- - page (int): Page number for pagination (default: 0)
142
- - size (int): Number of items per page (default: 20)
143
- - order_by (str): Field to order results by
144
- - order (str): Order direction ('asc' or 'desc')
145
- - embedded (bool): For READ, whether to include embedded entities
146
- - id (str): For READ/DELETE, entity identifier
147
-
148
- Returns
149
- -------
150
- dict
151
- Formatted parameters with 'params' containing query parameters
152
- and other request-specific parameters like 'id' for entity operations.
153
-
154
- Notes
155
- -----
156
- Search and pagination:
157
- - Filters are applied via 'filter' parameter in query string
158
- - Pagination uses 'page' and 'size' parameters
159
- - Results can be ordered using 'sort' parameter format
160
-
161
- Entity operations:
162
- - READ: Supports embedded entity inclusion via 'embedded' param
163
- - DELETE: Requires entity 'id' parameter
164
- """
165
- kwargs = self._set_params(**kwargs)
166
-
167
- # Handle read
168
- if operation == BackendOperations.READ.value:
169
- name = kwargs.pop("entity_name", None)
170
- if name is not None:
171
- kwargs["params"]["name"] = name
172
- elif operation == BackendOperations.READ_ALL_VERSIONS.value:
173
- kwargs["params"]["versions"] = "all"
174
- kwargs["params"]["name"] = kwargs.pop("entity_name")
175
- # Handle delete
176
- elif operation == BackendOperations.DELETE.value:
177
- # Handle cascade
178
- if (cascade := kwargs.pop("cascade", None)) is not None:
179
- kwargs["params"]["cascade"] = str(cascade).lower()
180
-
181
- # Handle delete all versions
182
- entity_id = kwargs.pop("entity_id")
183
- entity_name = kwargs.pop("entity_name")
184
- if not kwargs.pop("delete_all_versions", False):
185
- if entity_id is None:
186
- raise ValueError(
187
- "If `delete_all_versions` is False, `entity_id` must be provided,"
188
- " either as an argument or in key `identifier`.",
189
- )
190
- else:
191
- kwargs["params"]["name"] = entity_name
192
- # Handle search
193
- elif operation == BackendOperations.SEARCH.value:
194
- # Handle fq
195
- if (fq := kwargs.pop("fq", None)) is not None:
196
- kwargs["params"]["fq"] = fq
197
-
198
- # Add search query
199
- if (query := kwargs.pop("query", None)) is not None:
200
- kwargs["params"]["q"] = query
201
-
202
- # Add search filters
203
- fq = []
204
-
205
- # Entity types
206
- if (entity_types := kwargs.pop("entity_types", None)) is not None:
207
- if not isinstance(entity_types, list):
208
- entity_types = [entity_types]
209
- if len(entity_types) == 1:
210
- entity_types = entity_types[0]
211
- else:
212
- entity_types = " OR ".join(entity_types)
213
- fq.append(f"type:({entity_types})")
214
-
215
- # Name
216
- if (name := kwargs.pop("name", None)) is not None:
217
- fq.append(f'metadata.name:"{name}"')
218
-
219
- # Kind
220
- if (kind := kwargs.pop("kind", None)) is not None:
221
- fq.append(f'kind:"{kind}"')
222
-
223
- # Time
224
- created = kwargs.pop("created", None)
225
- updated = kwargs.pop("updated", None)
226
- created = created if created is not None else "*"
227
- updated = updated if updated is not None else "*"
228
- fq.append(f"metadata.updated:[{created} TO {updated}]")
229
-
230
- # Description
231
- if (description := kwargs.pop("description", None)) is not None:
232
- fq.append(f'metadata.description:"{description}"')
233
-
234
- # Labels
235
- if (labels := kwargs.pop("labels", None)) is not None:
236
- if len(labels) == 1:
237
- labels = labels[0]
238
- else:
239
- labels = " AND ".join(labels)
240
- fq.append(f"metadata.labels:({labels})")
241
-
242
- # Add filters
243
- kwargs["params"]["fq"] = fq
244
-
245
- return kwargs
246
-
247
- @staticmethod
248
- def _set_params(**kwargs) -> dict:
249
- """
250
- Initialize parameter dictionary with query parameters structure.
251
-
252
- Ensures that the parameter dictionary has a 'params' key for
253
- HTTP query parameters. This is a utility method used by all
254
- parameter building methods to guarantee consistent structure.
255
-
256
- Parameters
257
- ----------
258
- **kwargs : dict
259
- Keyword arguments to be formatted. May be empty or contain
260
- various parameters for API operations.
261
-
262
- Returns
263
- -------
264
- dict
265
- Parameters dictionary with guaranteed 'params' key containing
266
- an empty dict if not already present.
267
-
268
- Notes
269
- -----
270
- This method is called at the beginning of all parameter building
271
- methods to ensure consistent dictionary structure for query
272
- parameter handling.
273
- """
274
- if not kwargs:
275
- kwargs = {}
276
- if "params" not in kwargs:
277
- kwargs["params"] = {}
278
- return kwargs
@@ -1,94 +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
- import typing
9
-
10
- from digitalhub.stores.client.api import get_client
11
- from digitalhub.stores.credentials.enums import CredsEnvVar
12
-
13
- if typing.TYPE_CHECKING:
14
- from digitalhub.stores.client.dhcore.client import ClientDHCore
15
-
16
-
17
- def set_dhcore_env(
18
- endpoint: str | None = None,
19
- user: str | None = None,
20
- password: str | None = None,
21
- access_token: str | None = None,
22
- refresh_token: str | None = None,
23
- client_id: str | None = None,
24
- ) -> None:
25
- """
26
- Function to set environment variables for DHCore config.
27
-
28
- Sets the environment variables for DHCore configuration and
29
- reloads the client configurator to use the new settings.
30
- Note that if the environment variable is already set, it
31
- will be overwritten.
32
-
33
- Parameters
34
- ----------
35
- endpoint : str, optional
36
- The endpoint URL of the DHCore backend.
37
- user : str, optional
38
- The username for basic authentication.
39
- password : str, optional
40
- The password for basic authentication.
41
- access_token : str, optional
42
- The OAuth2 access token.
43
- refresh_token : str, optional
44
- The OAuth2 refresh token.
45
- client_id : str, optional
46
- The OAuth2 client identifier.
47
-
48
- Returns
49
- -------
50
- None
51
-
52
- Notes
53
- -----
54
- After setting the environment variables, this function automatically
55
- reloads the client configurator to apply the new configuration.
56
- """
57
- if endpoint is not None:
58
- os.environ[CredsEnvVar.DHCORE_ENDPOINT.value] = endpoint
59
- if user is not None:
60
- os.environ[CredsEnvVar.DHCORE_USER.value] = user
61
- if password is not None:
62
- os.environ[CredsEnvVar.DHCORE_PASSWORD.value] = password
63
- if access_token is not None:
64
- os.environ[CredsEnvVar.DHCORE_ACCESS_TOKEN.value] = access_token
65
- if refresh_token is not None:
66
- os.environ[CredsEnvVar.DHCORE_REFRESH_TOKEN.value] = refresh_token
67
- if client_id is not None:
68
- os.environ[CredsEnvVar.DHCORE_CLIENT_ID.value] = client_id
69
-
70
- client: ClientDHCore = get_client(local=False)
71
- client._configurator.load_env_vars()
72
-
73
-
74
- def refresh_token() -> None:
75
- """
76
- Function to refresh the OAuth2 access token.
77
-
78
- Attempts to refresh the current OAuth2 access token using the
79
- refresh token stored in the client configuration. This function
80
- requires that the client be configured with OAuth2 authentication.
81
-
82
- Returns
83
- -------
84
- None
85
-
86
- Raises
87
- ------
88
- ClientError
89
- If the client is not properly configured or if the token
90
- refresh fails.
91
- """
92
- client: ClientDHCore = get_client(local=False)
93
- client._configurator.check_config()
94
- client._configurator.refresh_credentials()
@@ -1,116 +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.api_builder import ClientApiBuilder
9
- from digitalhub.stores.client.local.enums import LocalClientVar
10
- from digitalhub.utils.exceptions import BackendError
11
-
12
- API_BASE = "/api/v1"
13
- API_CONTEXT = f"{API_BASE}/-"
14
-
15
-
16
- class ClientLocalApiBuilder(ClientApiBuilder):
17
- """
18
- This class is used to build the API for the Local client.
19
- """
20
-
21
- def build_api(self, category: str, operation: str, **kwargs) -> str:
22
- """
23
- Build the API for the client.
24
-
25
- Parameters
26
- ----------
27
- category : str
28
- API category.
29
- operation : str
30
- API operation.
31
- **kwargs : dict
32
- Additional parameters.
33
-
34
- Returns
35
- -------
36
- str
37
- API formatted.
38
- """
39
- if category == ApiCategories.BASE.value:
40
- return self.build_api_base(operation, **kwargs)
41
- return self.build_api_context(operation, **kwargs)
42
-
43
- def build_api_base(self, operation: str, **kwargs) -> str:
44
- """
45
- Build the base API for the client.
46
-
47
- Parameters
48
- ----------
49
- operation : str
50
- API operation.
51
- **kwargs : dict
52
- Additional parameters.
53
-
54
- Returns
55
- -------
56
- str
57
- API formatted.
58
- """
59
- entity_type = kwargs["entity_type"] + "s"
60
- if operation in (
61
- BackendOperations.CREATE.value,
62
- BackendOperations.LIST.value,
63
- ):
64
- return f"{API_BASE}/{entity_type}"
65
- elif operation in (
66
- BackendOperations.READ.value,
67
- BackendOperations.UPDATE.value,
68
- BackendOperations.DELETE.value,
69
- ):
70
- return f"{API_BASE}/{entity_type}/{kwargs['entity_name']}"
71
- raise BackendError(f"API for operation '{operation}' for entity type '{entity_type}' not implemented in Local.")
72
-
73
- def build_api_context(self, operation: str, **kwargs) -> str:
74
- """
75
- Build the context API for the client.
76
-
77
- Parameters
78
- ----------
79
- operation : str
80
- The API operation.
81
- **kwargs : dict
82
- Additional parameters including project, entity_type, entity_id, etc.
83
-
84
- Returns
85
- -------
86
- str
87
- The formatted context API endpoint.
88
-
89
- Raises
90
- ------
91
- BackendError
92
- If the operation is not supported for the entity type.
93
- """
94
- try:
95
- entity_type = kwargs["entity_type"] + "s"
96
- except KeyError:
97
- pass
98
- project = kwargs["project"]
99
- if operation in (
100
- BackendOperations.CREATE.value,
101
- BackendOperations.LIST.value,
102
- ):
103
- return f"{API_CONTEXT}/{project}/{entity_type}"
104
- elif operation in (
105
- BackendOperations.READ.value,
106
- BackendOperations.UPDATE.value,
107
- BackendOperations.DELETE.value,
108
- ):
109
- return f"{API_CONTEXT}/{project}/{entity_type}/{kwargs['entity_id']}"
110
- elif operation in (
111
- BackendOperations.LOGS.value,
112
- BackendOperations.FILES.value,
113
- BackendOperations.METRICS.value,
114
- ):
115
- return LocalClientVar.EMPTY.value
116
- raise BackendError(f"API for operation '{operation}' for entity type '{entity_type}' not implemented in Local.")