digitalhub 0.7.0b2__py3-none-any.whl → 0.8.0__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.

Files changed (232) hide show
  1. digitalhub/__init__.py +63 -93
  2. digitalhub/client/__init__.py +0 -0
  3. digitalhub/client/_base/__init__.py +0 -0
  4. digitalhub/client/_base/client.py +56 -0
  5. digitalhub/client/api.py +63 -0
  6. digitalhub/client/builder.py +50 -0
  7. digitalhub/client/dhcore/__init__.py +0 -0
  8. digitalhub/client/dhcore/client.py +669 -0
  9. digitalhub/client/dhcore/env.py +21 -0
  10. digitalhub/client/dhcore/models.py +46 -0
  11. digitalhub/client/dhcore/utils.py +111 -0
  12. digitalhub/client/local/__init__.py +0 -0
  13. digitalhub/client/local/client.py +533 -0
  14. digitalhub/context/__init__.py +0 -0
  15. digitalhub/context/api.py +93 -0
  16. digitalhub/context/builder.py +94 -0
  17. digitalhub/context/context.py +136 -0
  18. digitalhub/datastores/__init__.py +0 -0
  19. digitalhub/datastores/_base/__init__.py +0 -0
  20. digitalhub/datastores/_base/datastore.py +85 -0
  21. digitalhub/datastores/api.py +37 -0
  22. digitalhub/datastores/builder.py +110 -0
  23. digitalhub/datastores/local/__init__.py +0 -0
  24. digitalhub/datastores/local/datastore.py +50 -0
  25. digitalhub/datastores/remote/__init__.py +0 -0
  26. digitalhub/datastores/remote/datastore.py +31 -0
  27. digitalhub/datastores/s3/__init__.py +0 -0
  28. digitalhub/datastores/s3/datastore.py +46 -0
  29. digitalhub/datastores/sql/__init__.py +0 -0
  30. digitalhub/datastores/sql/datastore.py +68 -0
  31. digitalhub/entities/__init__.py +0 -0
  32. digitalhub/entities/_base/__init__.py +0 -0
  33. digitalhub/entities/_base/_base/__init__.py +0 -0
  34. digitalhub/entities/_base/_base/entity.py +82 -0
  35. digitalhub/entities/_base/api_utils.py +620 -0
  36. digitalhub/entities/_base/context/__init__.py +0 -0
  37. digitalhub/entities/_base/context/entity.py +118 -0
  38. digitalhub/entities/_base/crud.py +468 -0
  39. digitalhub/entities/_base/entity/__init__.py +0 -0
  40. digitalhub/entities/_base/entity/_constructors/__init__.py +0 -0
  41. digitalhub/entities/_base/entity/_constructors/metadata.py +44 -0
  42. digitalhub/entities/_base/entity/_constructors/name.py +31 -0
  43. digitalhub/entities/_base/entity/_constructors/spec.py +33 -0
  44. digitalhub/entities/_base/entity/_constructors/status.py +52 -0
  45. digitalhub/entities/_base/entity/_constructors/uuid.py +26 -0
  46. digitalhub/entities/_base/entity/builder.py +175 -0
  47. digitalhub/entities/_base/entity/entity.py +106 -0
  48. digitalhub/entities/_base/entity/metadata.py +59 -0
  49. digitalhub/entities/_base/entity/spec.py +58 -0
  50. digitalhub/entities/_base/entity/status.py +43 -0
  51. digitalhub/entities/_base/executable/__init__.py +0 -0
  52. digitalhub/entities/_base/executable/entity.py +405 -0
  53. digitalhub/entities/_base/material/__init__.py +0 -0
  54. digitalhub/entities/_base/material/entity.py +214 -0
  55. digitalhub/entities/_base/material/spec.py +22 -0
  56. digitalhub/entities/_base/material/status.py +49 -0
  57. digitalhub/entities/_base/runtime_entity/__init__.py +0 -0
  58. digitalhub/entities/_base/runtime_entity/builder.py +106 -0
  59. digitalhub/entities/_base/unversioned/__init__.py +0 -0
  60. digitalhub/entities/_base/unversioned/builder.py +66 -0
  61. digitalhub/entities/_base/unversioned/entity.py +49 -0
  62. digitalhub/entities/_base/versioned/__init__.py +0 -0
  63. digitalhub/entities/_base/versioned/builder.py +68 -0
  64. digitalhub/entities/_base/versioned/entity.py +53 -0
  65. digitalhub/entities/artifact/__init__.py +0 -0
  66. digitalhub/entities/artifact/_base/__init__.py +0 -0
  67. digitalhub/entities/artifact/_base/builder.py +86 -0
  68. digitalhub/entities/artifact/_base/entity.py +39 -0
  69. digitalhub/entities/artifact/_base/spec.py +15 -0
  70. digitalhub/entities/artifact/_base/status.py +9 -0
  71. digitalhub/entities/artifact/artifact/__init__.py +0 -0
  72. digitalhub/entities/artifact/artifact/builder.py +18 -0
  73. digitalhub/entities/artifact/artifact/entity.py +32 -0
  74. digitalhub/entities/artifact/artifact/spec.py +27 -0
  75. digitalhub/entities/artifact/artifact/status.py +15 -0
  76. digitalhub/entities/artifact/crud.py +332 -0
  77. digitalhub/entities/builders.py +63 -0
  78. digitalhub/entities/dataitem/__init__.py +0 -0
  79. digitalhub/entities/dataitem/_base/__init__.py +0 -0
  80. digitalhub/entities/dataitem/_base/builder.py +86 -0
  81. digitalhub/entities/dataitem/_base/entity.py +75 -0
  82. digitalhub/entities/dataitem/_base/spec.py +15 -0
  83. digitalhub/entities/dataitem/_base/status.py +20 -0
  84. digitalhub/entities/dataitem/crud.py +372 -0
  85. digitalhub/entities/dataitem/dataitem/__init__.py +0 -0
  86. digitalhub/entities/dataitem/dataitem/builder.py +18 -0
  87. digitalhub/entities/dataitem/dataitem/entity.py +32 -0
  88. digitalhub/entities/dataitem/dataitem/spec.py +15 -0
  89. digitalhub/entities/dataitem/dataitem/status.py +9 -0
  90. digitalhub/entities/dataitem/iceberg/__init__.py +0 -0
  91. digitalhub/entities/dataitem/iceberg/builder.py +18 -0
  92. digitalhub/entities/dataitem/iceberg/entity.py +32 -0
  93. digitalhub/entities/dataitem/iceberg/spec.py +15 -0
  94. digitalhub/entities/dataitem/iceberg/status.py +9 -0
  95. digitalhub/entities/dataitem/table/__init__.py +0 -0
  96. digitalhub/entities/dataitem/table/builder.py +18 -0
  97. digitalhub/entities/dataitem/table/entity.py +146 -0
  98. digitalhub/entities/dataitem/table/models.py +62 -0
  99. digitalhub/entities/dataitem/table/spec.py +25 -0
  100. digitalhub/entities/dataitem/table/status.py +9 -0
  101. digitalhub/entities/function/__init__.py +0 -0
  102. digitalhub/entities/function/_base/__init__.py +0 -0
  103. digitalhub/entities/function/_base/builder.py +79 -0
  104. digitalhub/entities/function/_base/entity.py +98 -0
  105. digitalhub/entities/function/_base/models.py +118 -0
  106. digitalhub/entities/function/_base/spec.py +15 -0
  107. digitalhub/entities/function/_base/status.py +9 -0
  108. digitalhub/entities/function/crud.py +279 -0
  109. digitalhub/entities/model/__init__.py +0 -0
  110. digitalhub/entities/model/_base/__init__.py +0 -0
  111. digitalhub/entities/model/_base/builder.py +86 -0
  112. digitalhub/entities/model/_base/entity.py +34 -0
  113. digitalhub/entities/model/_base/spec.py +49 -0
  114. digitalhub/entities/model/_base/status.py +9 -0
  115. digitalhub/entities/model/crud.py +331 -0
  116. digitalhub/entities/model/huggingface/__init__.py +0 -0
  117. digitalhub/entities/model/huggingface/builder.py +18 -0
  118. digitalhub/entities/model/huggingface/entity.py +32 -0
  119. digitalhub/entities/model/huggingface/spec.py +36 -0
  120. digitalhub/entities/model/huggingface/status.py +9 -0
  121. digitalhub/entities/model/mlflow/__init__.py +0 -0
  122. digitalhub/entities/model/mlflow/builder.py +18 -0
  123. digitalhub/entities/model/mlflow/entity.py +32 -0
  124. digitalhub/entities/model/mlflow/models.py +26 -0
  125. digitalhub/entities/model/mlflow/spec.py +44 -0
  126. digitalhub/entities/model/mlflow/status.py +9 -0
  127. digitalhub/entities/model/mlflow/utils.py +81 -0
  128. digitalhub/entities/model/model/__init__.py +0 -0
  129. digitalhub/entities/model/model/builder.py +18 -0
  130. digitalhub/entities/model/model/entity.py +32 -0
  131. digitalhub/entities/model/model/spec.py +15 -0
  132. digitalhub/entities/model/model/status.py +9 -0
  133. digitalhub/entities/model/sklearn/__init__.py +0 -0
  134. digitalhub/entities/model/sklearn/builder.py +18 -0
  135. digitalhub/entities/model/sklearn/entity.py +32 -0
  136. digitalhub/entities/model/sklearn/spec.py +15 -0
  137. digitalhub/entities/model/sklearn/status.py +9 -0
  138. digitalhub/entities/project/__init__.py +0 -0
  139. digitalhub/entities/project/_base/__init__.py +0 -0
  140. digitalhub/entities/project/_base/builder.py +128 -0
  141. digitalhub/entities/project/_base/entity.py +2078 -0
  142. digitalhub/entities/project/_base/spec.py +50 -0
  143. digitalhub/entities/project/_base/status.py +9 -0
  144. digitalhub/entities/project/crud.py +357 -0
  145. digitalhub/entities/run/__init__.py +0 -0
  146. digitalhub/entities/run/_base/__init__.py +0 -0
  147. digitalhub/entities/run/_base/builder.py +94 -0
  148. digitalhub/entities/run/_base/entity.py +307 -0
  149. digitalhub/entities/run/_base/spec.py +50 -0
  150. digitalhub/entities/run/_base/status.py +9 -0
  151. digitalhub/entities/run/crud.py +219 -0
  152. digitalhub/entities/secret/__init__.py +0 -0
  153. digitalhub/entities/secret/_base/__init__.py +0 -0
  154. digitalhub/entities/secret/_base/builder.py +81 -0
  155. digitalhub/entities/secret/_base/entity.py +74 -0
  156. digitalhub/entities/secret/_base/spec.py +35 -0
  157. digitalhub/entities/secret/_base/status.py +9 -0
  158. digitalhub/entities/secret/crud.py +290 -0
  159. digitalhub/entities/task/__init__.py +0 -0
  160. digitalhub/entities/task/_base/__init__.py +0 -0
  161. digitalhub/entities/task/_base/builder.py +91 -0
  162. digitalhub/entities/task/_base/entity.py +136 -0
  163. digitalhub/entities/task/_base/models.py +208 -0
  164. digitalhub/entities/task/_base/spec.py +53 -0
  165. digitalhub/entities/task/_base/status.py +9 -0
  166. digitalhub/entities/task/crud.py +228 -0
  167. digitalhub/entities/utils/__init__.py +0 -0
  168. digitalhub/entities/utils/api.py +346 -0
  169. digitalhub/entities/utils/entity_types.py +19 -0
  170. digitalhub/entities/utils/state.py +31 -0
  171. digitalhub/entities/utils/utils.py +202 -0
  172. digitalhub/entities/workflow/__init__.py +0 -0
  173. digitalhub/entities/workflow/_base/__init__.py +0 -0
  174. digitalhub/entities/workflow/_base/builder.py +79 -0
  175. digitalhub/entities/workflow/_base/entity.py +74 -0
  176. digitalhub/entities/workflow/_base/spec.py +15 -0
  177. digitalhub/entities/workflow/_base/status.py +9 -0
  178. digitalhub/entities/workflow/crud.py +278 -0
  179. digitalhub/factory/__init__.py +0 -0
  180. digitalhub/factory/api.py +277 -0
  181. digitalhub/factory/factory.py +268 -0
  182. digitalhub/factory/utils.py +90 -0
  183. digitalhub/readers/__init__.py +0 -0
  184. digitalhub/readers/_base/__init__.py +0 -0
  185. digitalhub/readers/_base/builder.py +26 -0
  186. digitalhub/readers/_base/reader.py +70 -0
  187. digitalhub/readers/api.py +80 -0
  188. digitalhub/readers/factory.py +133 -0
  189. digitalhub/readers/pandas/__init__.py +0 -0
  190. digitalhub/readers/pandas/builder.py +29 -0
  191. digitalhub/readers/pandas/reader.py +207 -0
  192. digitalhub/runtimes/__init__.py +0 -0
  193. digitalhub/runtimes/_base.py +102 -0
  194. digitalhub/runtimes/builder.py +32 -0
  195. digitalhub/stores/__init__.py +0 -0
  196. digitalhub/stores/_base/__init__.py +0 -0
  197. digitalhub/stores/_base/store.py +189 -0
  198. digitalhub/stores/api.py +54 -0
  199. digitalhub/stores/builder.py +211 -0
  200. digitalhub/stores/local/__init__.py +0 -0
  201. digitalhub/stores/local/store.py +230 -0
  202. digitalhub/stores/remote/__init__.py +0 -0
  203. digitalhub/stores/remote/store.py +143 -0
  204. digitalhub/stores/s3/__init__.py +0 -0
  205. digitalhub/stores/s3/store.py +563 -0
  206. digitalhub/stores/sql/__init__.py +0 -0
  207. digitalhub/stores/sql/store.py +328 -0
  208. digitalhub/utils/__init__.py +0 -0
  209. digitalhub/utils/data_utils.py +127 -0
  210. digitalhub/utils/exceptions.py +67 -0
  211. digitalhub/utils/file_utils.py +204 -0
  212. digitalhub/utils/generic_utils.py +183 -0
  213. digitalhub/utils/git_utils.py +148 -0
  214. digitalhub/utils/io_utils.py +116 -0
  215. digitalhub/utils/logger.py +17 -0
  216. digitalhub/utils/s3_utils.py +58 -0
  217. digitalhub/utils/uri_utils.py +56 -0
  218. {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/METADATA +30 -13
  219. digitalhub-0.8.0.dist-info/RECORD +231 -0
  220. {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/WHEEL +1 -1
  221. test/local/CRUD/test_artifacts.py +96 -0
  222. test/local/CRUD/test_dataitems.py +96 -0
  223. test/local/CRUD/test_models.py +95 -0
  224. test/test_crud_functions.py +1 -1
  225. test/test_crud_runs.py +1 -1
  226. test/test_crud_tasks.py +1 -1
  227. digitalhub-0.7.0b2.dist-info/RECORD +0 -14
  228. test/test_crud_artifacts.py +0 -96
  229. test/test_crud_dataitems.py +0 -96
  230. {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/LICENSE.txt +0 -0
  231. {digitalhub-0.7.0b2.dist-info → digitalhub-0.8.0.dist-info}/top_level.txt +0 -0
  232. /test/{test_imports.py → local/imports/test_imports.py} +0 -0
@@ -0,0 +1,74 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.api_utils import get_data_api, set_data_api
6
+ from digitalhub.entities._base.versioned.entity import VersionedEntity
7
+ from digitalhub.entities.utils.entity_types import EntityTypes
8
+
9
+ if typing.TYPE_CHECKING:
10
+ from digitalhub.entities._base.entity.metadata import Metadata
11
+ from digitalhub.entities.secret._base.spec import SecretSpec
12
+ from digitalhub.entities.secret._base.status import SecretStatus
13
+
14
+
15
+ class Secret(VersionedEntity):
16
+ """
17
+ A class representing a secret.
18
+ """
19
+
20
+ ENTITY_TYPE = EntityTypes.SECRET.value
21
+
22
+ def __init__(
23
+ self,
24
+ project: str,
25
+ name: str,
26
+ uuid: str,
27
+ kind: str,
28
+ metadata: Metadata,
29
+ spec: SecretSpec,
30
+ status: SecretStatus,
31
+ user: str | None = None,
32
+ ) -> None:
33
+ super().__init__(project, name, uuid, kind, metadata, spec, status, user)
34
+ self.spec: SecretSpec
35
+ self.status: SecretStatus
36
+
37
+ ##############################
38
+ # Secret methods
39
+ ##############################
40
+
41
+ def set_secret_value(self, value: str) -> None:
42
+ """
43
+ Update the secret value with a new one.
44
+
45
+ Parameters
46
+ ----------
47
+ value : str
48
+ Value of the secret.
49
+
50
+ Returns
51
+ -------
52
+ None
53
+ """
54
+ if self._context().local:
55
+ raise NotImplementedError("set_secret() is not implemented for local projects.")
56
+
57
+ obj = {self.name: value}
58
+ set_data_api(self.project, self.ENTITY_TYPE, obj)
59
+
60
+ def read_secret_value(self) -> dict:
61
+ """
62
+ Read the secret value from backend.
63
+
64
+ Returns
65
+ -------
66
+ str
67
+ Value of the secret.
68
+ """
69
+ if self._context().local:
70
+ raise NotImplementedError("read_secret() is not implemented for local projects.")
71
+
72
+ params = {"keys": self.name}
73
+ data = get_data_api(self.project, self.ENTITY_TYPE, params=params)
74
+ return data[self.name]
@@ -0,0 +1,35 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.entity.spec import Spec, SpecValidator
4
+
5
+
6
+ class SecretSpec(Spec):
7
+ """
8
+ SecretSpec specifications.
9
+ """
10
+
11
+ def __init__(self, path: str | None = None, provider: str | None = None, **kwargs) -> None:
12
+ """
13
+ Constructor.
14
+
15
+ Parameters
16
+ ----------
17
+ path : str
18
+ Path to the secret.
19
+ provider : str
20
+ Provider of the secret.
21
+ """
22
+ self.path = path
23
+ self.provider = provider
24
+
25
+
26
+ class SecretValidator(SpecValidator):
27
+ """
28
+ SecretValidator validator.
29
+ """
30
+
31
+ path: str = None
32
+ """Path to the secret."""
33
+
34
+ provider: str = None
35
+ """Provider of the secret."""
@@ -0,0 +1,9 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.entity.status import Status
4
+
5
+
6
+ class SecretStatus(Status):
7
+ """
8
+ SecretStatus status.
9
+ """
@@ -0,0 +1,290 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.context.api import check_context
6
+ from digitalhub.entities._base.crud import (
7
+ delete_entity,
8
+ get_context_entity_versions,
9
+ get_versioned_entity,
10
+ import_context_entity,
11
+ list_context_entities,
12
+ new_context_entity,
13
+ )
14
+ from digitalhub.entities.utils.entity_types import EntityTypes
15
+ from digitalhub.utils.exceptions import EntityNotExistsError
16
+
17
+ if typing.TYPE_CHECKING:
18
+ from digitalhub.entities.secret._base.entity import Secret
19
+
20
+
21
+ ENTITY_TYPE = EntityTypes.SECRET.value
22
+
23
+
24
+ def new_secret(
25
+ project: str,
26
+ name: str,
27
+ uuid: str | None = None,
28
+ description: str | None = None,
29
+ labels: list[str] | None = None,
30
+ embedded: bool = False,
31
+ secret_value: str | None = None,
32
+ **kwargs,
33
+ ) -> Secret:
34
+ """
35
+ Create a new object.
36
+
37
+ Parameters
38
+ ----------
39
+ project : str
40
+ Project name.
41
+ name : str
42
+ Object name.
43
+ uuid : str
44
+ ID of the object.
45
+ description : str
46
+ Description of the object (human readable).
47
+ labels : list[str]
48
+ List of labels.
49
+ embedded : bool
50
+ Flag to determine if object spec must be embedded in project spec.
51
+ secret_value : str
52
+ Value of the secret.
53
+ **kwargs : dict
54
+ Spec keyword arguments.
55
+
56
+ Returns
57
+ -------
58
+ Secret
59
+ Object instance.
60
+
61
+ Examples
62
+ --------
63
+ >>> obj = new_secret(project="my-project",
64
+ >>> name="my-secret",
65
+ >>> secret_value="my-secret-value")
66
+ """
67
+ check_context(project)
68
+
69
+ if secret_value is None:
70
+ raise ValueError("secret_value must be provided.")
71
+ obj: Secret = new_context_entity(
72
+ project=project,
73
+ name=name,
74
+ kind="secret",
75
+ uuid=uuid,
76
+ description=description,
77
+ labels=labels,
78
+ embedded=embedded,
79
+ **kwargs,
80
+ )
81
+ obj.set_secret_value(value=secret_value)
82
+ return obj
83
+
84
+
85
+ def get_secret(
86
+ identifier: str,
87
+ project: str | None = None,
88
+ entity_id: str | None = None,
89
+ **kwargs,
90
+ ) -> Secret:
91
+ """
92
+ Get object from backend.
93
+
94
+ Parameters
95
+ ----------
96
+ identifier : str
97
+ Entity key (store://...) or entity name.
98
+ project : str
99
+ Project name.
100
+ entity_id : str
101
+ Entity ID.
102
+ **kwargs : dict
103
+ Parameters to pass to the API call.
104
+
105
+ Returns
106
+ -------
107
+ Secret
108
+ Object instance.
109
+
110
+ Examples
111
+ --------
112
+ Using entity key:
113
+ >>> obj = get_secret("store://my-secret-key")
114
+
115
+ Using entity name:
116
+ >>> obj = get_secret("my-secret-name"
117
+ >>> project="my-project",
118
+ >>> entity_id="my-secret-id")
119
+ """
120
+ if not identifier.startswith("store://"):
121
+ secrets = list_secrets(project=project, **kwargs)
122
+ for secret in secrets:
123
+ if secret.name == identifier:
124
+ return secret
125
+ else:
126
+ raise EntityNotExistsError(f"Secret {identifier} not found.")
127
+
128
+ return get_versioned_entity(
129
+ identifier,
130
+ entity_type=ENTITY_TYPE,
131
+ project=project,
132
+ entity_id=entity_id,
133
+ **kwargs,
134
+ )
135
+
136
+
137
+ def get_secret_versions(
138
+ identifier: str,
139
+ project: str | None = None,
140
+ **kwargs,
141
+ ) -> list[Secret]:
142
+ """
143
+ Get object versions from backend.
144
+
145
+ Parameters
146
+ ----------
147
+ identifier : str
148
+ Entity key (store://...) or entity name.
149
+ project : str
150
+ Project name.
151
+ **kwargs : dict
152
+ Parameters to pass to the API call.
153
+
154
+ Returns
155
+ -------
156
+ list[Secret]
157
+ List of object instances.
158
+
159
+ Examples
160
+ --------
161
+ Using entity key:
162
+ >>> objs = get_secret_versions("store://my-secret-key")
163
+
164
+ Using entity name:
165
+ >>> objs = get_secret_versions("my-secret-name",
166
+ >>> project="my-project")
167
+ """
168
+ return get_context_entity_versions(
169
+ identifier,
170
+ entity_type=ENTITY_TYPE,
171
+ project=project,
172
+ **kwargs,
173
+ )
174
+
175
+
176
+ def list_secrets(project: str, **kwargs) -> list[Secret]:
177
+ """
178
+ List all latest version objects from backend.
179
+
180
+ Parameters
181
+ ----------
182
+ project : str
183
+ Project name.
184
+ **kwargs : dict
185
+ Parameters to pass to the API call.
186
+
187
+ Returns
188
+ -------
189
+ list[Secret]
190
+ List of object instances.
191
+
192
+ Examples
193
+ --------
194
+ >>> objs = list_secrets(project="my-project")
195
+ """
196
+ return list_context_entities(
197
+ project=project,
198
+ entity_type=ENTITY_TYPE,
199
+ **kwargs,
200
+ )
201
+
202
+
203
+ def import_secret(file: str) -> Secret:
204
+ """
205
+ Import object from a YAML file.
206
+
207
+ Parameters
208
+ ----------
209
+ file : str
210
+ Path to YAML file.
211
+
212
+ Returns
213
+ -------
214
+ Secret
215
+ Object instance.
216
+
217
+ Examples
218
+ --------
219
+ >>> obj = import_secret("my-secret.yaml")
220
+ """
221
+ return import_context_entity(file)
222
+
223
+
224
+ def update_secret(entity: Secret) -> Secret:
225
+ """
226
+ Update object. Note that object spec are immutable.
227
+
228
+ Parameters
229
+ ----------
230
+ entity : Secret
231
+ Object to update.
232
+
233
+ Returns
234
+ -------
235
+ Secret
236
+ Entity updated.
237
+
238
+ Examples
239
+ --------
240
+ >>> obj = update_secret(obj)
241
+ """
242
+ return entity.save(update=True)
243
+
244
+
245
+ def delete_secret(
246
+ identifier: str,
247
+ project: str | None = None,
248
+ entity_id: str | None = None,
249
+ delete_all_versions: bool = False,
250
+ **kwargs,
251
+ ) -> dict:
252
+ """
253
+ Delete object from backend.
254
+
255
+ Parameters
256
+ ----------
257
+ identifier : str
258
+ Entity key (store://...) or entity name.
259
+ project : str
260
+ Project name.
261
+ entity_id : str
262
+ Entity ID.
263
+ delete_all_versions : bool
264
+ Delete all versions of the named entity. If True, use entity name instead of entity key as identifier.
265
+ **kwargs : dict
266
+ Parameters to pass to the API call.
267
+
268
+ Returns
269
+ -------
270
+ dict
271
+ Response from backend.
272
+
273
+ Examples
274
+ --------
275
+ If delete_all_versions is False:
276
+ >>> obj = delete_secret("store://my-secret-key")
277
+
278
+ Otherwise:
279
+ >>> obj = delete_secret("my-secret-name"
280
+ >>> project="my-project",
281
+ >>> delete_all_versions=True)
282
+ """
283
+ return delete_entity(
284
+ identifier=identifier,
285
+ entity_type=ENTITY_TYPE,
286
+ project=project,
287
+ entity_id=entity_id,
288
+ delete_all_versions=delete_all_versions,
289
+ **kwargs,
290
+ )
File without changes
File without changes
@@ -0,0 +1,91 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.runtime_entity.builder import EntityError, RuntimeEntityBuilder
6
+ from digitalhub.entities._base.unversioned.builder import UnversionedBuilder
7
+ from digitalhub.entities.utils.entity_types import EntityTypes
8
+
9
+ if typing.TYPE_CHECKING:
10
+ from digitalhub.entities.task._base.entity import Task
11
+
12
+
13
+ class TaskBuilder(UnversionedBuilder, RuntimeEntityBuilder):
14
+ """
15
+ Task builder.
16
+ """
17
+
18
+ ENTITY_TYPE = EntityTypes.TASK.value
19
+
20
+ def build(
21
+ self,
22
+ project: str,
23
+ kind: str,
24
+ uuid: str | None = None,
25
+ labels: list[str] | None = None,
26
+ function: str | None = None,
27
+ **kwargs,
28
+ ) -> Task:
29
+ """
30
+ Create a new object.
31
+
32
+ Parameters
33
+ ----------
34
+ project : str
35
+ Project name.
36
+ kind : str
37
+ Kind the object.
38
+ uuid : str
39
+ ID of the object.
40
+ labels : list[str]
41
+ List of labels.
42
+ function : str
43
+ Name of the executable associated with the task.
44
+ **kwargs : dict
45
+ Spec keyword arguments.
46
+
47
+ Returns
48
+ -------
49
+ Task
50
+ Object instance.
51
+ """
52
+ if function is None:
53
+ raise EntityError("function must be provided")
54
+
55
+ self._check_kind_validity(function)
56
+ uuid = self.build_uuid(uuid)
57
+ metadata = self.build_metadata(
58
+ project=project,
59
+ name=uuid,
60
+ labels=labels,
61
+ )
62
+ spec = self.build_spec(
63
+ function=function,
64
+ **kwargs,
65
+ )
66
+ status = self.build_status()
67
+ return self.build_entity(
68
+ project=project,
69
+ uuid=uuid,
70
+ kind=kind,
71
+ metadata=metadata,
72
+ spec=spec,
73
+ status=status,
74
+ )
75
+
76
+ def _check_kind_validity(self, function: str) -> None:
77
+ """
78
+ Check kind validity.
79
+
80
+ Parameters
81
+ ----------
82
+ function : str
83
+ Function string.
84
+
85
+ Returns
86
+ -------
87
+ None
88
+ """
89
+ function_kind = function.split("://")[0]
90
+ if self.EXECUTABLE_KIND != function_kind:
91
+ raise EntityError(f"Invalid task '{self.ENTITY_KIND}' for function kind '{function_kind}'")
@@ -0,0 +1,136 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.unversioned.entity import UnversionedEntity
6
+ from digitalhub.entities.run.crud import delete_run, get_run, new_run
7
+ from digitalhub.entities.utils.entity_types import EntityTypes
8
+ from digitalhub.factory.api import build_entity_from_params
9
+
10
+ if typing.TYPE_CHECKING:
11
+ from digitalhub.entities._base.entity.metadata import Metadata
12
+ from digitalhub.entities.run._base.entity import Run
13
+ from digitalhub.entities.task._base.spec import TaskSpec
14
+ from digitalhub.entities.task._base.status import TaskStatus
15
+
16
+
17
+ class Task(UnversionedEntity):
18
+ """
19
+ A class representing a task.
20
+ """
21
+
22
+ ENTITY_TYPE = EntityTypes.TASK.value
23
+
24
+ def __init__(
25
+ self,
26
+ project: str,
27
+ uuid: str,
28
+ kind: str,
29
+ metadata: Metadata,
30
+ spec: TaskSpec,
31
+ status: TaskStatus,
32
+ user: str | None = None,
33
+ ) -> None:
34
+ super().__init__(project, uuid, kind, metadata, spec, status, user)
35
+ self.spec: TaskSpec
36
+ self.status: TaskStatus
37
+
38
+ ##############################
39
+ # Task methods
40
+ ##############################
41
+
42
+ def run(
43
+ self,
44
+ run_kind: str,
45
+ local_execution: bool = False,
46
+ **kwargs,
47
+ ) -> Run:
48
+ """
49
+ Run task.
50
+
51
+ Parameters
52
+ ----------
53
+ run_kind : str
54
+ Kind the object.
55
+ local_execution : bool
56
+ Flag to indicate if the run will be executed locally.
57
+ **kwargs : dict
58
+ Keyword arguments.
59
+
60
+ Returns
61
+ -------
62
+ Run
63
+ Run object.
64
+ """
65
+ return self.new_run(
66
+ project=self.project,
67
+ task=self._get_task_string(),
68
+ kind=run_kind,
69
+ local_execution=local_execution,
70
+ **kwargs,
71
+ )
72
+
73
+ def _get_task_string(self) -> str:
74
+ """
75
+ Get task string.
76
+
77
+ Returns
78
+ -------
79
+ str
80
+ Task string.
81
+ """
82
+ splitted = self.spec.function.split("://")
83
+ return f"{self.kind}://{splitted[1]}"
84
+
85
+ ##############################
86
+ # CRUD Methods for Run
87
+ ##############################
88
+
89
+ def new_run(self, **kwargs) -> Run:
90
+ """
91
+ Create a new run.
92
+
93
+ Parameters
94
+ ----------
95
+ **kwargs : dict
96
+ Keyword arguments.
97
+
98
+ Returns
99
+ -------
100
+ Run
101
+ Run object.
102
+ """
103
+ if kwargs["local_execution"]:
104
+ return build_entity_from_params(**kwargs)
105
+ return new_run(**kwargs)
106
+
107
+ def get_run(self, entity_key: str) -> Run:
108
+ """
109
+ Get run.
110
+
111
+ Parameters
112
+ ----------
113
+ entity_key : str
114
+ Entity key.
115
+
116
+ Returns
117
+ -------
118
+ Run
119
+ Run object.
120
+ """
121
+ return get_run(entity_key)
122
+
123
+ def delete_run(self, entity_key: str) -> None:
124
+ """
125
+ Delete run.
126
+
127
+ Parameters
128
+ ----------
129
+ entity_key : str
130
+ Entity key.
131
+
132
+ Returns
133
+ -------
134
+ None
135
+ """
136
+ delete_run(entity_key)