digitalhub 0.14.0b1__py3-none-any.whl → 0.14.0b3__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 +9 -21
- digitalhub/entities/_base/material/entity.py +5 -21
- digitalhub/entities/_base/unversioned/entity.py +1 -1
- digitalhub/entities/_base/versioned/entity.py +1 -1
- digitalhub/entities/_processors/base/__init__.py +3 -0
- digitalhub/entities/_processors/{base.py → base/crud.py} +12 -232
- 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 -2
- digitalhub/entities/artifact/crud.py +1 -1
- digitalhub/entities/dataitem/crud.py +6 -3
- digitalhub/entities/dataitem/table/entity.py +24 -1
- digitalhub/entities/dataitem/utils.py +4 -0
- digitalhub/entities/function/_base/entity.py +3 -3
- digitalhub/entities/function/crud.py +1 -1
- digitalhub/entities/model/_base/entity.py +46 -24
- digitalhub/entities/model/crud.py +1 -1
- digitalhub/entities/project/_base/entity.py +3 -12
- digitalhub/entities/project/crud.py +1 -2
- digitalhub/entities/run/_base/builder.py +0 -4
- digitalhub/entities/run/_base/entity.py +53 -66
- digitalhub/entities/run/crud.py +5 -2
- digitalhub/entities/secret/_base/entity.py +1 -5
- digitalhub/entities/secret/crud.py +1 -1
- digitalhub/entities/task/_base/builder.py +0 -4
- digitalhub/entities/task/_base/entity.py +5 -5
- digitalhub/entities/task/crud.py +1 -1
- digitalhub/entities/trigger/_base/entity.py +1 -5
- digitalhub/entities/trigger/crud.py +1 -1
- digitalhub/entities/workflow/_base/entity.py +3 -3
- digitalhub/entities/workflow/crud.py +1 -1
- digitalhub/factory/entity.py +283 -0
- digitalhub/factory/registry.py +197 -0
- digitalhub/factory/runtime.py +44 -0
- digitalhub/runtimes/_base.py +2 -2
- digitalhub/stores/client/dhcore/client.py +0 -14
- digitalhub/stores/client/dhcore/configurator.py +5 -28
- digitalhub/stores/client/dhcore/error_parser.py +0 -4
- digitalhub/stores/credentials/configurator.py +4 -29
- 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 +2 -10
- digitalhub/stores/data/s3/store.py +0 -12
- 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 +9 -19
- digitalhub/utils/io_utils.py +0 -4
- {digitalhub-0.14.0b1.dist-info → digitalhub-0.14.0b3.dist-info}/METADATA +1 -1
- {digitalhub-0.14.0b1.dist-info → digitalhub-0.14.0b3.dist-info}/RECORD +69 -57
- digitalhub/entities/_processors/context.py +0 -1499
- digitalhub/factory/factory.py +0 -460
- {digitalhub-0.14.0b1.dist-info → digitalhub-0.14.0b3.dist-info}/WHEEL +0 -0
- {digitalhub-0.14.0b1.dist-info → digitalhub-0.14.0b3.dist-info}/licenses/AUTHORS +0 -0
- {digitalhub-0.14.0b1.dist-info → digitalhub-0.14.0b3.dist-info}/licenses/LICENSE +0 -0
digitalhub/context/builder.py
CHANGED
digitalhub/context/context.py
CHANGED
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
+
import os
|
|
7
8
|
import typing
|
|
8
9
|
from pathlib import Path
|
|
9
10
|
|
|
11
|
+
from digitalhub.runtimes.enums import RuntimeEnvVar
|
|
12
|
+
|
|
10
13
|
if typing.TYPE_CHECKING:
|
|
11
14
|
from digitalhub.entities.project._base.entity import Project
|
|
12
15
|
from digitalhub.stores.client._base.client import Client
|
|
@@ -47,6 +50,15 @@ class Context:
|
|
|
47
50
|
|
|
48
51
|
self.is_running: bool = False
|
|
49
52
|
self._run_ctx: str | None = None
|
|
53
|
+
self._search_run_ctx()
|
|
54
|
+
|
|
55
|
+
def _search_run_ctx(self) -> None:
|
|
56
|
+
"""
|
|
57
|
+
Search for an existing run id in env.
|
|
58
|
+
"""
|
|
59
|
+
run_id = os.getenv(RuntimeEnvVar.RUN_ID.value)
|
|
60
|
+
if run_id is not None:
|
|
61
|
+
self.set_run(run_id)
|
|
50
62
|
|
|
51
63
|
def set_run(self, run_ctx: str) -> None:
|
|
52
64
|
"""
|
|
@@ -56,10 +68,6 @@ class Context:
|
|
|
56
68
|
----------
|
|
57
69
|
run_ctx : str
|
|
58
70
|
The run key to set.
|
|
59
|
-
|
|
60
|
-
Returns
|
|
61
|
-
-------
|
|
62
|
-
None
|
|
63
71
|
"""
|
|
64
72
|
self.is_running = True
|
|
65
73
|
self._run_ctx = run_ctx
|
|
@@ -67,10 +75,6 @@ class Context:
|
|
|
67
75
|
def unset_run(self) -> None:
|
|
68
76
|
"""
|
|
69
77
|
Clear the current run key and reset running state.
|
|
70
|
-
|
|
71
|
-
Returns
|
|
72
|
-
-------
|
|
73
|
-
None
|
|
74
78
|
"""
|
|
75
79
|
self.is_running = False
|
|
76
80
|
self._run_ctx = None
|
|
@@ -8,7 +8,7 @@ import typing
|
|
|
8
8
|
|
|
9
9
|
from digitalhub.context.api import get_context
|
|
10
10
|
from digitalhub.entities._base.entity.entity import Entity
|
|
11
|
-
from digitalhub.entities._processors.
|
|
11
|
+
from digitalhub.entities._processors.processors import context_processor
|
|
12
12
|
from digitalhub.utils.generic_utils import get_timestamp
|
|
13
13
|
from digitalhub.utils.io_utils import write_yaml
|
|
14
14
|
|
|
@@ -67,10 +67,6 @@ class Entity(Base):
|
|
|
67
67
|
----------
|
|
68
68
|
obj : dict
|
|
69
69
|
Mapping representation of object.
|
|
70
|
-
|
|
71
|
-
Returns
|
|
72
|
-
-------
|
|
73
|
-
None
|
|
74
70
|
"""
|
|
75
71
|
self.metadata = obj.metadata
|
|
76
72
|
self.spec = obj.spec
|
|
@@ -95,10 +91,6 @@ class Entity(Base):
|
|
|
95
91
|
The target entity.
|
|
96
92
|
source : str
|
|
97
93
|
The source entity.
|
|
98
|
-
|
|
99
|
-
Returns
|
|
100
|
-
-------
|
|
101
|
-
None
|
|
102
94
|
"""
|
|
103
95
|
if self.metadata.relationships is None:
|
|
104
96
|
self.metadata.relationships = []
|
|
@@ -9,11 +9,11 @@ from abc import abstractmethod
|
|
|
9
9
|
|
|
10
10
|
from digitalhub.entities._base.versioned.entity import VersionedEntity
|
|
11
11
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
12
|
-
from digitalhub.entities._processors.
|
|
12
|
+
from digitalhub.entities._processors.processors import context_processor
|
|
13
13
|
from digitalhub.entities.run.crud import list_runs
|
|
14
14
|
from digitalhub.entities.task.crud import delete_task, list_tasks
|
|
15
15
|
from digitalhub.entities.trigger.crud import list_triggers
|
|
16
|
-
from digitalhub.factory.
|
|
16
|
+
from digitalhub.factory.entity import entity_factory
|
|
17
17
|
from digitalhub.utils.exceptions import EntityAlreadyExistsError, EntityError
|
|
18
18
|
|
|
19
19
|
if typing.TYPE_CHECKING:
|
|
@@ -94,10 +94,6 @@ class ExecutableEntity(VersionedEntity):
|
|
|
94
94
|
----------
|
|
95
95
|
tasks : list[dict]
|
|
96
96
|
List of tasks to import.
|
|
97
|
-
|
|
98
|
-
Returns
|
|
99
|
-
-------
|
|
100
|
-
None
|
|
101
97
|
"""
|
|
102
98
|
# Loop over tasks list, in the case where the function
|
|
103
99
|
# is imported from local file.
|
|
@@ -109,7 +105,7 @@ class ExecutableEntity(VersionedEntity):
|
|
|
109
105
|
# Create a new object from dictionary.
|
|
110
106
|
# the form in which tasks are stored in function
|
|
111
107
|
# status
|
|
112
|
-
task_obj: Task =
|
|
108
|
+
task_obj: Task = entity_factory.build_entity_from_dict(task)
|
|
113
109
|
|
|
114
110
|
# Try to save it in backend to been able to use
|
|
115
111
|
# it for launching runs. In fact, tasks must be
|
|
@@ -149,7 +145,7 @@ class ExecutableEntity(VersionedEntity):
|
|
|
149
145
|
kwargs["kind"] = kind
|
|
150
146
|
|
|
151
147
|
# Create object instance
|
|
152
|
-
task: Task =
|
|
148
|
+
task: Task = entity_factory.build_entity_from_params(**kwargs)
|
|
153
149
|
task.save()
|
|
154
150
|
|
|
155
151
|
self._tasks[kind] = task
|
|
@@ -225,7 +221,7 @@ class ExecutableEntity(VersionedEntity):
|
|
|
225
221
|
kwargs["uuid"] = self._tasks[kind].id
|
|
226
222
|
|
|
227
223
|
# Update task
|
|
228
|
-
task: Task =
|
|
224
|
+
task: Task = entity_factory.build_entity_from_params(**kwargs)
|
|
229
225
|
task.save(update=True)
|
|
230
226
|
self._tasks[kind] = task
|
|
231
227
|
return task
|
|
@@ -295,10 +291,6 @@ class ExecutableEntity(VersionedEntity):
|
|
|
295
291
|
kind : str
|
|
296
292
|
Kind the object.
|
|
297
293
|
|
|
298
|
-
Returns
|
|
299
|
-
-------
|
|
300
|
-
None
|
|
301
|
-
|
|
302
294
|
Raises
|
|
303
295
|
------
|
|
304
296
|
EntityError
|
|
@@ -316,10 +308,6 @@ class ExecutableEntity(VersionedEntity):
|
|
|
316
308
|
kind : str
|
|
317
309
|
Kind the object.
|
|
318
310
|
|
|
319
|
-
Returns
|
|
320
|
-
-------
|
|
321
|
-
None
|
|
322
|
-
|
|
323
311
|
Raises
|
|
324
312
|
------
|
|
325
313
|
EntityError
|
|
@@ -425,13 +413,13 @@ class ExecutableEntity(VersionedEntity):
|
|
|
425
413
|
Run instance.
|
|
426
414
|
"""
|
|
427
415
|
# Get task
|
|
428
|
-
task_kind =
|
|
416
|
+
task_kind = entity_factory.get_task_kind_from_action(self.kind, action)
|
|
429
417
|
task = self._get_or_create_task(task_kind)
|
|
430
418
|
task_string = task._get_task_string()
|
|
431
419
|
|
|
432
420
|
# Get run validator for building trigger template
|
|
433
|
-
run_kind =
|
|
434
|
-
run_validator: SpecValidator =
|
|
421
|
+
run_kind = entity_factory.get_run_kind_from_action(self.kind, action)
|
|
422
|
+
run_validator: SpecValidator = entity_factory.get_spec_validator(run_kind)
|
|
435
423
|
# Override kwargs
|
|
436
424
|
kwargs["project"] = self.project
|
|
437
425
|
kwargs["kind"] = trigger_kind
|
|
@@ -441,7 +429,7 @@ class ExecutableEntity(VersionedEntity):
|
|
|
441
429
|
kwargs["template"] = run_validator(**kwargs).to_dict()
|
|
442
430
|
|
|
443
431
|
# Create object instance
|
|
444
|
-
trigger: Trigger =
|
|
432
|
+
trigger: Trigger = entity_factory.build_entity_from_params(**kwargs)
|
|
445
433
|
trigger.save()
|
|
446
434
|
return trigger
|
|
447
435
|
|
|
@@ -8,7 +8,7 @@ import typing
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
|
|
10
10
|
from digitalhub.entities._base.versioned.entity import VersionedEntity
|
|
11
|
-
from digitalhub.entities._processors.
|
|
11
|
+
from digitalhub.entities._processors.processors import context_processor
|
|
12
12
|
from digitalhub.stores.data.api import get_store
|
|
13
13
|
from digitalhub.utils.types import SourcesOrListOfSources
|
|
14
14
|
|
|
@@ -142,20 +142,16 @@ class MaterialEntity(VersionedEntity):
|
|
|
142
142
|
source : str | list[str]
|
|
143
143
|
Local filepath, directory or list of filepaths.
|
|
144
144
|
|
|
145
|
-
Returns
|
|
146
|
-
-------
|
|
147
|
-
None
|
|
148
|
-
|
|
149
145
|
Examples
|
|
150
146
|
--------
|
|
151
147
|
Upload a single file:
|
|
152
148
|
|
|
153
|
-
>>> entity.spec.path =
|
|
154
|
-
>>> entity.upload(
|
|
149
|
+
>>> entity.spec.path = "s3://bucket/data.csv"
|
|
150
|
+
>>> entity.upload("./data.csv")
|
|
155
151
|
|
|
156
152
|
Upload a folder:
|
|
157
|
-
>>> entity.spec.path =
|
|
158
|
-
>>> entity.upload(
|
|
153
|
+
>>> entity.spec.path = "s3://bucket/data/"
|
|
154
|
+
>>> entity.upload("./data")
|
|
159
155
|
"""
|
|
160
156
|
# Get store and upload object
|
|
161
157
|
store = get_store(self.spec.path)
|
|
@@ -177,10 +173,6 @@ class MaterialEntity(VersionedEntity):
|
|
|
177
173
|
----------
|
|
178
174
|
files : list[dict]
|
|
179
175
|
Files to add.
|
|
180
|
-
|
|
181
|
-
Returns
|
|
182
|
-
-------
|
|
183
|
-
None
|
|
184
176
|
"""
|
|
185
177
|
available = 100 - len(self.status.files)
|
|
186
178
|
if len(files) > available:
|
|
@@ -214,10 +206,6 @@ class MaterialEntity(VersionedEntity):
|
|
|
214
206
|
----------
|
|
215
207
|
files_info : list[dict] | None
|
|
216
208
|
Files info.
|
|
217
|
-
|
|
218
|
-
Returns
|
|
219
|
-
-------
|
|
220
|
-
None
|
|
221
209
|
"""
|
|
222
210
|
if files_info is None:
|
|
223
211
|
return
|
|
@@ -229,10 +217,6 @@ class MaterialEntity(VersionedEntity):
|
|
|
229
217
|
def _get_files_info(self) -> None:
|
|
230
218
|
"""
|
|
231
219
|
Get files info from backend.
|
|
232
|
-
|
|
233
|
-
Returns
|
|
234
|
-
-------
|
|
235
|
-
None
|
|
236
220
|
"""
|
|
237
221
|
if not self._context().local and not self.status.files:
|
|
238
222
|
files = context_processor.read_files_info(
|
|
@@ -7,7 +7,7 @@ from __future__ import annotations
|
|
|
7
7
|
import typing
|
|
8
8
|
|
|
9
9
|
from digitalhub.entities._base.context.entity import ContextEntity
|
|
10
|
-
from digitalhub.entities._processors.
|
|
10
|
+
from digitalhub.entities._processors.processors import context_processor
|
|
11
11
|
|
|
12
12
|
if typing.TYPE_CHECKING:
|
|
13
13
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -7,7 +7,7 @@ from __future__ import annotations
|
|
|
7
7
|
import typing
|
|
8
8
|
|
|
9
9
|
from digitalhub.entities._base.context.entity import ContextEntity
|
|
10
|
-
from digitalhub.entities._processors.
|
|
10
|
+
from digitalhub.entities._processors.processors import context_processor
|
|
11
11
|
|
|
12
12
|
if typing.TYPE_CHECKING:
|
|
13
13
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -5,34 +5,25 @@
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
7
|
import typing
|
|
8
|
-
from warnings import warn
|
|
9
8
|
|
|
10
9
|
from digitalhub.context.api import delete_context
|
|
11
10
|
from digitalhub.entities._commons.enums import ApiCategories, BackendOperations
|
|
12
|
-
from digitalhub.factory.
|
|
11
|
+
from digitalhub.factory.entity import entity_factory
|
|
13
12
|
from digitalhub.stores.client.api import get_client
|
|
14
|
-
from digitalhub.utils.exceptions import EntityAlreadyExistsError, EntityError, EntityNotExistsError
|
|
15
|
-
from digitalhub.utils.io_utils import read_yaml
|
|
16
13
|
|
|
17
14
|
if typing.TYPE_CHECKING:
|
|
18
15
|
from digitalhub.entities.project._base.entity import Project
|
|
19
16
|
from digitalhub.stores.client._base.client import Client
|
|
20
17
|
|
|
21
18
|
|
|
22
|
-
class
|
|
19
|
+
class BaseEntityCRUDProcessor:
|
|
23
20
|
"""
|
|
24
|
-
Processor for
|
|
21
|
+
Processor for core CRUD operations on base entities.
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
client layer to perform backend operations and manages entity lifecycle
|
|
29
|
-
including creation, reading, updating, deletion, and sharing.
|
|
23
|
+
Handles creation, reading, updating, deletion, and listing of
|
|
24
|
+
base-level entities (primarily projects) within the backend.
|
|
30
25
|
"""
|
|
31
26
|
|
|
32
|
-
##############################
|
|
33
|
-
# CRUD base entity
|
|
34
|
-
##############################
|
|
35
|
-
|
|
36
27
|
def _create_base_entity(
|
|
37
28
|
self,
|
|
38
29
|
client: Client,
|
|
@@ -100,10 +91,10 @@ class BaseEntityOperationsProcessor:
|
|
|
100
91
|
obj = _entity
|
|
101
92
|
else:
|
|
102
93
|
client = get_client(kwargs.get("local"))
|
|
103
|
-
obj =
|
|
94
|
+
obj = entity_factory.build_entity_from_params(**kwargs)
|
|
104
95
|
ent = self._create_base_entity(client, obj.ENTITY_TYPE, obj.to_dict())
|
|
105
96
|
ent["local"] = client.is_local()
|
|
106
|
-
return
|
|
97
|
+
return entity_factory.build_entity_from_dict(ent)
|
|
107
98
|
|
|
108
99
|
def _read_base_entity(
|
|
109
100
|
self,
|
|
@@ -172,98 +163,7 @@ class BaseEntityOperationsProcessor:
|
|
|
172
163
|
client = get_client(kwargs.pop("local", False))
|
|
173
164
|
obj = self._read_base_entity(client, entity_type, entity_name, **kwargs)
|
|
174
165
|
obj["local"] = client.is_local()
|
|
175
|
-
return
|
|
176
|
-
|
|
177
|
-
def import_project_entity(
|
|
178
|
-
self,
|
|
179
|
-
file: str,
|
|
180
|
-
**kwargs,
|
|
181
|
-
) -> Project:
|
|
182
|
-
"""
|
|
183
|
-
Import a project entity from a YAML file and create it in the backend.
|
|
184
|
-
|
|
185
|
-
Reads project configuration from a YAML file, creates a new project
|
|
186
|
-
entity in the backend, and imports any related entities defined
|
|
187
|
-
in the file. Raises an error if the project already exists.
|
|
188
|
-
|
|
189
|
-
Parameters
|
|
190
|
-
----------
|
|
191
|
-
file : str
|
|
192
|
-
Path to the YAML file containing project configuration.
|
|
193
|
-
**kwargs : dict
|
|
194
|
-
Additional parameters including 'local' and 'reset_id' flags.
|
|
195
|
-
|
|
196
|
-
Returns
|
|
197
|
-
-------
|
|
198
|
-
Project
|
|
199
|
-
The imported and created project entity.
|
|
200
|
-
|
|
201
|
-
Raises
|
|
202
|
-
------
|
|
203
|
-
EntityError
|
|
204
|
-
If the project already exists in the backend.
|
|
205
|
-
"""
|
|
206
|
-
client = get_client(kwargs.pop("local", False))
|
|
207
|
-
obj: dict = read_yaml(file)
|
|
208
|
-
obj["status"] = {}
|
|
209
|
-
obj["local"] = client.is_local()
|
|
210
|
-
ent: Project = factory.build_entity_from_dict(obj)
|
|
211
|
-
reset_id = kwargs.pop("reset_id", False)
|
|
212
|
-
|
|
213
|
-
try:
|
|
214
|
-
self._create_base_entity(ent._client, ent.ENTITY_TYPE, ent.to_dict())
|
|
215
|
-
except EntityAlreadyExistsError:
|
|
216
|
-
msg = f"Entity {ent.name} already exists."
|
|
217
|
-
if reset_id:
|
|
218
|
-
ent._import_entities(obj, reset_id=reset_id)
|
|
219
|
-
warn(f"{msg} Other entities ids have been imported.")
|
|
220
|
-
ent.refresh()
|
|
221
|
-
return ent
|
|
222
|
-
raise EntityError(f"{msg} If you want to update it, use load instead.")
|
|
223
|
-
|
|
224
|
-
# Import related entities
|
|
225
|
-
ent._import_entities(obj, reset_id=reset_id)
|
|
226
|
-
ent.refresh()
|
|
227
|
-
return ent
|
|
228
|
-
|
|
229
|
-
def load_project_entity(
|
|
230
|
-
self,
|
|
231
|
-
file: str,
|
|
232
|
-
**kwargs,
|
|
233
|
-
) -> Project:
|
|
234
|
-
"""
|
|
235
|
-
Load a project entity from a YAML file and update it in the backend.
|
|
236
|
-
|
|
237
|
-
Reads project configuration from a YAML file and updates an existing
|
|
238
|
-
project in the backend. If the project doesn't exist, it creates a
|
|
239
|
-
new one. Also loads any related entities defined in the file.
|
|
240
|
-
|
|
241
|
-
Parameters
|
|
242
|
-
----------
|
|
243
|
-
file : str
|
|
244
|
-
Path to the YAML file containing project configuration.
|
|
245
|
-
**kwargs : dict
|
|
246
|
-
Additional parameters including 'local' flag.
|
|
247
|
-
|
|
248
|
-
Returns
|
|
249
|
-
-------
|
|
250
|
-
Project
|
|
251
|
-
The loaded and updated project entity.
|
|
252
|
-
"""
|
|
253
|
-
client = get_client(kwargs.pop("local", False))
|
|
254
|
-
obj: dict = read_yaml(file)
|
|
255
|
-
obj["local"] = client.is_local()
|
|
256
|
-
ent: Project = factory.build_entity_from_dict(obj)
|
|
257
|
-
|
|
258
|
-
try:
|
|
259
|
-
self._update_base_entity(ent._client, ent.ENTITY_TYPE, ent.name, ent.to_dict())
|
|
260
|
-
except EntityNotExistsError:
|
|
261
|
-
self._create_base_entity(ent._client, ent.ENTITY_TYPE, ent.to_dict())
|
|
262
|
-
|
|
263
|
-
# Load related entities
|
|
264
|
-
ent._load_entities(obj)
|
|
265
|
-
ent.refresh()
|
|
266
|
-
return ent
|
|
166
|
+
return entity_factory.build_entity_from_dict(obj)
|
|
267
167
|
|
|
268
168
|
def _list_base_entities(
|
|
269
169
|
self,
|
|
@@ -328,7 +228,7 @@ class BaseEntityOperationsProcessor:
|
|
|
328
228
|
entities = []
|
|
329
229
|
for obj in objs:
|
|
330
230
|
obj["local"] = client.is_local()
|
|
331
|
-
ent =
|
|
231
|
+
ent = entity_factory.build_entity_from_dict(obj)
|
|
332
232
|
entities.append(ent)
|
|
333
233
|
return entities
|
|
334
234
|
|
|
@@ -405,7 +305,7 @@ class BaseEntityOperationsProcessor:
|
|
|
405
305
|
client = get_client(kwargs.pop("local", False))
|
|
406
306
|
obj = self._update_base_entity(client, entity_type, entity_name, entity_dict, **kwargs)
|
|
407
307
|
obj["local"] = client.is_local()
|
|
408
|
-
return
|
|
308
|
+
return entity_factory.build_entity_from_dict(obj)
|
|
409
309
|
|
|
410
310
|
def _delete_base_entity(
|
|
411
311
|
self,
|
|
@@ -464,6 +364,8 @@ class BaseEntityOperationsProcessor:
|
|
|
464
364
|
|
|
465
365
|
Parameters
|
|
466
366
|
----------
|
|
367
|
+
crud_processor : BaseEntityCRUDProcessor
|
|
368
|
+
The CRUD processor instance for entity operations.
|
|
467
369
|
entity_type : str
|
|
468
370
|
The type of entity to delete (typically 'project').
|
|
469
371
|
entity_name : str
|
|
@@ -486,125 +388,3 @@ class BaseEntityOperationsProcessor:
|
|
|
486
388
|
entity_name,
|
|
487
389
|
**kwargs,
|
|
488
390
|
)
|
|
489
|
-
|
|
490
|
-
##############################
|
|
491
|
-
# Base entity operations
|
|
492
|
-
##############################
|
|
493
|
-
|
|
494
|
-
def _build_base_entity_key(
|
|
495
|
-
self,
|
|
496
|
-
client: Client,
|
|
497
|
-
entity_id: str,
|
|
498
|
-
) -> str:
|
|
499
|
-
"""
|
|
500
|
-
Build a storage key for a base entity.
|
|
501
|
-
|
|
502
|
-
Creates a standardized key string that can be used to identify
|
|
503
|
-
and store the entity in various contexts.
|
|
504
|
-
|
|
505
|
-
Parameters
|
|
506
|
-
----------
|
|
507
|
-
client : Client
|
|
508
|
-
The client instance to use for key building.
|
|
509
|
-
entity_id : str
|
|
510
|
-
The unique identifier of the entity.
|
|
511
|
-
|
|
512
|
-
Returns
|
|
513
|
-
-------
|
|
514
|
-
str
|
|
515
|
-
The constructed entity key string.
|
|
516
|
-
"""
|
|
517
|
-
return client.build_key(ApiCategories.BASE.value, entity_id)
|
|
518
|
-
|
|
519
|
-
def build_project_key(
|
|
520
|
-
self,
|
|
521
|
-
entity_id: str,
|
|
522
|
-
**kwargs,
|
|
523
|
-
) -> str:
|
|
524
|
-
"""
|
|
525
|
-
Build a storage key for a project entity.
|
|
526
|
-
|
|
527
|
-
Creates a standardized key string for project identification
|
|
528
|
-
and storage, handling both local and remote client contexts.
|
|
529
|
-
|
|
530
|
-
Parameters
|
|
531
|
-
----------
|
|
532
|
-
entity_id : str
|
|
533
|
-
The unique identifier of the project entity.
|
|
534
|
-
**kwargs : dict
|
|
535
|
-
Additional parameters including 'local' flag.
|
|
536
|
-
|
|
537
|
-
Returns
|
|
538
|
-
-------
|
|
539
|
-
str
|
|
540
|
-
The constructed project entity key string.
|
|
541
|
-
"""
|
|
542
|
-
client = get_client(kwargs.pop("local", False))
|
|
543
|
-
return self._build_base_entity_key(client, entity_id)
|
|
544
|
-
|
|
545
|
-
def share_project_entity(
|
|
546
|
-
self,
|
|
547
|
-
entity_type: str,
|
|
548
|
-
entity_name: str,
|
|
549
|
-
**kwargs,
|
|
550
|
-
) -> None:
|
|
551
|
-
"""
|
|
552
|
-
Share or unshare a project entity with a user.
|
|
553
|
-
|
|
554
|
-
Manages project access permissions by sharing the project with
|
|
555
|
-
a specified user or removing user access. Handles both sharing
|
|
556
|
-
and unsharing operations based on the 'unshare' parameter.
|
|
557
|
-
|
|
558
|
-
Parameters
|
|
559
|
-
----------
|
|
560
|
-
entity_type : str
|
|
561
|
-
The type of entity to share (typically 'project').
|
|
562
|
-
entity_name : str
|
|
563
|
-
The name identifier of the project to share.
|
|
564
|
-
**kwargs : dict
|
|
565
|
-
Additional parameters including:
|
|
566
|
-
- 'user': username to share with/unshare from
|
|
567
|
-
- 'unshare': boolean flag for unsharing (default False)
|
|
568
|
-
- 'local': boolean flag for local backend
|
|
569
|
-
|
|
570
|
-
Returns
|
|
571
|
-
-------
|
|
572
|
-
None
|
|
573
|
-
|
|
574
|
-
Raises
|
|
575
|
-
------
|
|
576
|
-
ValueError
|
|
577
|
-
If trying to unshare from a user who doesn't have access.
|
|
578
|
-
"""
|
|
579
|
-
client = get_client(kwargs.pop("local", False))
|
|
580
|
-
api = client.build_api(
|
|
581
|
-
ApiCategories.BASE.value,
|
|
582
|
-
BackendOperations.SHARE.value,
|
|
583
|
-
entity_type=entity_type,
|
|
584
|
-
entity_name=entity_name,
|
|
585
|
-
)
|
|
586
|
-
|
|
587
|
-
user = kwargs.pop("user", None)
|
|
588
|
-
if unshare := kwargs.pop("unshare", False):
|
|
589
|
-
users = client.read_object(api, **kwargs)
|
|
590
|
-
for u in users:
|
|
591
|
-
if u["user"] == user:
|
|
592
|
-
kwargs["id"] = u["id"]
|
|
593
|
-
break
|
|
594
|
-
else:
|
|
595
|
-
raise ValueError(f"User '{user}' does not have access to project.")
|
|
596
|
-
|
|
597
|
-
kwargs = client.build_parameters(
|
|
598
|
-
ApiCategories.BASE.value,
|
|
599
|
-
BackendOperations.SHARE.value,
|
|
600
|
-
unshare=unshare,
|
|
601
|
-
user=user,
|
|
602
|
-
**kwargs,
|
|
603
|
-
)
|
|
604
|
-
if unshare:
|
|
605
|
-
client.delete_object(api, **kwargs)
|
|
606
|
-
return
|
|
607
|
-
client.create_object(api, obj={}, **kwargs)
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
base_processor = BaseEntityOperationsProcessor()
|