pal-found-cli 0.1.2__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.
- pal_found_cli/__init__.py +1 -0
- pal_found_cli/_version.py +24 -0
- pal_found_cli/admin/__init__.py +2 -0
- pal_found_cli/admin/scripts/__init__.py +2 -0
- pal_found_cli/admin/scripts/pal_found_admin_cli.py +600 -0
- pal_found_cli/aip_agents/__init__.py +1 -0
- pal_found_cli/aip_agents/metadata-allow-list.md +20 -0
- pal_found_cli/aip_agents/scripts/__init__.py +1 -0
- pal_found_cli/aip_agents/scripts/pal_found_aip_agents_cli.py +704 -0
- pal_found_cli/audit/__init__.py +1 -0
- pal_found_cli/audit/metadata-allow-list.md +4 -0
- pal_found_cli/audit/scripts/__init__.py +1 -0
- pal_found_cli/audit/scripts/pal_found_audit_cli.py +387 -0
- pal_found_cli/checkpoints/__init__.py +9 -0
- pal_found_cli/checkpoints/metadata-allow-list.md +7 -0
- pal_found_cli/checkpoints/scripts/__init__.py +1 -0
- pal_found_cli/checkpoints/scripts/pal_found_checkpoints_cli.py +527 -0
- pal_found_cli/common/__init__.py +56 -0
- pal_found_cli/common/access_control_guard.py +591 -0
- pal_found_cli/common/async_client_factory.py +161 -0
- pal_found_cli/common/auth_provider.py +82 -0
- pal_found_cli/common/binary_download_handler.py +288 -0
- pal_found_cli/common/config_loader.py +388 -0
- pal_found_cli/common/error_serializer.py +412 -0
- pal_found_cli/common/log_setup.py +241 -0
- pal_found_cli/common/metadata-allow-list.md +169 -0
- pal_found_cli/common/output_formatter.py +267 -0
- pal_found_cli/common/pagination_helper.py +212 -0
- pal_found_cli/common/retry.py +617 -0
- pal_found_cli/common/sdk_error_utils.py +112 -0
- pal_found_cli/common/session_manager.py +461 -0
- pal_found_cli/common/tracing_provider.py +107 -0
- pal_found_cli/connectivity/__init__.py +9 -0
- pal_found_cli/connectivity/metadata-allow-list.md +24 -0
- pal_found_cli/connectivity/scripts/__init__.py +1 -0
- pal_found_cli/connectivity/scripts/pal_found_connectivity_cli.py +720 -0
- pal_found_cli/data_health/__init__.py +9 -0
- pal_found_cli/data_health/metadata-allow-list.md +10 -0
- pal_found_cli/data_health/scripts/__init__.py +1 -0
- pal_found_cli/data_health/scripts/pal_found_data_health_cli.py +458 -0
- pal_found_cli/datasets/__init__.py +1 -0
- pal_found_cli/datasets/scripts/__init__.py +1 -0
- pal_found_cli/datasets/scripts/pal_found_datasets_cli.py +732 -0
- pal_found_cli/filesystem/__init__.py +2 -0
- pal_found_cli/filesystem/scripts/__init__.py +2 -0
- pal_found_cli/filesystem/scripts/pal_found_filesystem_cli.py +659 -0
- pal_found_cli/functions/__init__.py +2 -0
- pal_found_cli/functions/scripts/__init__.py +2 -0
- pal_found_cli/functions/scripts/pal_found_functions_cli.py +389 -0
- pal_found_cli/language_models/__init__.py +1 -0
- pal_found_cli/language_models/metadata-allow-list.md +6 -0
- pal_found_cli/language_models/scripts/__init__.py +1 -0
- pal_found_cli/language_models/scripts/pal_found_language_models_cli.py +342 -0
- pal_found_cli/media_sets/__init__.py +9 -0
- pal_found_cli/media_sets/metadata-allow-list.md +23 -0
- pal_found_cli/media_sets/scripts/__init__.py +1 -0
- pal_found_cli/media_sets/scripts/pal_found_media_sets_cli.py +642 -0
- pal_found_cli/models/__init__.py +5 -0
- pal_found_cli/models/metadata-allow-list.md +27 -0
- pal_found_cli/models/scripts/__init__.py +1 -0
- pal_found_cli/models/scripts/pal_found_models_cli.py +714 -0
- pal_found_cli/ontologies/__init__.py +1 -0
- pal_found_cli/ontologies/scripts/__init__.py +1 -0
- pal_found_cli/ontologies/scripts/pal_found_ontologies_cli.py +1225 -0
- pal_found_cli/orchestration/__init__.py +9 -0
- pal_found_cli/orchestration/metadata-allow-list.md +24 -0
- pal_found_cli/orchestration/scripts/__init__.py +1 -0
- pal_found_cli/orchestration/scripts/pal_found_orchestration_cli.py +640 -0
- pal_found_cli/sql_queries/__init__.py +9 -0
- pal_found_cli/sql_queries/metadata-allow-list.md +9 -0
- pal_found_cli/sql_queries/scripts/__init__.py +1 -0
- pal_found_cli/sql_queries/scripts/pal_found_sql_queries_cli.py +514 -0
- pal_found_cli/streams/__init__.py +9 -0
- pal_found_cli/streams/metadata-allow-list.md +19 -0
- pal_found_cli/streams/scripts/__init__.py +1 -0
- pal_found_cli/streams/scripts/pal_found_streams_cli.py +615 -0
- pal_found_cli/third_party_applications/__init__.py +9 -0
- pal_found_cli/third_party_applications/metadata-allow-list.md +13 -0
- pal_found_cli/third_party_applications/scripts/__init__.py +1 -0
- pal_found_cli/third_party_applications/scripts/pal_found_third_party_applications_cli.py +547 -0
- pal_found_cli/widgets/__init__.py +9 -0
- pal_found_cli/widgets/metadata-allow-list.md +12 -0
- pal_found_cli/widgets/scripts/__init__.py +1 -0
- pal_found_cli/widgets/scripts/pal_found_widgets_cli.py +571 -0
- pal_found_cli-0.1.2.dist-info/METADATA +74 -0
- pal_found_cli-0.1.2.dist-info/RECORD +89 -0
- pal_found_cli-0.1.2.dist-info/WHEEL +5 -0
- pal_found_cli-0.1.2.dist-info/entry_points.txt +19 -0
- pal_found_cli-0.1.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1225 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Foundry Ontologies CLI - 67 canonical API v2 operations."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import asyncio
|
|
8
|
+
import inspect
|
|
9
|
+
import json
|
|
10
|
+
import logging
|
|
11
|
+
import sys
|
|
12
|
+
from collections.abc import AsyncIterable, Iterable
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
_SCRIPT_DIR = Path(__file__).resolve().parent
|
|
17
|
+
_PROJECT_ROOT: str | None = None
|
|
18
|
+
_candidate = _SCRIPT_DIR
|
|
19
|
+
for _depth in range(8):
|
|
20
|
+
if (_candidate / "src" / "pal_found_cli" / "__init__.py").exists():
|
|
21
|
+
_PROJECT_ROOT = str(_candidate)
|
|
22
|
+
break
|
|
23
|
+
if _candidate.parent == _candidate:
|
|
24
|
+
break
|
|
25
|
+
_candidate = _candidate.parent
|
|
26
|
+
if _PROJECT_ROOT is None:
|
|
27
|
+
_PROJECT_ROOT = str(_SCRIPT_DIR.parents[4])
|
|
28
|
+
if _PROJECT_ROOT not in sys.path:
|
|
29
|
+
sys.path.insert(0, _PROJECT_ROOT)
|
|
30
|
+
|
|
31
|
+
from pal_found_cli.common.access_control_guard import (
|
|
32
|
+
AccessControlError,
|
|
33
|
+
AccessControlGuard,
|
|
34
|
+
)
|
|
35
|
+
from pal_found_cli.common.async_client_factory import AsyncClientFactory
|
|
36
|
+
from pal_found_cli.common.binary_download_handler import BinaryDownloadHandler
|
|
37
|
+
from pal_found_cli.common.config_loader import ConfigLoader
|
|
38
|
+
from pal_found_cli.common.error_serializer import (
|
|
39
|
+
EXIT_ACCESS_CONTROL,
|
|
40
|
+
EXIT_NOT_FOUND,
|
|
41
|
+
EXIT_PERMISSION_DENIED,
|
|
42
|
+
EXIT_RATE_LIMIT,
|
|
43
|
+
EXIT_SERVER_ERROR,
|
|
44
|
+
EXIT_SUCCESS,
|
|
45
|
+
EXIT_TIMEOUT,
|
|
46
|
+
EXIT_USER_INPUT,
|
|
47
|
+
ErrorSerializer,
|
|
48
|
+
)
|
|
49
|
+
from pal_found_cli.common.log_setup import LogSetup
|
|
50
|
+
from pal_found_cli.common.output_formatter import OutputFormatter
|
|
51
|
+
from pal_found_cli.common.pagination_helper import PaginationHelper
|
|
52
|
+
from pal_found_cli.common.retry import RetryHandler
|
|
53
|
+
|
|
54
|
+
logger = logging.getLogger(__name__)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
OperationSpec = dict[str, Any]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _op(
|
|
61
|
+
resource: str,
|
|
62
|
+
operation: str,
|
|
63
|
+
client_path: str,
|
|
64
|
+
method: str,
|
|
65
|
+
positional: Iterable[str] = (),
|
|
66
|
+
optional: Iterable[str] = (),
|
|
67
|
+
*,
|
|
68
|
+
json_args: Iterable[str] = (),
|
|
69
|
+
binary_download: bool = False,
|
|
70
|
+
binary_upload: bool = False,
|
|
71
|
+
) -> OperationSpec:
|
|
72
|
+
return {
|
|
73
|
+
"resource": resource,
|
|
74
|
+
"operation": operation,
|
|
75
|
+
"client_path": client_path,
|
|
76
|
+
"method": method,
|
|
77
|
+
"positional": tuple(positional),
|
|
78
|
+
"optional": tuple(optional),
|
|
79
|
+
"json_args": frozenset(json_args),
|
|
80
|
+
"binary_download": binary_download,
|
|
81
|
+
"binary_upload": binary_upload,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
OP_SPECS: tuple[OperationSpec, ...] = (
|
|
86
|
+
_op(
|
|
87
|
+
"action",
|
|
88
|
+
"apply",
|
|
89
|
+
"Action",
|
|
90
|
+
"apply",
|
|
91
|
+
("ontology", "action"),
|
|
92
|
+
(
|
|
93
|
+
"parameters",
|
|
94
|
+
"branch",
|
|
95
|
+
"options",
|
|
96
|
+
"sdk_package_rid",
|
|
97
|
+
"sdk_version",
|
|
98
|
+
"transaction_id",
|
|
99
|
+
),
|
|
100
|
+
json_args=("parameters", "options"),
|
|
101
|
+
),
|
|
102
|
+
_op(
|
|
103
|
+
"action",
|
|
104
|
+
"apply_batch",
|
|
105
|
+
"Action",
|
|
106
|
+
"apply_batch",
|
|
107
|
+
("ontology", "action"),
|
|
108
|
+
("requests", "branch", "options", "sdk_package_rid", "sdk_version"),
|
|
109
|
+
json_args=("requests", "options"),
|
|
110
|
+
),
|
|
111
|
+
_op(
|
|
112
|
+
"action",
|
|
113
|
+
"apply_with_overrides",
|
|
114
|
+
"Action",
|
|
115
|
+
"apply_with_overrides",
|
|
116
|
+
("ontology", "action"),
|
|
117
|
+
(
|
|
118
|
+
"overrides",
|
|
119
|
+
"request",
|
|
120
|
+
"branch",
|
|
121
|
+
"sdk_package_rid",
|
|
122
|
+
"sdk_version",
|
|
123
|
+
"transaction_id",
|
|
124
|
+
),
|
|
125
|
+
json_args=("overrides", "request"),
|
|
126
|
+
),
|
|
127
|
+
_op(
|
|
128
|
+
"action_type",
|
|
129
|
+
"get",
|
|
130
|
+
"Ontology.ActionType",
|
|
131
|
+
"get",
|
|
132
|
+
("ontology", "action_type"),
|
|
133
|
+
("branch",),
|
|
134
|
+
),
|
|
135
|
+
_op(
|
|
136
|
+
"action_type",
|
|
137
|
+
"get_by_rid",
|
|
138
|
+
"Ontology.ActionType",
|
|
139
|
+
"get_by_rid",
|
|
140
|
+
("ontology", "action_type_rid"),
|
|
141
|
+
("branch",),
|
|
142
|
+
),
|
|
143
|
+
_op(
|
|
144
|
+
"action_type",
|
|
145
|
+
"get_by_rid_batch",
|
|
146
|
+
"Ontology.ActionType",
|
|
147
|
+
"get_by_rid_batch",
|
|
148
|
+
("ontology",),
|
|
149
|
+
("requests", "branch"),
|
|
150
|
+
json_args=("requests",),
|
|
151
|
+
),
|
|
152
|
+
_op(
|
|
153
|
+
"action_type",
|
|
154
|
+
"list",
|
|
155
|
+
"Ontology.ActionType",
|
|
156
|
+
"list",
|
|
157
|
+
("ontology",),
|
|
158
|
+
("branch", "page_size", "page_token"),
|
|
159
|
+
),
|
|
160
|
+
_op(
|
|
161
|
+
"action_type_full_metadata",
|
|
162
|
+
"get",
|
|
163
|
+
"ActionTypeFullMetadata",
|
|
164
|
+
"get",
|
|
165
|
+
("ontology", "action_type"),
|
|
166
|
+
("branch",),
|
|
167
|
+
),
|
|
168
|
+
_op(
|
|
169
|
+
"action_type_full_metadata",
|
|
170
|
+
"list",
|
|
171
|
+
"ActionTypeFullMetadata",
|
|
172
|
+
"list",
|
|
173
|
+
("ontology",),
|
|
174
|
+
("branch", "object_type_api_names", "page_size", "page_token"),
|
|
175
|
+
json_args=("object_type_api_names",),
|
|
176
|
+
),
|
|
177
|
+
_op("attachment", "get", "Attachment", "get", ("attachment_rid",)),
|
|
178
|
+
_op(
|
|
179
|
+
"attachment",
|
|
180
|
+
"read",
|
|
181
|
+
"Attachment",
|
|
182
|
+
"read",
|
|
183
|
+
("attachment_rid",),
|
|
184
|
+
binary_download=True,
|
|
185
|
+
),
|
|
186
|
+
_op(
|
|
187
|
+
"attachment",
|
|
188
|
+
"upload",
|
|
189
|
+
"Attachment",
|
|
190
|
+
"upload",
|
|
191
|
+
(),
|
|
192
|
+
("content_length", "content_type", "filename"),
|
|
193
|
+
binary_upload=True,
|
|
194
|
+
),
|
|
195
|
+
_op(
|
|
196
|
+
"attachment",
|
|
197
|
+
"upload_with_rid",
|
|
198
|
+
"Attachment",
|
|
199
|
+
"upload_with_rid",
|
|
200
|
+
("attachment_rid",),
|
|
201
|
+
("content_length", "content_type", "filename", "preview"),
|
|
202
|
+
binary_upload=True,
|
|
203
|
+
),
|
|
204
|
+
_op(
|
|
205
|
+
"attachment_property",
|
|
206
|
+
"get_attachment",
|
|
207
|
+
"AttachmentProperty",
|
|
208
|
+
"get_attachment",
|
|
209
|
+
("ontology", "object_type", "primary_key", "property"),
|
|
210
|
+
("sdk_package_rid", "sdk_version"),
|
|
211
|
+
),
|
|
212
|
+
_op(
|
|
213
|
+
"attachment_property",
|
|
214
|
+
"get_attachment_by_rid",
|
|
215
|
+
"AttachmentProperty",
|
|
216
|
+
"get_attachment_by_rid",
|
|
217
|
+
("ontology", "object_type", "primary_key", "property", "attachment_rid"),
|
|
218
|
+
("sdk_package_rid", "sdk_version"),
|
|
219
|
+
),
|
|
220
|
+
_op(
|
|
221
|
+
"attachment_property",
|
|
222
|
+
"read_attachment",
|
|
223
|
+
"AttachmentProperty",
|
|
224
|
+
"read_attachment",
|
|
225
|
+
("ontology", "object_type", "primary_key", "property"),
|
|
226
|
+
("sdk_package_rid", "sdk_version"),
|
|
227
|
+
binary_download=True,
|
|
228
|
+
),
|
|
229
|
+
_op(
|
|
230
|
+
"attachment_property",
|
|
231
|
+
"read_attachment_by_rid",
|
|
232
|
+
"AttachmentProperty",
|
|
233
|
+
"read_attachment_by_rid",
|
|
234
|
+
("ontology", "object_type", "primary_key", "property", "attachment_rid"),
|
|
235
|
+
("sdk_package_rid", "sdk_version"),
|
|
236
|
+
binary_download=True,
|
|
237
|
+
),
|
|
238
|
+
_op(
|
|
239
|
+
"cipher_text_property",
|
|
240
|
+
"decrypt",
|
|
241
|
+
"CipherTextProperty",
|
|
242
|
+
"decrypt",
|
|
243
|
+
("ontology", "object_type", "primary_key", "property"),
|
|
244
|
+
),
|
|
245
|
+
_op(
|
|
246
|
+
"geotemporal_series_property",
|
|
247
|
+
"get_geotemporal_series_latest_value",
|
|
248
|
+
"GeotemporalSeriesProperty",
|
|
249
|
+
"get_geotemporal_series_latest_value",
|
|
250
|
+
("ontology", "object_type", "primary_key", "property_name"),
|
|
251
|
+
("sdk_package_rid", "sdk_version"),
|
|
252
|
+
),
|
|
253
|
+
_op(
|
|
254
|
+
"geotemporal_series_property",
|
|
255
|
+
"stream_geotemporal_series_historic_values",
|
|
256
|
+
"GeotemporalSeriesProperty",
|
|
257
|
+
"stream_geotemporal_series_historic_values",
|
|
258
|
+
("ontology", "object_type", "primary_key", "property_name"),
|
|
259
|
+
("range", "sdk_package_rid", "sdk_version"),
|
|
260
|
+
json_args=("range",),
|
|
261
|
+
binary_download=True,
|
|
262
|
+
),
|
|
263
|
+
_op(
|
|
264
|
+
"linked_object",
|
|
265
|
+
"get_linked_object",
|
|
266
|
+
"LinkedObject",
|
|
267
|
+
"get_linked_object",
|
|
268
|
+
(
|
|
269
|
+
"ontology",
|
|
270
|
+
"object_type",
|
|
271
|
+
"primary_key",
|
|
272
|
+
"link_type",
|
|
273
|
+
"linked_object_primary_key",
|
|
274
|
+
),
|
|
275
|
+
("branch", "exclude_rid", "sdk_package_rid", "sdk_version", "select"),
|
|
276
|
+
json_args=("select",),
|
|
277
|
+
),
|
|
278
|
+
_op(
|
|
279
|
+
"linked_object",
|
|
280
|
+
"list_linked_objects",
|
|
281
|
+
"LinkedObject",
|
|
282
|
+
"list_linked_objects",
|
|
283
|
+
("ontology", "object_type", "primary_key", "link_type"),
|
|
284
|
+
(
|
|
285
|
+
"branch",
|
|
286
|
+
"exclude_rid",
|
|
287
|
+
"order_by",
|
|
288
|
+
"page_size",
|
|
289
|
+
"page_token",
|
|
290
|
+
"sdk_package_rid",
|
|
291
|
+
"sdk_version",
|
|
292
|
+
"select",
|
|
293
|
+
"snapshot",
|
|
294
|
+
),
|
|
295
|
+
json_args=("order_by", "select"),
|
|
296
|
+
),
|
|
297
|
+
_op(
|
|
298
|
+
"media_reference_property",
|
|
299
|
+
"get_media_content",
|
|
300
|
+
"MediaReferenceProperty",
|
|
301
|
+
"get_media_content",
|
|
302
|
+
("ontology", "object_type", "primary_key", "property"),
|
|
303
|
+
("preview", "sdk_package_rid", "sdk_version"),
|
|
304
|
+
binary_download=True,
|
|
305
|
+
),
|
|
306
|
+
_op(
|
|
307
|
+
"media_reference_property",
|
|
308
|
+
"get_media_metadata",
|
|
309
|
+
"MediaReferenceProperty",
|
|
310
|
+
"get_media_metadata",
|
|
311
|
+
("ontology", "object_type", "primary_key", "property"),
|
|
312
|
+
("preview", "sdk_package_rid", "sdk_version"),
|
|
313
|
+
),
|
|
314
|
+
_op(
|
|
315
|
+
"media_reference_property",
|
|
316
|
+
"upload",
|
|
317
|
+
"MediaReferenceProperty",
|
|
318
|
+
"upload",
|
|
319
|
+
("ontology", "object_type", "property"),
|
|
320
|
+
("media_item_path", "preview"),
|
|
321
|
+
binary_upload=True,
|
|
322
|
+
),
|
|
323
|
+
_op(
|
|
324
|
+
"object_type",
|
|
325
|
+
"get",
|
|
326
|
+
"Ontology.ObjectType",
|
|
327
|
+
"get",
|
|
328
|
+
("ontology", "object_type"),
|
|
329
|
+
("branch",),
|
|
330
|
+
),
|
|
331
|
+
_op(
|
|
332
|
+
"object_type",
|
|
333
|
+
"get_by_rid_batch",
|
|
334
|
+
"Ontology.ObjectType",
|
|
335
|
+
"get_by_rid_batch",
|
|
336
|
+
("ontology",),
|
|
337
|
+
("requests", "branch"),
|
|
338
|
+
json_args=("requests",),
|
|
339
|
+
),
|
|
340
|
+
_op(
|
|
341
|
+
"object_type",
|
|
342
|
+
"get_edits_history",
|
|
343
|
+
"Ontology.ObjectType",
|
|
344
|
+
"get_edits_history",
|
|
345
|
+
("ontology", "object_type"),
|
|
346
|
+
(
|
|
347
|
+
"branch",
|
|
348
|
+
"filters",
|
|
349
|
+
"include_all_previous_properties",
|
|
350
|
+
"object_primary_key",
|
|
351
|
+
"page_size",
|
|
352
|
+
"page_token",
|
|
353
|
+
"sort_order",
|
|
354
|
+
),
|
|
355
|
+
json_args=("filters",),
|
|
356
|
+
),
|
|
357
|
+
_op(
|
|
358
|
+
"object_type",
|
|
359
|
+
"get_full_metadata",
|
|
360
|
+
"Ontology.ObjectType",
|
|
361
|
+
"get_full_metadata",
|
|
362
|
+
("ontology", "object_type"),
|
|
363
|
+
("branch", "preview", "sdk_package_rid", "sdk_version"),
|
|
364
|
+
),
|
|
365
|
+
_op(
|
|
366
|
+
"object_type",
|
|
367
|
+
"get_outgoing_link_type",
|
|
368
|
+
"Ontology.ObjectType",
|
|
369
|
+
"get_outgoing_link_type",
|
|
370
|
+
("ontology", "object_type", "link_type"),
|
|
371
|
+
("branch",),
|
|
372
|
+
),
|
|
373
|
+
_op(
|
|
374
|
+
"object_type",
|
|
375
|
+
"list",
|
|
376
|
+
"Ontology.ObjectType",
|
|
377
|
+
"list",
|
|
378
|
+
("ontology",),
|
|
379
|
+
("branch", "page_size", "page_token"),
|
|
380
|
+
),
|
|
381
|
+
_op(
|
|
382
|
+
"object_type",
|
|
383
|
+
"list_outgoing_link_types",
|
|
384
|
+
"Ontology.ObjectType",
|
|
385
|
+
"list_outgoing_link_types",
|
|
386
|
+
("ontology", "object_type"),
|
|
387
|
+
("branch", "page_size", "page_token"),
|
|
388
|
+
),
|
|
389
|
+
_op("ontology", "get", "Ontology", "get", ("ontology",)),
|
|
390
|
+
_op(
|
|
391
|
+
"ontology",
|
|
392
|
+
"get_full_metadata",
|
|
393
|
+
"Ontology",
|
|
394
|
+
"get_full_metadata",
|
|
395
|
+
("ontology",),
|
|
396
|
+
("branch",),
|
|
397
|
+
),
|
|
398
|
+
_op("ontology", "list", "Ontology", "list"),
|
|
399
|
+
_op(
|
|
400
|
+
"ontology",
|
|
401
|
+
"load_metadata",
|
|
402
|
+
"Ontology",
|
|
403
|
+
"load_metadata",
|
|
404
|
+
("ontology",),
|
|
405
|
+
(
|
|
406
|
+
"action_types",
|
|
407
|
+
"interface_types",
|
|
408
|
+
"link_types",
|
|
409
|
+
"object_types",
|
|
410
|
+
"query_types",
|
|
411
|
+
"branch",
|
|
412
|
+
"preview",
|
|
413
|
+
),
|
|
414
|
+
json_args=(
|
|
415
|
+
"action_types",
|
|
416
|
+
"interface_types",
|
|
417
|
+
"link_types",
|
|
418
|
+
"object_types",
|
|
419
|
+
"query_types",
|
|
420
|
+
),
|
|
421
|
+
),
|
|
422
|
+
_op(
|
|
423
|
+
"ontology_interface",
|
|
424
|
+
"aggregate",
|
|
425
|
+
"OntologyInterface",
|
|
426
|
+
"aggregate",
|
|
427
|
+
("ontology", "interface_type"),
|
|
428
|
+
("aggregation", "group_by", "accuracy", "branch", "preview", "where"),
|
|
429
|
+
json_args=("aggregation", "group_by", "where"),
|
|
430
|
+
),
|
|
431
|
+
_op(
|
|
432
|
+
"ontology_interface",
|
|
433
|
+
"get",
|
|
434
|
+
"OntologyInterface",
|
|
435
|
+
"get",
|
|
436
|
+
("ontology", "interface_type"),
|
|
437
|
+
("branch", "preview", "sdk_package_rid", "sdk_version"),
|
|
438
|
+
),
|
|
439
|
+
_op(
|
|
440
|
+
"ontology_interface",
|
|
441
|
+
"get_outgoing_interface_link_type",
|
|
442
|
+
"OntologyInterface",
|
|
443
|
+
"get_outgoing_interface_link_type",
|
|
444
|
+
("ontology", "interface_type", "interface_link_type"),
|
|
445
|
+
("branch",),
|
|
446
|
+
),
|
|
447
|
+
_op(
|
|
448
|
+
"ontology_interface",
|
|
449
|
+
"list",
|
|
450
|
+
"OntologyInterface",
|
|
451
|
+
"list",
|
|
452
|
+
("ontology",),
|
|
453
|
+
("branch", "page_size", "page_token", "preview"),
|
|
454
|
+
),
|
|
455
|
+
_op(
|
|
456
|
+
"ontology_interface",
|
|
457
|
+
"list_interface_linked_objects",
|
|
458
|
+
"OntologyInterface",
|
|
459
|
+
"list_interface_linked_objects",
|
|
460
|
+
(
|
|
461
|
+
"ontology",
|
|
462
|
+
"interface_type",
|
|
463
|
+
"object_type",
|
|
464
|
+
"primary_key",
|
|
465
|
+
"interface_link_type",
|
|
466
|
+
),
|
|
467
|
+
(
|
|
468
|
+
"branch",
|
|
469
|
+
"exclude_rid",
|
|
470
|
+
"order_by",
|
|
471
|
+
"page_size",
|
|
472
|
+
"page_token",
|
|
473
|
+
"preview",
|
|
474
|
+
"select",
|
|
475
|
+
"snapshot",
|
|
476
|
+
),
|
|
477
|
+
json_args=("order_by", "select"),
|
|
478
|
+
),
|
|
479
|
+
_op(
|
|
480
|
+
"ontology_interface",
|
|
481
|
+
"list_objects_for_interface",
|
|
482
|
+
"OntologyInterface",
|
|
483
|
+
"list_objects_for_interface",
|
|
484
|
+
("ontology", "interface_type"),
|
|
485
|
+
(
|
|
486
|
+
"branch",
|
|
487
|
+
"exclude_rid",
|
|
488
|
+
"order_by",
|
|
489
|
+
"page_size",
|
|
490
|
+
"page_token",
|
|
491
|
+
"preview",
|
|
492
|
+
"select",
|
|
493
|
+
"snapshot",
|
|
494
|
+
),
|
|
495
|
+
json_args=("order_by", "select"),
|
|
496
|
+
),
|
|
497
|
+
_op(
|
|
498
|
+
"ontology_interface",
|
|
499
|
+
"list_outgoing_interface_link_types",
|
|
500
|
+
"OntologyInterface",
|
|
501
|
+
"list_outgoing_interface_link_types",
|
|
502
|
+
("ontology", "interface_type"),
|
|
503
|
+
("branch",),
|
|
504
|
+
),
|
|
505
|
+
_op(
|
|
506
|
+
"ontology_interface",
|
|
507
|
+
"search",
|
|
508
|
+
"OntologyInterface",
|
|
509
|
+
"search",
|
|
510
|
+
("ontology", "interface_type"),
|
|
511
|
+
(
|
|
512
|
+
"augmented_interface_property_types",
|
|
513
|
+
"augmented_properties",
|
|
514
|
+
"augmented_shared_property_types",
|
|
515
|
+
"other_interface_types",
|
|
516
|
+
"selected_interface_property_types",
|
|
517
|
+
"selected_object_types",
|
|
518
|
+
"selected_shared_property_types",
|
|
519
|
+
"branch",
|
|
520
|
+
"order_by",
|
|
521
|
+
"page_size",
|
|
522
|
+
"page_token",
|
|
523
|
+
"preview",
|
|
524
|
+
"where",
|
|
525
|
+
),
|
|
526
|
+
json_args=(
|
|
527
|
+
"augmented_interface_property_types",
|
|
528
|
+
"augmented_properties",
|
|
529
|
+
"augmented_shared_property_types",
|
|
530
|
+
"other_interface_types",
|
|
531
|
+
"selected_interface_property_types",
|
|
532
|
+
"selected_object_types",
|
|
533
|
+
"selected_shared_property_types",
|
|
534
|
+
"order_by",
|
|
535
|
+
"where",
|
|
536
|
+
),
|
|
537
|
+
),
|
|
538
|
+
_op(
|
|
539
|
+
"ontology_object",
|
|
540
|
+
"aggregate",
|
|
541
|
+
"OntologyObject",
|
|
542
|
+
"aggregate",
|
|
543
|
+
("ontology", "object_type"),
|
|
544
|
+
(
|
|
545
|
+
"aggregation",
|
|
546
|
+
"group_by",
|
|
547
|
+
"accuracy",
|
|
548
|
+
"branch",
|
|
549
|
+
"sdk_package_rid",
|
|
550
|
+
"sdk_version",
|
|
551
|
+
"where",
|
|
552
|
+
),
|
|
553
|
+
json_args=("aggregation", "group_by", "where"),
|
|
554
|
+
),
|
|
555
|
+
_op(
|
|
556
|
+
"ontology_object",
|
|
557
|
+
"count",
|
|
558
|
+
"OntologyObject",
|
|
559
|
+
"count",
|
|
560
|
+
("ontology", "object_type"),
|
|
561
|
+
("branch", "sdk_package_rid", "sdk_version"),
|
|
562
|
+
),
|
|
563
|
+
_op(
|
|
564
|
+
"ontology_object",
|
|
565
|
+
"get",
|
|
566
|
+
"OntologyObject",
|
|
567
|
+
"get",
|
|
568
|
+
("ontology", "object_type", "primary_key"),
|
|
569
|
+
("branch", "exclude_rid", "sdk_package_rid", "sdk_version", "select"),
|
|
570
|
+
json_args=("select",),
|
|
571
|
+
),
|
|
572
|
+
_op(
|
|
573
|
+
"ontology_object",
|
|
574
|
+
"list",
|
|
575
|
+
"OntologyObject",
|
|
576
|
+
"list",
|
|
577
|
+
("ontology", "object_type"),
|
|
578
|
+
(
|
|
579
|
+
"branch",
|
|
580
|
+
"exclude_rid",
|
|
581
|
+
"order_by",
|
|
582
|
+
"page_size",
|
|
583
|
+
"page_token",
|
|
584
|
+
"sdk_package_rid",
|
|
585
|
+
"sdk_version",
|
|
586
|
+
"select",
|
|
587
|
+
"snapshot",
|
|
588
|
+
),
|
|
589
|
+
json_args=("order_by", "select"),
|
|
590
|
+
),
|
|
591
|
+
_op(
|
|
592
|
+
"ontology_object",
|
|
593
|
+
"search",
|
|
594
|
+
"OntologyObject",
|
|
595
|
+
"search",
|
|
596
|
+
("ontology", "object_type"),
|
|
597
|
+
(
|
|
598
|
+
"select",
|
|
599
|
+
"branch",
|
|
600
|
+
"exclude_rid",
|
|
601
|
+
"order_by",
|
|
602
|
+
"page_size",
|
|
603
|
+
"page_token",
|
|
604
|
+
"sdk_package_rid",
|
|
605
|
+
"sdk_version",
|
|
606
|
+
"select_v2",
|
|
607
|
+
"snapshot",
|
|
608
|
+
"where",
|
|
609
|
+
),
|
|
610
|
+
json_args=("select", "order_by", "select_v2", "where"),
|
|
611
|
+
),
|
|
612
|
+
_op(
|
|
613
|
+
"ontology_object_set",
|
|
614
|
+
"aggregate",
|
|
615
|
+
"OntologyObjectSet",
|
|
616
|
+
"aggregate",
|
|
617
|
+
("ontology",),
|
|
618
|
+
(
|
|
619
|
+
"aggregation",
|
|
620
|
+
"group_by",
|
|
621
|
+
"object_set",
|
|
622
|
+
"accuracy",
|
|
623
|
+
"branch",
|
|
624
|
+
"include_compute_usage",
|
|
625
|
+
"sdk_package_rid",
|
|
626
|
+
"sdk_version",
|
|
627
|
+
"transaction_id",
|
|
628
|
+
),
|
|
629
|
+
json_args=("aggregation", "group_by", "object_set"),
|
|
630
|
+
),
|
|
631
|
+
_op(
|
|
632
|
+
"ontology_object_set",
|
|
633
|
+
"create_temporary",
|
|
634
|
+
"OntologyObjectSet",
|
|
635
|
+
"create_temporary",
|
|
636
|
+
("ontology",),
|
|
637
|
+
("object_set", "branch", "sdk_package_rid", "sdk_version"),
|
|
638
|
+
json_args=("object_set",),
|
|
639
|
+
),
|
|
640
|
+
_op(
|
|
641
|
+
"ontology_object_set",
|
|
642
|
+
"get",
|
|
643
|
+
"OntologyObjectSet",
|
|
644
|
+
"get",
|
|
645
|
+
("ontology", "object_set_rid"),
|
|
646
|
+
),
|
|
647
|
+
_op(
|
|
648
|
+
"ontology_object_set",
|
|
649
|
+
"load",
|
|
650
|
+
"OntologyObjectSet",
|
|
651
|
+
"load",
|
|
652
|
+
("ontology",),
|
|
653
|
+
(
|
|
654
|
+
"object_set",
|
|
655
|
+
"select",
|
|
656
|
+
"branch",
|
|
657
|
+
"exclude_rid",
|
|
658
|
+
"include_compute_usage",
|
|
659
|
+
"load_property_securities",
|
|
660
|
+
"order_by",
|
|
661
|
+
"page_size",
|
|
662
|
+
"page_token",
|
|
663
|
+
"sdk_package_rid",
|
|
664
|
+
"sdk_version",
|
|
665
|
+
"select_v2",
|
|
666
|
+
"snapshot",
|
|
667
|
+
"transaction_id",
|
|
668
|
+
),
|
|
669
|
+
json_args=("object_set", "select", "order_by", "select_v2"),
|
|
670
|
+
),
|
|
671
|
+
_op(
|
|
672
|
+
"ontology_object_set",
|
|
673
|
+
"load_links",
|
|
674
|
+
"OntologyObjectSet",
|
|
675
|
+
"load_links",
|
|
676
|
+
("ontology",),
|
|
677
|
+
(
|
|
678
|
+
"links",
|
|
679
|
+
"object_set",
|
|
680
|
+
"branch",
|
|
681
|
+
"include_compute_usage",
|
|
682
|
+
"page_token",
|
|
683
|
+
"preview",
|
|
684
|
+
"sdk_package_rid",
|
|
685
|
+
"sdk_version",
|
|
686
|
+
),
|
|
687
|
+
json_args=("links", "object_set"),
|
|
688
|
+
),
|
|
689
|
+
_op(
|
|
690
|
+
"ontology_object_set",
|
|
691
|
+
"load_multiple_object_types",
|
|
692
|
+
"OntologyObjectSet",
|
|
693
|
+
"load_multiple_object_types",
|
|
694
|
+
("ontology",),
|
|
695
|
+
(
|
|
696
|
+
"object_set",
|
|
697
|
+
"select",
|
|
698
|
+
"branch",
|
|
699
|
+
"exclude_rid",
|
|
700
|
+
"include_compute_usage",
|
|
701
|
+
"load_property_securities",
|
|
702
|
+
"order_by",
|
|
703
|
+
"page_size",
|
|
704
|
+
"page_token",
|
|
705
|
+
"preview",
|
|
706
|
+
"sdk_package_rid",
|
|
707
|
+
"sdk_version",
|
|
708
|
+
"select_v2",
|
|
709
|
+
"snapshot",
|
|
710
|
+
"transaction_id",
|
|
711
|
+
),
|
|
712
|
+
json_args=("object_set", "select", "order_by", "select_v2"),
|
|
713
|
+
),
|
|
714
|
+
_op(
|
|
715
|
+
"ontology_object_set",
|
|
716
|
+
"load_objects_or_interfaces",
|
|
717
|
+
"OntologyObjectSet",
|
|
718
|
+
"load_objects_or_interfaces",
|
|
719
|
+
("ontology",),
|
|
720
|
+
(
|
|
721
|
+
"object_set",
|
|
722
|
+
"select",
|
|
723
|
+
"branch",
|
|
724
|
+
"exclude_rid",
|
|
725
|
+
"order_by",
|
|
726
|
+
"page_size",
|
|
727
|
+
"page_token",
|
|
728
|
+
"preview",
|
|
729
|
+
"sdk_package_rid",
|
|
730
|
+
"sdk_version",
|
|
731
|
+
"select_v2",
|
|
732
|
+
"snapshot",
|
|
733
|
+
"transaction_id",
|
|
734
|
+
),
|
|
735
|
+
json_args=("object_set", "select", "order_by", "select_v2"),
|
|
736
|
+
),
|
|
737
|
+
_op(
|
|
738
|
+
"ontology_transaction",
|
|
739
|
+
"post_edits",
|
|
740
|
+
"OntologyTransaction",
|
|
741
|
+
"post_edits",
|
|
742
|
+
("ontology", "transaction_id"),
|
|
743
|
+
("edits", "preview", "sdk_package_rid", "sdk_version"),
|
|
744
|
+
json_args=("edits",),
|
|
745
|
+
),
|
|
746
|
+
_op(
|
|
747
|
+
"ontology_value_type",
|
|
748
|
+
"get",
|
|
749
|
+
"OntologyValueType",
|
|
750
|
+
"get",
|
|
751
|
+
("ontology", "value_type"),
|
|
752
|
+
("preview",),
|
|
753
|
+
),
|
|
754
|
+
_op(
|
|
755
|
+
"ontology_value_type",
|
|
756
|
+
"list",
|
|
757
|
+
"OntologyValueType",
|
|
758
|
+
"list",
|
|
759
|
+
("ontology",),
|
|
760
|
+
("preview",),
|
|
761
|
+
),
|
|
762
|
+
_op(
|
|
763
|
+
"query",
|
|
764
|
+
"execute",
|
|
765
|
+
"Query",
|
|
766
|
+
"execute",
|
|
767
|
+
("ontology", "query_api_name"),
|
|
768
|
+
(
|
|
769
|
+
"parameters",
|
|
770
|
+
"attribution",
|
|
771
|
+
"branch",
|
|
772
|
+
"sdk_package_rid",
|
|
773
|
+
"sdk_version",
|
|
774
|
+
"transaction_id",
|
|
775
|
+
"version",
|
|
776
|
+
),
|
|
777
|
+
json_args=("parameters", "attribution"),
|
|
778
|
+
),
|
|
779
|
+
_op(
|
|
780
|
+
"query_type",
|
|
781
|
+
"get",
|
|
782
|
+
"Ontology.QueryType",
|
|
783
|
+
"get",
|
|
784
|
+
("ontology", "query_api_name"),
|
|
785
|
+
("sdk_package_rid", "sdk_version", "version"),
|
|
786
|
+
),
|
|
787
|
+
_op(
|
|
788
|
+
"query_type",
|
|
789
|
+
"list",
|
|
790
|
+
"Ontology.QueryType",
|
|
791
|
+
"list",
|
|
792
|
+
("ontology",),
|
|
793
|
+
("page_size", "page_token"),
|
|
794
|
+
),
|
|
795
|
+
_op(
|
|
796
|
+
"time_series_property_v2",
|
|
797
|
+
"get_first_point",
|
|
798
|
+
"TimeSeriesPropertyV2",
|
|
799
|
+
"get_first_point",
|
|
800
|
+
("ontology", "object_type", "primary_key", "property"),
|
|
801
|
+
("sdk_package_rid", "sdk_version"),
|
|
802
|
+
),
|
|
803
|
+
_op(
|
|
804
|
+
"time_series_property_v2",
|
|
805
|
+
"get_last_point",
|
|
806
|
+
"TimeSeriesPropertyV2",
|
|
807
|
+
"get_last_point",
|
|
808
|
+
("ontology", "object_type", "primary_key", "property"),
|
|
809
|
+
("sdk_package_rid", "sdk_version"),
|
|
810
|
+
),
|
|
811
|
+
_op(
|
|
812
|
+
"time_series_property_v2",
|
|
813
|
+
"stream_points",
|
|
814
|
+
"TimeSeriesPropertyV2",
|
|
815
|
+
"stream_points",
|
|
816
|
+
("ontology", "object_type", "primary_key", "property"),
|
|
817
|
+
("aggregate", "format", "range", "sdk_package_rid", "sdk_version"),
|
|
818
|
+
json_args=("aggregate", "range"),
|
|
819
|
+
binary_download=True,
|
|
820
|
+
),
|
|
821
|
+
_op(
|
|
822
|
+
"time_series_value_bank_property",
|
|
823
|
+
"get_latest_value",
|
|
824
|
+
"TimeSeriesValueBankProperty",
|
|
825
|
+
"get_latest_value",
|
|
826
|
+
("ontology", "object_type", "primary_key", "property_name"),
|
|
827
|
+
("sdk_package_rid", "sdk_version"),
|
|
828
|
+
),
|
|
829
|
+
_op(
|
|
830
|
+
"time_series_value_bank_property",
|
|
831
|
+
"stream_values",
|
|
832
|
+
"TimeSeriesValueBankProperty",
|
|
833
|
+
"stream_values",
|
|
834
|
+
("ontology", "object_type", "primary_key", "property"),
|
|
835
|
+
("range", "sdk_package_rid", "sdk_version"),
|
|
836
|
+
json_args=("range",),
|
|
837
|
+
binary_download=True,
|
|
838
|
+
),
|
|
839
|
+
)
|
|
840
|
+
|
|
841
|
+
OPERATION_BY_RESOURCE: dict[str, dict[str, OperationSpec]] = {}
|
|
842
|
+
for _spec in OP_SPECS:
|
|
843
|
+
OPERATION_BY_RESOURCE.setdefault(_spec["resource"], {})[_spec["operation"]] = _spec
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
def _model_to_dict(obj: Any) -> Any:
|
|
847
|
+
"""Convert SDK/Pydantic objects into JSON-serializable values."""
|
|
848
|
+
if obj is None:
|
|
849
|
+
return None
|
|
850
|
+
if isinstance(obj, (bytes, bytearray)):
|
|
851
|
+
return {"bytes": len(obj)}
|
|
852
|
+
if isinstance(obj, list):
|
|
853
|
+
return [_model_to_dict(item) for item in obj]
|
|
854
|
+
if isinstance(obj, dict):
|
|
855
|
+
return {key: _model_to_dict(value) for key, value in obj.items()}
|
|
856
|
+
try:
|
|
857
|
+
result = obj.to_dict()
|
|
858
|
+
if isinstance(result, dict):
|
|
859
|
+
return result
|
|
860
|
+
except (AttributeError, TypeError):
|
|
861
|
+
pass
|
|
862
|
+
try:
|
|
863
|
+
result = obj.model_dump()
|
|
864
|
+
if isinstance(result, dict):
|
|
865
|
+
return result
|
|
866
|
+
except (AttributeError, TypeError):
|
|
867
|
+
pass
|
|
868
|
+
try:
|
|
869
|
+
result = obj.dict()
|
|
870
|
+
if isinstance(result, dict):
|
|
871
|
+
return result
|
|
872
|
+
except (AttributeError, TypeError):
|
|
873
|
+
pass
|
|
874
|
+
return obj
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
def _resolve(resource: str, op: str) -> str:
|
|
878
|
+
"""Resolve CLI kebab-case operation name to SDK snake_case."""
|
|
879
|
+
return op.replace("-", "_")
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
def _kebab(name: str) -> str:
|
|
883
|
+
return name.replace("_", "-")
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
def _common_parser() -> argparse.ArgumentParser:
|
|
887
|
+
"""Build shared parser for global options."""
|
|
888
|
+
common = argparse.ArgumentParser(add_help=False)
|
|
889
|
+
common.add_argument("--timeout", type=int, default=None)
|
|
890
|
+
common.add_argument("--format", choices=["json", "toon", "auto"], default="auto")
|
|
891
|
+
common.add_argument("--pretty", action="store_true")
|
|
892
|
+
common.add_argument("--page-size", type=int, default=None, dest="page_size")
|
|
893
|
+
common.add_argument("--page-token", type=str, default=None, dest="page_token")
|
|
894
|
+
common.add_argument("--batch-pages", type=int, default=None, dest="batch_pages")
|
|
895
|
+
common.add_argument("--output-filename", default=None, dest="output_filename")
|
|
896
|
+
common.add_argument(
|
|
897
|
+
"--content-length", type=int, default=None, dest="content_length"
|
|
898
|
+
)
|
|
899
|
+
common.add_argument("--content-type", default=None, dest="content_type")
|
|
900
|
+
common.add_argument("--body-file", default=None, dest="body_file")
|
|
901
|
+
return common
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
905
|
+
"""Build argparse parser with all 67 ontology operations."""
|
|
906
|
+
parser = argparse.ArgumentParser(
|
|
907
|
+
prog="pal_found_ontologies_cli",
|
|
908
|
+
description="Foundry Ontologies CLI - 67 operations",
|
|
909
|
+
)
|
|
910
|
+
subparsers = parser.add_subparsers(dest="resource", help="Resource type")
|
|
911
|
+
|
|
912
|
+
for resource in sorted(OPERATION_BY_RESOURCE):
|
|
913
|
+
res_parser = subparsers.add_parser(_kebab(resource))
|
|
914
|
+
op_sub = res_parser.add_subparsers(dest="operation")
|
|
915
|
+
for operation, spec in sorted(OPERATION_BY_RESOURCE[resource].items()):
|
|
916
|
+
op_parser = op_sub.add_parser(_kebab(operation), parents=[_common_parser()])
|
|
917
|
+
for arg_name in spec["positional"]:
|
|
918
|
+
op_parser.add_argument(arg_name)
|
|
919
|
+
for arg_name in spec["optional"]:
|
|
920
|
+
if arg_name in {
|
|
921
|
+
"page_size",
|
|
922
|
+
"page_token",
|
|
923
|
+
"content_length",
|
|
924
|
+
"content_type",
|
|
925
|
+
}:
|
|
926
|
+
continue
|
|
927
|
+
if arg_name == "format":
|
|
928
|
+
op_parser.add_argument(
|
|
929
|
+
"--stream-format", default=None, dest="stream_format"
|
|
930
|
+
)
|
|
931
|
+
continue
|
|
932
|
+
flag = "--" + _kebab(arg_name)
|
|
933
|
+
if arg_name.startswith("include_") or arg_name in {
|
|
934
|
+
"preview",
|
|
935
|
+
"snapshot",
|
|
936
|
+
"exclude_rid",
|
|
937
|
+
"load_property_securities",
|
|
938
|
+
"include_all_previous_properties",
|
|
939
|
+
}:
|
|
940
|
+
op_parser.add_argument(
|
|
941
|
+
flag, action="store_true", default=None, dest=arg_name
|
|
942
|
+
)
|
|
943
|
+
else:
|
|
944
|
+
op_parser.add_argument(flag, default=None, dest=arg_name)
|
|
945
|
+
|
|
946
|
+
return parser
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
def _spec_for(resource: str, operation: str) -> OperationSpec:
|
|
950
|
+
try:
|
|
951
|
+
return OPERATION_BY_RESOURCE[resource][operation]
|
|
952
|
+
except KeyError as exc:
|
|
953
|
+
raise ValueError(f"Unknown operation: {resource}.{operation}") from exc
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
def _get_client(
|
|
957
|
+
cfg: ConfigLoader, resource: str, factory: AsyncClientFactory | None = None
|
|
958
|
+
) -> Any:
|
|
959
|
+
"""Get SDK client for an ontology resource."""
|
|
960
|
+
root = (factory or AsyncClientFactory()).create(cfg).ontologies
|
|
961
|
+
spec = next(iter(OPERATION_BY_RESOURCE[resource].values()))
|
|
962
|
+
client = root
|
|
963
|
+
for attr in spec["client_path"].split("."):
|
|
964
|
+
client = getattr(client, attr)
|
|
965
|
+
return client
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
def _coerce_arg(value: Any, *, json_arg: bool) -> Any:
|
|
969
|
+
if value is None:
|
|
970
|
+
return None
|
|
971
|
+
if json_arg and isinstance(value, str):
|
|
972
|
+
return json.loads(value)
|
|
973
|
+
return value
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
def _read_binary_body(args: argparse.Namespace) -> bytes:
|
|
977
|
+
body_file = getattr(args, "body_file", None)
|
|
978
|
+
if not body_file:
|
|
979
|
+
raise ValueError("body_file is required for binary upload operations")
|
|
980
|
+
return Path(body_file).read_bytes()
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
async def _bytes_iter(
|
|
984
|
+
value: bytes | bytearray | AsyncIterable[bytes],
|
|
985
|
+
) -> AsyncIterable[bytes]:
|
|
986
|
+
if isinstance(value, (bytes, bytearray)):
|
|
987
|
+
yield bytes(value)
|
|
988
|
+
return
|
|
989
|
+
if isinstance(value, Iterable):
|
|
990
|
+
for chunk in value:
|
|
991
|
+
yield bytes(chunk)
|
|
992
|
+
return
|
|
993
|
+
async for chunk in value:
|
|
994
|
+
yield chunk
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
async def _resolve_result(value: Any) -> Any:
|
|
998
|
+
"""Await SDK calls that return awaitables; pass iterators through unchanged."""
|
|
999
|
+
if asyncio.isfuture(value) or inspect.isawaitable(value):
|
|
1000
|
+
return await value
|
|
1001
|
+
return value
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
async def _persist_binary_result(
|
|
1005
|
+
result: Any,
|
|
1006
|
+
*,
|
|
1007
|
+
cfg: ConfigLoader,
|
|
1008
|
+
resource: str,
|
|
1009
|
+
operation: str,
|
|
1010
|
+
args: argparse.Namespace,
|
|
1011
|
+
) -> dict[str, Any]:
|
|
1012
|
+
handler = BinaryDownloadHandler(config=cfg)
|
|
1013
|
+
download = await handler.save(
|
|
1014
|
+
_bytes_iter(result),
|
|
1015
|
+
original_filename=getattr(args, "output_filename", None),
|
|
1016
|
+
namespace="ontologies",
|
|
1017
|
+
operation=f"{resource}.{operation}",
|
|
1018
|
+
content_length=None,
|
|
1019
|
+
content_encoding=None,
|
|
1020
|
+
mime_type=None,
|
|
1021
|
+
)
|
|
1022
|
+
return download.to_dict()
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
async def _invoke(
|
|
1026
|
+
resource: str,
|
|
1027
|
+
operation: str,
|
|
1028
|
+
client: Any,
|
|
1029
|
+
args: argparse.Namespace,
|
|
1030
|
+
timeout: int | None,
|
|
1031
|
+
cfg: ConfigLoader | None = None,
|
|
1032
|
+
) -> Any:
|
|
1033
|
+
"""Invoke an ontology SDK operation."""
|
|
1034
|
+
spec = _spec_for(resource, operation)
|
|
1035
|
+
method = getattr(client, spec["method"])
|
|
1036
|
+
positional = [getattr(args, name) for name in spec["positional"]]
|
|
1037
|
+
kwargs: dict[str, Any] = {}
|
|
1038
|
+
|
|
1039
|
+
for name in spec["optional"]:
|
|
1040
|
+
if name in {"content_length", "content_type"}:
|
|
1041
|
+
continue
|
|
1042
|
+
if name == "format":
|
|
1043
|
+
value = getattr(args, "stream_format", None)
|
|
1044
|
+
if value is None and getattr(args, "format", None) not in {
|
|
1045
|
+
"json",
|
|
1046
|
+
"toon",
|
|
1047
|
+
"auto",
|
|
1048
|
+
}:
|
|
1049
|
+
value = getattr(args, "format", None)
|
|
1050
|
+
else:
|
|
1051
|
+
value = getattr(args, name, None)
|
|
1052
|
+
if value is not None:
|
|
1053
|
+
kwargs[name] = _coerce_arg(value, json_arg=name in spec["json_args"])
|
|
1054
|
+
|
|
1055
|
+
if spec["binary_upload"]:
|
|
1056
|
+
body = _read_binary_body(args)
|
|
1057
|
+
body_index = len(positional)
|
|
1058
|
+
if spec["resource"] in {"attachment", "media_reference_property"}:
|
|
1059
|
+
positional.insert(body_index, body)
|
|
1060
|
+
if spec["resource"] == "attachment":
|
|
1061
|
+
if not getattr(args, "filename", None):
|
|
1062
|
+
raise ValueError(
|
|
1063
|
+
"filename is required for attachment upload operations"
|
|
1064
|
+
)
|
|
1065
|
+
kwargs["content_length"] = getattr(args, "content_length", None) or len(
|
|
1066
|
+
body
|
|
1067
|
+
)
|
|
1068
|
+
kwargs["content_type"] = (
|
|
1069
|
+
getattr(args, "content_type", None) or "application/octet-stream"
|
|
1070
|
+
)
|
|
1071
|
+
|
|
1072
|
+
kwargs["request_timeout"] = timeout
|
|
1073
|
+
result = await _resolve_result(method(*positional, **kwargs))
|
|
1074
|
+
|
|
1075
|
+
if spec["binary_download"]:
|
|
1076
|
+
if cfg is None:
|
|
1077
|
+
cfg = ConfigLoader()
|
|
1078
|
+
return await _persist_binary_result(
|
|
1079
|
+
result,
|
|
1080
|
+
cfg=cfg,
|
|
1081
|
+
resource=resource,
|
|
1082
|
+
operation=operation,
|
|
1083
|
+
args=args,
|
|
1084
|
+
)
|
|
1085
|
+
return result
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
PAGINATED_OPS = frozenset(
|
|
1089
|
+
(spec["resource"], spec["operation"])
|
|
1090
|
+
for spec in OP_SPECS
|
|
1091
|
+
if "page_size" in spec["optional"] and "page_token" in spec["optional"]
|
|
1092
|
+
)
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
def _is_paginated(resource: str, operation: str) -> bool:
|
|
1096
|
+
"""Return true if operation supports SDK pagination args."""
|
|
1097
|
+
return (resource, operation) in PAGINATED_OPS
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
async def _invoke_paginated(
|
|
1101
|
+
resource: str,
|
|
1102
|
+
operation: str,
|
|
1103
|
+
client: Any,
|
|
1104
|
+
args: argparse.Namespace,
|
|
1105
|
+
timeout: int | None,
|
|
1106
|
+
helper: PaginationHelper,
|
|
1107
|
+
cfg: ConfigLoader,
|
|
1108
|
+
) -> Any:
|
|
1109
|
+
"""Invoke a paginated ontology operation through PaginationHelper."""
|
|
1110
|
+
|
|
1111
|
+
async def _single_page(**page_kwargs: Any) -> Any:
|
|
1112
|
+
paged_args = argparse.Namespace(**vars(args))
|
|
1113
|
+
paged_args.page_size = page_kwargs.get(
|
|
1114
|
+
"page_size", getattr(args, "page_size", None)
|
|
1115
|
+
)
|
|
1116
|
+
paged_args.page_token = page_kwargs.get("page_token", None)
|
|
1117
|
+
return await _invoke(resource, operation, client, paged_args, timeout, cfg)
|
|
1118
|
+
|
|
1119
|
+
return await helper.paginate(_single_page)
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
async def main() -> int:
|
|
1123
|
+
"""Run the Foundry Ontologies CLI."""
|
|
1124
|
+
parser = build_parser()
|
|
1125
|
+
args = parser.parse_args()
|
|
1126
|
+
if not args.resource:
|
|
1127
|
+
parser.print_help()
|
|
1128
|
+
return EXIT_USER_INPUT
|
|
1129
|
+
if not getattr(args, "operation", None):
|
|
1130
|
+
parser.print_help()
|
|
1131
|
+
return EXIT_USER_INPUT
|
|
1132
|
+
|
|
1133
|
+
cfg = ConfigLoader()
|
|
1134
|
+
cfg.load()
|
|
1135
|
+
LogSetup.configure(log_level=cfg.log_level)
|
|
1136
|
+
|
|
1137
|
+
resource = args.resource.replace("-", "_")
|
|
1138
|
+
operation = _resolve(resource, args.operation)
|
|
1139
|
+
logger.info(
|
|
1140
|
+
"Executing operation", extra={"resource": resource, "operation": operation}
|
|
1141
|
+
)
|
|
1142
|
+
|
|
1143
|
+
try:
|
|
1144
|
+
_spec_for(resource, operation)
|
|
1145
|
+
except ValueError as exc:
|
|
1146
|
+
ErrorSerializer().serialize(exc)
|
|
1147
|
+
return EXIT_USER_INPUT
|
|
1148
|
+
|
|
1149
|
+
try:
|
|
1150
|
+
AccessControlGuard(cfg, "ONTOLOGIES").check(resource, operation)
|
|
1151
|
+
except AccessControlError as exc:
|
|
1152
|
+
ErrorSerializer().serialize(exc)
|
|
1153
|
+
return EXIT_ACCESS_CONTROL
|
|
1154
|
+
|
|
1155
|
+
factory = AsyncClientFactory()
|
|
1156
|
+
try:
|
|
1157
|
+
with factory.invocation_scope(cfg):
|
|
1158
|
+
client = _get_client(cfg, resource, factory)
|
|
1159
|
+
timeout = getattr(args, "timeout", None) or getattr(cfg, "timeout_s", None)
|
|
1160
|
+
retry_handler = RetryHandler()
|
|
1161
|
+
helper: PaginationHelper | None = None
|
|
1162
|
+
if _is_paginated(resource, operation):
|
|
1163
|
+
helper = PaginationHelper(
|
|
1164
|
+
page_size=getattr(args, "page_size", None),
|
|
1165
|
+
page_token=getattr(args, "page_token", None),
|
|
1166
|
+
batch_pages=getattr(args, "batch_pages", None),
|
|
1167
|
+
)
|
|
1168
|
+
if helper is not None:
|
|
1169
|
+
result = await retry_handler.execute(
|
|
1170
|
+
_invoke_paginated,
|
|
1171
|
+
resource,
|
|
1172
|
+
operation,
|
|
1173
|
+
client,
|
|
1174
|
+
args,
|
|
1175
|
+
timeout,
|
|
1176
|
+
helper,
|
|
1177
|
+
cfg,
|
|
1178
|
+
)
|
|
1179
|
+
else:
|
|
1180
|
+
result = await retry_handler.execute(
|
|
1181
|
+
_invoke,
|
|
1182
|
+
resource,
|
|
1183
|
+
operation,
|
|
1184
|
+
client,
|
|
1185
|
+
args,
|
|
1186
|
+
timeout,
|
|
1187
|
+
cfg,
|
|
1188
|
+
)
|
|
1189
|
+
formatter = OutputFormatter(
|
|
1190
|
+
format_setting=getattr(args, "format", "auto"),
|
|
1191
|
+
pretty=getattr(args, "pretty", False),
|
|
1192
|
+
)
|
|
1193
|
+
print(formatter.format(_model_to_dict(result)))
|
|
1194
|
+
if helper is not None:
|
|
1195
|
+
helper.emit_metadata()
|
|
1196
|
+
return EXIT_SUCCESS
|
|
1197
|
+
except PermissionError as exc:
|
|
1198
|
+
ErrorSerializer().serialize(exc)
|
|
1199
|
+
return EXIT_PERMISSION_DENIED
|
|
1200
|
+
except FileNotFoundError as exc:
|
|
1201
|
+
ErrorSerializer().serialize(exc)
|
|
1202
|
+
return EXIT_NOT_FOUND
|
|
1203
|
+
except TimeoutError as exc:
|
|
1204
|
+
ErrorSerializer().serialize(exc)
|
|
1205
|
+
return EXIT_TIMEOUT
|
|
1206
|
+
except ValueError as exc:
|
|
1207
|
+
ErrorSerializer().serialize(exc)
|
|
1208
|
+
return EXIT_USER_INPUT
|
|
1209
|
+
except OSError as exc:
|
|
1210
|
+
exit_code = ErrorSerializer().serialize(exc)
|
|
1211
|
+
if getattr(exc, "errno", None) in (11, 115):
|
|
1212
|
+
return EXIT_RATE_LIMIT
|
|
1213
|
+
return exit_code
|
|
1214
|
+
except Exception as exc:
|
|
1215
|
+
ErrorSerializer().serialize(exc)
|
|
1216
|
+
return EXIT_SERVER_ERROR
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
def console_main() -> int:
|
|
1220
|
+
"""Run the async CLI from the console script entry point."""
|
|
1221
|
+
return asyncio.run(main())
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
if __name__ == "__main__":
|
|
1225
|
+
sys.exit(console_main())
|