digitalhub 0.14.0b2__py3-none-any.whl → 0.14.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.
- digitalhub/context/builder.py +0 -4
- digitalhub/context/context.py +12 -8
- digitalhub/entities/_base/_base/entity.py +0 -4
- digitalhub/entities/_base/context/entity.py +1 -1
- digitalhub/entities/_base/entity/entity.py +0 -8
- digitalhub/entities/_base/executable/entity.py +161 -79
- digitalhub/entities/_base/material/entity.py +7 -23
- digitalhub/entities/_base/material/utils.py +28 -0
- digitalhub/entities/_base/unversioned/entity.py +1 -1
- digitalhub/entities/_base/versioned/entity.py +1 -1
- digitalhub/entities/_commons/enums.py +0 -31
- digitalhub/entities/_constructors/_resources.py +151 -0
- digitalhub/entities/_constructors/name.py +18 -0
- digitalhub/entities/_processors/base/__init__.py +3 -0
- digitalhub/entities/_processors/{base.py → base/crud.py} +7 -227
- digitalhub/entities/_processors/base/import_export.py +122 -0
- digitalhub/entities/_processors/base/processor.py +302 -0
- digitalhub/entities/_processors/base/special_ops.py +108 -0
- digitalhub/entities/_processors/context/__init__.py +3 -0
- digitalhub/entities/_processors/context/crud.py +654 -0
- digitalhub/entities/_processors/context/import_export.py +242 -0
- digitalhub/entities/_processors/context/material.py +123 -0
- digitalhub/entities/_processors/context/processor.py +400 -0
- digitalhub/entities/_processors/context/special_ops.py +476 -0
- digitalhub/entities/_processors/processors.py +12 -0
- digitalhub/entities/_processors/utils.py +2 -1
- digitalhub/entities/artifact/crud.py +45 -41
- digitalhub/entities/dataitem/crud.py +45 -37
- digitalhub/entities/dataitem/table/entity.py +5 -6
- digitalhub/entities/function/crud.py +47 -43
- digitalhub/entities/model/_base/entity.py +3 -23
- digitalhub/entities/model/crud.py +45 -39
- digitalhub/entities/project/_base/entity.py +45 -134
- digitalhub/entities/project/crud.py +13 -42
- digitalhub/entities/run/_base/builder.py +0 -4
- digitalhub/entities/run/_base/entity.py +4 -60
- digitalhub/entities/run/crud.py +61 -40
- digitalhub/entities/secret/_base/entity.py +1 -5
- digitalhub/entities/secret/crud.py +14 -42
- digitalhub/entities/task/_base/builder.py +0 -4
- digitalhub/entities/task/_base/entity.py +1 -1
- digitalhub/entities/task/crud.py +47 -44
- digitalhub/entities/trigger/_base/entity.py +1 -5
- digitalhub/entities/trigger/crud.py +51 -43
- digitalhub/entities/workflow/crud.py +47 -40
- digitalhub/factory/registry.py +0 -24
- digitalhub/stores/client/_base/enums.py +39 -0
- digitalhub/stores/client/_base/key_builder.py +1 -1
- digitalhub/stores/client/_base/params_builder.py +48 -0
- digitalhub/stores/client/dhcore/api_builder.py +2 -1
- digitalhub/stores/client/dhcore/client.py +67 -73
- digitalhub/stores/client/dhcore/configurator.py +5 -28
- digitalhub/stores/client/dhcore/error_parser.py +0 -4
- digitalhub/stores/client/dhcore/params_builder.py +130 -75
- digitalhub/stores/client/local/api_builder.py +1 -1
- digitalhub/stores/client/local/params_builder.py +18 -41
- digitalhub/stores/credentials/configurator.py +0 -24
- digitalhub/stores/credentials/handler.py +0 -12
- digitalhub/stores/credentials/store.py +0 -4
- digitalhub/stores/data/_base/store.py +0 -16
- digitalhub/stores/data/builder.py +0 -4
- digitalhub/stores/data/remote/store.py +0 -4
- digitalhub/stores/data/s3/configurator.py +0 -8
- digitalhub/stores/data/s3/store.py +8 -17
- digitalhub/stores/data/sql/configurator.py +0 -8
- digitalhub/stores/data/sql/store.py +0 -4
- digitalhub/stores/readers/data/factory.py +0 -8
- digitalhub/stores/readers/data/pandas/reader.py +0 -16
- digitalhub/utils/io_utils.py +0 -4
- {digitalhub-0.14.0b2.dist-info → digitalhub-0.14.0b4.dist-info}/METADATA +1 -1
- {digitalhub-0.14.0b2.dist-info → digitalhub-0.14.0b4.dist-info}/RECORD +74 -62
- digitalhub/entities/_processors/context.py +0 -1499
- {digitalhub-0.14.0b2.dist-info → digitalhub-0.14.0b4.dist-info}/WHEEL +0 -0
- {digitalhub-0.14.0b2.dist-info → digitalhub-0.14.0b4.dist-info}/licenses/AUTHORS +0 -0
- {digitalhub-0.14.0b2.dist-info → digitalhub-0.14.0b4.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,476 @@
|
|
|
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 typing
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from digitalhub.entities._processors.utils import get_context_from_project
|
|
11
|
+
from digitalhub.stores.client._base.enums import ApiCategories, BackendOperations
|
|
12
|
+
|
|
13
|
+
if typing.TYPE_CHECKING:
|
|
14
|
+
from digitalhub.entities._base.context.entity import ContextEntity
|
|
15
|
+
from digitalhub.entities._processors.context.crud import ContextEntityCRUDProcessor
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ContextEntitySpecialOpsProcessor:
|
|
19
|
+
"""
|
|
20
|
+
Processor for specialized context entity operations.
|
|
21
|
+
|
|
22
|
+
Handles backend operations like secrets management, logging,
|
|
23
|
+
entity control (start/stop/resume), file operations, and metrics.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def build_context_entity_key(
|
|
27
|
+
self,
|
|
28
|
+
project: str,
|
|
29
|
+
entity_type: str,
|
|
30
|
+
entity_kind: str,
|
|
31
|
+
entity_name: str,
|
|
32
|
+
entity_id: str | None = None,
|
|
33
|
+
) -> str:
|
|
34
|
+
"""
|
|
35
|
+
Build a storage key for a context entity.
|
|
36
|
+
|
|
37
|
+
Creates a standardized key string for context entity identification
|
|
38
|
+
and storage, resolving the project context automatically.
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
project : str
|
|
43
|
+
The project name containing the entity.
|
|
44
|
+
entity_type : str
|
|
45
|
+
The type of entity.
|
|
46
|
+
entity_kind : str
|
|
47
|
+
The kind/subtype of entity.
|
|
48
|
+
entity_name : str
|
|
49
|
+
The name of the entity.
|
|
50
|
+
entity_id : str, optional
|
|
51
|
+
The unique identifier of the entity version.
|
|
52
|
+
|
|
53
|
+
Returns
|
|
54
|
+
-------
|
|
55
|
+
str
|
|
56
|
+
The constructed context entity key string.
|
|
57
|
+
"""
|
|
58
|
+
context = get_context_from_project(project)
|
|
59
|
+
return context.client.build_key(
|
|
60
|
+
ApiCategories.CONTEXT.value,
|
|
61
|
+
project=context.name,
|
|
62
|
+
entity_type=entity_type,
|
|
63
|
+
entity_kind=entity_kind,
|
|
64
|
+
entity_name=entity_name,
|
|
65
|
+
entity_id=entity_id,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def read_secret_data(
|
|
69
|
+
self,
|
|
70
|
+
project: str,
|
|
71
|
+
entity_type: str,
|
|
72
|
+
**kwargs,
|
|
73
|
+
) -> dict:
|
|
74
|
+
"""
|
|
75
|
+
Read secret data from the backend.
|
|
76
|
+
|
|
77
|
+
Retrieves secret data stored in the backend for a specific
|
|
78
|
+
project and entity type.
|
|
79
|
+
|
|
80
|
+
Parameters
|
|
81
|
+
----------
|
|
82
|
+
project : str
|
|
83
|
+
The project name containing the secrets.
|
|
84
|
+
entity_type : str
|
|
85
|
+
The type of entity (typically 'secret').
|
|
86
|
+
**kwargs : dict
|
|
87
|
+
Additional parameters to pass to the API call.
|
|
88
|
+
|
|
89
|
+
Returns
|
|
90
|
+
-------
|
|
91
|
+
dict
|
|
92
|
+
Secret data retrieved from the backend.
|
|
93
|
+
"""
|
|
94
|
+
context = get_context_from_project(project)
|
|
95
|
+
api = context.client.build_api(
|
|
96
|
+
ApiCategories.CONTEXT.value,
|
|
97
|
+
BackendOperations.DATA.value,
|
|
98
|
+
project=context.name,
|
|
99
|
+
entity_type=entity_type,
|
|
100
|
+
)
|
|
101
|
+
return context.client.read_object(api, **kwargs)
|
|
102
|
+
|
|
103
|
+
def update_secret_data(
|
|
104
|
+
self,
|
|
105
|
+
project: str,
|
|
106
|
+
entity_type: str,
|
|
107
|
+
data: dict,
|
|
108
|
+
**kwargs,
|
|
109
|
+
) -> None:
|
|
110
|
+
"""
|
|
111
|
+
Update secret data in the backend.
|
|
112
|
+
|
|
113
|
+
Stores or updates secret data in the backend for a specific
|
|
114
|
+
project and entity type.
|
|
115
|
+
|
|
116
|
+
Parameters
|
|
117
|
+
----------
|
|
118
|
+
project : str
|
|
119
|
+
The project name to store secrets in.
|
|
120
|
+
entity_type : str
|
|
121
|
+
The type of entity (typically 'secret').
|
|
122
|
+
data : dict
|
|
123
|
+
The secret data dictionary to store.
|
|
124
|
+
**kwargs : dict
|
|
125
|
+
Additional parameters to pass to the API call.
|
|
126
|
+
"""
|
|
127
|
+
context = get_context_from_project(project)
|
|
128
|
+
api = context.client.build_api(
|
|
129
|
+
ApiCategories.CONTEXT.value,
|
|
130
|
+
BackendOperations.DATA.value,
|
|
131
|
+
project=context.name,
|
|
132
|
+
entity_type=entity_type,
|
|
133
|
+
)
|
|
134
|
+
context.client.update_object(api, data, **kwargs)
|
|
135
|
+
|
|
136
|
+
def read_run_logs(
|
|
137
|
+
self,
|
|
138
|
+
project: str,
|
|
139
|
+
entity_type: str,
|
|
140
|
+
entity_id: str,
|
|
141
|
+
**kwargs,
|
|
142
|
+
) -> dict:
|
|
143
|
+
"""
|
|
144
|
+
Read execution logs from the backend.
|
|
145
|
+
|
|
146
|
+
Retrieves logs for a specific run or task execution from
|
|
147
|
+
the backend.
|
|
148
|
+
|
|
149
|
+
Parameters
|
|
150
|
+
----------
|
|
151
|
+
project : str
|
|
152
|
+
The project name containing the entity.
|
|
153
|
+
entity_type : str
|
|
154
|
+
The type of entity (typically 'run' or 'task').
|
|
155
|
+
entity_id : str
|
|
156
|
+
The unique identifier of the entity to get logs for.
|
|
157
|
+
**kwargs : dict
|
|
158
|
+
Additional parameters to pass to the API call.
|
|
159
|
+
|
|
160
|
+
Returns
|
|
161
|
+
-------
|
|
162
|
+
dict
|
|
163
|
+
Log data retrieved from the backend.
|
|
164
|
+
"""
|
|
165
|
+
context = get_context_from_project(project)
|
|
166
|
+
api = context.client.build_api(
|
|
167
|
+
ApiCategories.CONTEXT.value,
|
|
168
|
+
BackendOperations.LOGS.value,
|
|
169
|
+
project=context.name,
|
|
170
|
+
entity_type=entity_type,
|
|
171
|
+
entity_id=entity_id,
|
|
172
|
+
)
|
|
173
|
+
return context.client.read_object(api, **kwargs)
|
|
174
|
+
|
|
175
|
+
def stop_entity(
|
|
176
|
+
self,
|
|
177
|
+
project: str,
|
|
178
|
+
entity_type: str,
|
|
179
|
+
entity_id: str,
|
|
180
|
+
**kwargs,
|
|
181
|
+
) -> None:
|
|
182
|
+
"""
|
|
183
|
+
Stop a running entity in the backend.
|
|
184
|
+
|
|
185
|
+
Sends a stop signal to halt execution of a running entity
|
|
186
|
+
such as a workflow or long-running task.
|
|
187
|
+
|
|
188
|
+
Parameters
|
|
189
|
+
----------
|
|
190
|
+
project : str
|
|
191
|
+
The project name containing the entity.
|
|
192
|
+
entity_type : str
|
|
193
|
+
The type of entity to stop.
|
|
194
|
+
entity_id : str
|
|
195
|
+
The unique identifier of the entity to stop.
|
|
196
|
+
**kwargs : dict
|
|
197
|
+
Additional parameters to pass to the API call.
|
|
198
|
+
"""
|
|
199
|
+
context = get_context_from_project(project)
|
|
200
|
+
api = context.client.build_api(
|
|
201
|
+
ApiCategories.CONTEXT.value,
|
|
202
|
+
BackendOperations.STOP.value,
|
|
203
|
+
project=context.name,
|
|
204
|
+
entity_type=entity_type,
|
|
205
|
+
entity_id=entity_id,
|
|
206
|
+
)
|
|
207
|
+
context.client.create_object(api, **kwargs)
|
|
208
|
+
|
|
209
|
+
def resume_entity(
|
|
210
|
+
self,
|
|
211
|
+
project: str,
|
|
212
|
+
entity_type: str,
|
|
213
|
+
entity_id: str,
|
|
214
|
+
**kwargs,
|
|
215
|
+
) -> None:
|
|
216
|
+
"""
|
|
217
|
+
Resume a stopped entity in the backend.
|
|
218
|
+
|
|
219
|
+
Sends a resume signal to restart execution of a previously
|
|
220
|
+
stopped entity such as a workflow or task.
|
|
221
|
+
|
|
222
|
+
Parameters
|
|
223
|
+
----------
|
|
224
|
+
project : str
|
|
225
|
+
The project name containing the entity.
|
|
226
|
+
entity_type : str
|
|
227
|
+
The type of entity to resume.
|
|
228
|
+
entity_id : str
|
|
229
|
+
The unique identifier of the entity to resume.
|
|
230
|
+
**kwargs : dict
|
|
231
|
+
Additional parameters to pass to the API call.
|
|
232
|
+
"""
|
|
233
|
+
context = get_context_from_project(project)
|
|
234
|
+
api = context.client.build_api(
|
|
235
|
+
ApiCategories.CONTEXT.value,
|
|
236
|
+
BackendOperations.RESUME.value,
|
|
237
|
+
project=context.name,
|
|
238
|
+
entity_type=entity_type,
|
|
239
|
+
entity_id=entity_id,
|
|
240
|
+
)
|
|
241
|
+
context.client.create_object(api, **kwargs)
|
|
242
|
+
|
|
243
|
+
def read_files_info(
|
|
244
|
+
self,
|
|
245
|
+
project: str,
|
|
246
|
+
entity_type: str,
|
|
247
|
+
entity_id: str,
|
|
248
|
+
**kwargs,
|
|
249
|
+
) -> list[dict]:
|
|
250
|
+
"""
|
|
251
|
+
Read file information from the backend.
|
|
252
|
+
|
|
253
|
+
Retrieves metadata about files associated with an entity,
|
|
254
|
+
including file paths, sizes, and other attributes.
|
|
255
|
+
|
|
256
|
+
Parameters
|
|
257
|
+
----------
|
|
258
|
+
project : str
|
|
259
|
+
The project name containing the entity.
|
|
260
|
+
entity_type : str
|
|
261
|
+
The type of entity to get file info for.
|
|
262
|
+
entity_id : str
|
|
263
|
+
The unique identifier of the entity.
|
|
264
|
+
**kwargs : dict
|
|
265
|
+
Additional parameters to pass to the API call.
|
|
266
|
+
|
|
267
|
+
Returns
|
|
268
|
+
-------
|
|
269
|
+
list[dict]
|
|
270
|
+
List of file information dictionaries from the backend.
|
|
271
|
+
"""
|
|
272
|
+
context = get_context_from_project(project)
|
|
273
|
+
api = context.client.build_api(
|
|
274
|
+
ApiCategories.CONTEXT.value,
|
|
275
|
+
BackendOperations.FILES.value,
|
|
276
|
+
project=context.name,
|
|
277
|
+
entity_type=entity_type,
|
|
278
|
+
entity_id=entity_id,
|
|
279
|
+
)
|
|
280
|
+
return context.client.read_object(api, **kwargs)
|
|
281
|
+
|
|
282
|
+
def update_files_info(
|
|
283
|
+
self,
|
|
284
|
+
project: str,
|
|
285
|
+
entity_type: str,
|
|
286
|
+
entity_id: str,
|
|
287
|
+
entity_list: list[dict],
|
|
288
|
+
**kwargs,
|
|
289
|
+
) -> None:
|
|
290
|
+
"""
|
|
291
|
+
Get files info from backend.
|
|
292
|
+
|
|
293
|
+
Parameters
|
|
294
|
+
----------
|
|
295
|
+
project : str
|
|
296
|
+
Project name.
|
|
297
|
+
entity_type : str
|
|
298
|
+
Entity type.
|
|
299
|
+
entity_id : str
|
|
300
|
+
Entity ID.
|
|
301
|
+
entity_list : list[dict]
|
|
302
|
+
Entity list.
|
|
303
|
+
**kwargs : dict
|
|
304
|
+
Parameters to pass to the API call.
|
|
305
|
+
"""
|
|
306
|
+
context = get_context_from_project(project)
|
|
307
|
+
api = context.client.build_api(
|
|
308
|
+
ApiCategories.CONTEXT.value,
|
|
309
|
+
BackendOperations.FILES.value,
|
|
310
|
+
project=context.name,
|
|
311
|
+
entity_type=entity_type,
|
|
312
|
+
entity_id=entity_id,
|
|
313
|
+
)
|
|
314
|
+
return context.client.update_object(api, entity_list, **kwargs)
|
|
315
|
+
|
|
316
|
+
def read_metrics(
|
|
317
|
+
self,
|
|
318
|
+
project: str,
|
|
319
|
+
entity_type: str,
|
|
320
|
+
entity_id: str,
|
|
321
|
+
metric_name: str | None = None,
|
|
322
|
+
**kwargs,
|
|
323
|
+
) -> dict:
|
|
324
|
+
"""
|
|
325
|
+
Read metrics from the backend for a specific entity.
|
|
326
|
+
|
|
327
|
+
Retrieves metrics data associated with an entity. Can fetch either
|
|
328
|
+
all metrics or a specific metric by name. Used for performance
|
|
329
|
+
monitoring and analysis of entity operations.
|
|
330
|
+
|
|
331
|
+
Parameters
|
|
332
|
+
----------
|
|
333
|
+
project : str
|
|
334
|
+
The project name containing the entity.
|
|
335
|
+
entity_type : str
|
|
336
|
+
The type of entity to read metrics from.
|
|
337
|
+
entity_id : str
|
|
338
|
+
The unique identifier of the entity.
|
|
339
|
+
metric_name : str, optional
|
|
340
|
+
The name of a specific metric to retrieve.
|
|
341
|
+
If None, retrieves all available metrics.
|
|
342
|
+
**kwargs : dict
|
|
343
|
+
Additional parameters to pass to the API call.
|
|
344
|
+
|
|
345
|
+
Returns
|
|
346
|
+
-------
|
|
347
|
+
dict
|
|
348
|
+
Dictionary containing metric data from the backend.
|
|
349
|
+
"""
|
|
350
|
+
context = get_context_from_project(project)
|
|
351
|
+
api = context.client.build_api(
|
|
352
|
+
ApiCategories.CONTEXT.value,
|
|
353
|
+
BackendOperations.METRICS.value,
|
|
354
|
+
project=context.name,
|
|
355
|
+
entity_type=entity_type,
|
|
356
|
+
entity_id=entity_id,
|
|
357
|
+
metric_name=metric_name,
|
|
358
|
+
)
|
|
359
|
+
return context.client.read_object(api, **kwargs)
|
|
360
|
+
|
|
361
|
+
def update_metric(
|
|
362
|
+
self,
|
|
363
|
+
project: str,
|
|
364
|
+
entity_type: str,
|
|
365
|
+
entity_id: str,
|
|
366
|
+
metric_name: str,
|
|
367
|
+
metric_value: Any,
|
|
368
|
+
**kwargs,
|
|
369
|
+
) -> None:
|
|
370
|
+
"""
|
|
371
|
+
Update or create a metric value for an entity in the backend.
|
|
372
|
+
|
|
373
|
+
Updates an existing metric or creates a new one with the specified
|
|
374
|
+
value. Metrics are used for tracking performance, status, and
|
|
375
|
+
other quantitative aspects of entity operations.
|
|
376
|
+
|
|
377
|
+
Parameters
|
|
378
|
+
----------
|
|
379
|
+
project : str
|
|
380
|
+
The project name containing the entity.
|
|
381
|
+
entity_type : str
|
|
382
|
+
The type of entity to update metrics for.
|
|
383
|
+
entity_id : str
|
|
384
|
+
The unique identifier of the entity.
|
|
385
|
+
metric_name : str
|
|
386
|
+
The name of the metric to update or create.
|
|
387
|
+
metric_value : Any
|
|
388
|
+
The value to set for the metric.
|
|
389
|
+
Can be numeric, string, or other supported types.
|
|
390
|
+
**kwargs : dict
|
|
391
|
+
Additional parameters to pass to the API call.
|
|
392
|
+
"""
|
|
393
|
+
context = get_context_from_project(project)
|
|
394
|
+
api = context.client.build_api(
|
|
395
|
+
ApiCategories.CONTEXT.value,
|
|
396
|
+
BackendOperations.METRICS.value,
|
|
397
|
+
project=context.name,
|
|
398
|
+
entity_type=entity_type,
|
|
399
|
+
entity_id=entity_id,
|
|
400
|
+
metric_name=metric_name,
|
|
401
|
+
)
|
|
402
|
+
context.client.update_object(api, metric_value, **kwargs)
|
|
403
|
+
|
|
404
|
+
def search_entity(
|
|
405
|
+
self,
|
|
406
|
+
crud_processor: ContextEntityCRUDProcessor,
|
|
407
|
+
project: str,
|
|
408
|
+
query: str | None = None,
|
|
409
|
+
entity_types: list[str] | None = None,
|
|
410
|
+
name: str | None = None,
|
|
411
|
+
kind: str | None = None,
|
|
412
|
+
created: str | None = None,
|
|
413
|
+
updated: str | None = None,
|
|
414
|
+
description: str | None = None,
|
|
415
|
+
labels: list[str] | None = None,
|
|
416
|
+
**kwargs,
|
|
417
|
+
) -> list[ContextEntity]:
|
|
418
|
+
"""
|
|
419
|
+
Search for entities in the backend using various criteria.
|
|
420
|
+
|
|
421
|
+
Performs a flexible search across multiple entity attributes,
|
|
422
|
+
allowing for complex queries and filtering. Returns matching
|
|
423
|
+
entities from the project context.
|
|
424
|
+
|
|
425
|
+
Parameters
|
|
426
|
+
----------
|
|
427
|
+
crud_processor : ContextEntityCRUDProcessor
|
|
428
|
+
The CRUD processor instance for entity operations.
|
|
429
|
+
project : str
|
|
430
|
+
The project name to search within.
|
|
431
|
+
query : str, optional
|
|
432
|
+
Free-text search query to match against entity content.
|
|
433
|
+
entity_types : list[str], optional
|
|
434
|
+
List of entity types to filter by.
|
|
435
|
+
If None, searches all entity types.
|
|
436
|
+
name : str, optional
|
|
437
|
+
Entity name pattern to match.
|
|
438
|
+
kind : str, optional
|
|
439
|
+
Entity kind to filter by.
|
|
440
|
+
created : str, optional
|
|
441
|
+
Creation date filter (ISO format).
|
|
442
|
+
updated : str, optional
|
|
443
|
+
Last update date filter (ISO format).
|
|
444
|
+
description : str, optional
|
|
445
|
+
Description pattern to match.
|
|
446
|
+
labels : list[str], optional
|
|
447
|
+
List of label patterns to match.
|
|
448
|
+
**kwargs : dict
|
|
449
|
+
Additional search parameters to pass to the API call.
|
|
450
|
+
|
|
451
|
+
Returns
|
|
452
|
+
-------
|
|
453
|
+
list[ContextEntity]
|
|
454
|
+
List of matching entity instances from the search.
|
|
455
|
+
"""
|
|
456
|
+
context = get_context_from_project(project)
|
|
457
|
+
kwargs = context.client.build_parameters(
|
|
458
|
+
ApiCategories.CONTEXT.value,
|
|
459
|
+
BackendOperations.SEARCH.value,
|
|
460
|
+
query=query,
|
|
461
|
+
entity_types=entity_types,
|
|
462
|
+
name=name,
|
|
463
|
+
kind=kind,
|
|
464
|
+
created=created,
|
|
465
|
+
updated=updated,
|
|
466
|
+
description=description,
|
|
467
|
+
labels=labels,
|
|
468
|
+
**kwargs,
|
|
469
|
+
)
|
|
470
|
+
api = context.client.build_api(
|
|
471
|
+
ApiCategories.CONTEXT.value,
|
|
472
|
+
BackendOperations.SEARCH.value,
|
|
473
|
+
project=context.name,
|
|
474
|
+
)
|
|
475
|
+
entities_dict = context.client.read_object(api, **kwargs)
|
|
476
|
+
return [crud_processor.read_context_entity(entity["key"]) for entity in entities_dict["content"]]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._processors.base.processor import BaseEntityOperationsProcessor
|
|
6
|
+
from digitalhub.entities._processors.context.processor import ContextEntityOperationsProcessor
|
|
7
|
+
|
|
8
|
+
# Base processor singleton instance
|
|
9
|
+
base_processor = BaseEntityOperationsProcessor()
|
|
10
|
+
|
|
11
|
+
# Context processor singleton instance
|
|
12
|
+
context_processor = ContextEntityOperationsProcessor()
|
|
@@ -7,9 +7,10 @@ from __future__ import annotations
|
|
|
7
7
|
import typing
|
|
8
8
|
|
|
9
9
|
from digitalhub.context.api import get_context
|
|
10
|
-
from digitalhub.entities._commons.enums import
|
|
10
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
11
11
|
from digitalhub.entities._commons.utils import get_project_from_key, is_valid_key, parse_entity_key
|
|
12
12
|
from digitalhub.factory.entity import entity_factory
|
|
13
|
+
from digitalhub.stores.client._base.enums import ApiCategories, BackendOperations
|
|
13
14
|
from digitalhub.stores.client.api import get_client
|
|
14
15
|
from digitalhub.utils.exceptions import ContextError, EntityError, EntityNotExistsError
|
|
15
16
|
|
|
@@ -7,7 +7,7 @@ from __future__ import annotations
|
|
|
7
7
|
import typing
|
|
8
8
|
|
|
9
9
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
10
|
-
from digitalhub.entities._processors.
|
|
10
|
+
from digitalhub.entities._processors.processors import context_processor
|
|
11
11
|
from digitalhub.entities.artifact._base.entity import Artifact
|
|
12
12
|
from digitalhub.entities.artifact.utils import eval_source, process_kwargs
|
|
13
13
|
from digitalhub.utils.types import SourcesOrListOfSources
|
|
@@ -132,7 +132,6 @@ def get_artifact(
|
|
|
132
132
|
identifier: str,
|
|
133
133
|
project: str | None = None,
|
|
134
134
|
entity_id: str | None = None,
|
|
135
|
-
**kwargs,
|
|
136
135
|
) -> Artifact:
|
|
137
136
|
"""
|
|
138
137
|
Get object from backend.
|
|
@@ -145,8 +144,6 @@ def get_artifact(
|
|
|
145
144
|
Project name.
|
|
146
145
|
entity_id : str
|
|
147
146
|
Entity ID.
|
|
148
|
-
**kwargs : dict
|
|
149
|
-
Parameters to pass to the API call.
|
|
150
147
|
|
|
151
148
|
Returns
|
|
152
149
|
-------
|
|
@@ -156,9 +153,7 @@ def get_artifact(
|
|
|
156
153
|
Examples
|
|
157
154
|
--------
|
|
158
155
|
Using entity key:
|
|
159
|
-
>>> obj = get_artifact(
|
|
160
|
-
... "store://my-artifact-key"
|
|
161
|
-
... )
|
|
156
|
+
>>> obj = get_artifact("store://my-artifact-key")
|
|
162
157
|
|
|
163
158
|
Using entity name:
|
|
164
159
|
>>> obj = get_artifact("my-artifact-name"
|
|
@@ -170,14 +165,12 @@ def get_artifact(
|
|
|
170
165
|
entity_type=ENTITY_TYPE,
|
|
171
166
|
project=project,
|
|
172
167
|
entity_id=entity_id,
|
|
173
|
-
**kwargs,
|
|
174
168
|
)
|
|
175
169
|
|
|
176
170
|
|
|
177
171
|
def get_artifact_versions(
|
|
178
172
|
identifier: str,
|
|
179
173
|
project: str | None = None,
|
|
180
|
-
**kwargs,
|
|
181
174
|
) -> list[Artifact]:
|
|
182
175
|
"""
|
|
183
176
|
Get object versions from backend.
|
|
@@ -188,8 +181,6 @@ def get_artifact_versions(
|
|
|
188
181
|
Entity key (store://...) or entity name.
|
|
189
182
|
project : str
|
|
190
183
|
Project name.
|
|
191
|
-
**kwargs : dict
|
|
192
|
-
Parameters to pass to the API call.
|
|
193
184
|
|
|
194
185
|
Returns
|
|
195
186
|
-------
|
|
@@ -199,9 +190,7 @@ def get_artifact_versions(
|
|
|
199
190
|
Examples
|
|
200
191
|
--------
|
|
201
192
|
Using entity key:
|
|
202
|
-
>>> obj = get_artifact_versions(
|
|
203
|
-
... "store://my-artifact-key"
|
|
204
|
-
... )
|
|
193
|
+
>>> obj = get_artifact_versions("store://my-artifact-key")
|
|
205
194
|
|
|
206
195
|
Using entity name:
|
|
207
196
|
>>> obj = get_artifact_versions("my-artifact-name"
|
|
@@ -211,11 +200,20 @@ def get_artifact_versions(
|
|
|
211
200
|
identifier=identifier,
|
|
212
201
|
entity_type=ENTITY_TYPE,
|
|
213
202
|
project=project,
|
|
214
|
-
**kwargs,
|
|
215
203
|
)
|
|
216
204
|
|
|
217
205
|
|
|
218
|
-
def list_artifacts(
|
|
206
|
+
def list_artifacts(
|
|
207
|
+
project: str,
|
|
208
|
+
q: str | None = None,
|
|
209
|
+
name: str | None = None,
|
|
210
|
+
kind: str | None = None,
|
|
211
|
+
user: str | None = None,
|
|
212
|
+
state: str | None = None,
|
|
213
|
+
created: str | None = None,
|
|
214
|
+
updated: str | None = None,
|
|
215
|
+
version: str | None = None,
|
|
216
|
+
) -> list[Artifact]:
|
|
219
217
|
"""
|
|
220
218
|
List all latest version objects from backend.
|
|
221
219
|
|
|
@@ -223,8 +221,22 @@ def list_artifacts(project: str, **kwargs) -> list[Artifact]:
|
|
|
223
221
|
----------
|
|
224
222
|
project : str
|
|
225
223
|
Project name.
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
q : str
|
|
225
|
+
Query string to filter objects.
|
|
226
|
+
name : str
|
|
227
|
+
Object name.
|
|
228
|
+
kind : str
|
|
229
|
+
Kind of the object.
|
|
230
|
+
user : str
|
|
231
|
+
User that created the object.
|
|
232
|
+
state : str
|
|
233
|
+
Object state.
|
|
234
|
+
created : str
|
|
235
|
+
Creation date filter.
|
|
236
|
+
updated : str
|
|
237
|
+
Update date filter.
|
|
238
|
+
version : str
|
|
239
|
+
Object version, default is latest.
|
|
228
240
|
|
|
229
241
|
Returns
|
|
230
242
|
-------
|
|
@@ -233,14 +245,19 @@ def list_artifacts(project: str, **kwargs) -> list[Artifact]:
|
|
|
233
245
|
|
|
234
246
|
Examples
|
|
235
247
|
--------
|
|
236
|
-
>>> objs = list_artifacts(
|
|
237
|
-
... project="my-project"
|
|
238
|
-
... )
|
|
248
|
+
>>> objs = list_artifacts(project="my-project")
|
|
239
249
|
"""
|
|
240
250
|
return context_processor.list_context_entities(
|
|
241
251
|
project=project,
|
|
242
252
|
entity_type=ENTITY_TYPE,
|
|
243
|
-
|
|
253
|
+
q=q,
|
|
254
|
+
name=name,
|
|
255
|
+
kind=kind,
|
|
256
|
+
user=user,
|
|
257
|
+
state=state,
|
|
258
|
+
created=created,
|
|
259
|
+
updated=updated,
|
|
260
|
+
version=version,
|
|
244
261
|
)
|
|
245
262
|
|
|
246
263
|
|
|
@@ -271,9 +288,7 @@ def import_artifact(
|
|
|
271
288
|
|
|
272
289
|
Examples
|
|
273
290
|
--------
|
|
274
|
-
>>> obj = import_artifact(
|
|
275
|
-
... "my-artifact.yaml"
|
|
276
|
-
... )
|
|
291
|
+
>>> obj = import_artifact("my-artifact.yaml")
|
|
277
292
|
"""
|
|
278
293
|
return context_processor.import_context_entity(
|
|
279
294
|
file,
|
|
@@ -299,9 +314,7 @@ def load_artifact(file: str) -> Artifact:
|
|
|
299
314
|
|
|
300
315
|
Examples
|
|
301
316
|
--------
|
|
302
|
-
>>> obj = load_artifact(
|
|
303
|
-
... "my-artifact.yaml"
|
|
304
|
-
... )
|
|
317
|
+
>>> obj = load_artifact("my-artifact.yaml")
|
|
305
318
|
"""
|
|
306
319
|
return context_processor.load_context_entity(file)
|
|
307
320
|
|
|
@@ -322,11 +335,7 @@ def update_artifact(entity: Artifact) -> Artifact:
|
|
|
322
335
|
|
|
323
336
|
Examples
|
|
324
337
|
--------
|
|
325
|
-
>>> obj = (
|
|
326
|
-
... update_artifact(
|
|
327
|
-
... obj
|
|
328
|
-
... )
|
|
329
|
-
... )
|
|
338
|
+
>>> obj = update_artifact(obj)
|
|
330
339
|
"""
|
|
331
340
|
return context_processor.update_context_entity(
|
|
332
341
|
project=entity.project,
|
|
@@ -342,7 +351,6 @@ def delete_artifact(
|
|
|
342
351
|
entity_id: str | None = None,
|
|
343
352
|
delete_all_versions: bool = False,
|
|
344
353
|
cascade: bool = True,
|
|
345
|
-
**kwargs,
|
|
346
354
|
) -> dict:
|
|
347
355
|
"""
|
|
348
356
|
Delete object from backend.
|
|
@@ -356,11 +364,10 @@ def delete_artifact(
|
|
|
356
364
|
entity_id : str
|
|
357
365
|
Entity ID.
|
|
358
366
|
delete_all_versions : bool
|
|
359
|
-
Delete all versions of the named entity.
|
|
367
|
+
Delete all versions of the named entity.
|
|
368
|
+
If True, use entity name instead of entity key as identifier.
|
|
360
369
|
cascade : bool
|
|
361
370
|
Cascade delete.
|
|
362
|
-
**kwargs : dict
|
|
363
|
-
Parameters to pass to the API call.
|
|
364
371
|
|
|
365
372
|
Returns
|
|
366
373
|
-------
|
|
@@ -370,9 +377,7 @@ def delete_artifact(
|
|
|
370
377
|
Examples
|
|
371
378
|
--------
|
|
372
379
|
If delete_all_versions is False:
|
|
373
|
-
>>> delete_artifact(
|
|
374
|
-
... "store://my-artifact-key"
|
|
375
|
-
... )
|
|
380
|
+
>>> delete_artifact("store://my-artifact-key")
|
|
376
381
|
|
|
377
382
|
Otherwise:
|
|
378
383
|
>>> delete_artifact("my-artifact-name",
|
|
@@ -386,5 +391,4 @@ def delete_artifact(
|
|
|
386
391
|
entity_id=entity_id,
|
|
387
392
|
delete_all_versions=delete_all_versions,
|
|
388
393
|
cascade=cascade,
|
|
389
|
-
**kwargs,
|
|
390
394
|
)
|