octostar-python-client 0.1.759__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.
- octostar/__init__.py +9 -0
- octostar/api/__init__.py +1 -0
- octostar/api/apps/__init__.py +0 -0
- octostar/api/apps/deploy_app.py +210 -0
- octostar/api/apps/execute_app_job.py +188 -0
- octostar/api/apps/get_app_logs.py +210 -0
- octostar/api/apps/get_apps_url.py +188 -0
- octostar/api/apps/get_job_logs.py +210 -0
- octostar/api/apps/get_job_progress.py +162 -0
- octostar/api/apps/kill_job.py +160 -0
- octostar/api/apps/list_app_jobs.py +276 -0
- octostar/api/apps/list_apps.py +251 -0
- octostar/api/apps/set_job_progress.py +216 -0
- octostar/api/apps/undeploy_app.py +160 -0
- octostar/api/metadata/__init__.py +0 -0
- octostar/api/metadata/get_version.py +232 -0
- octostar/api/metadata/get_whoami.py +232 -0
- octostar/api/notifications/__init__.py +0 -0
- octostar/api/notifications/delete_stream.py +222 -0
- octostar/api/notifications/get_subscriptions.py +240 -0
- octostar/api/notifications/publish_notification.py +275 -0
- octostar/api/notifications/pull_events_from_stream.py +282 -0
- octostar/api/notifications/push_event_to_stream.py +265 -0
- octostar/api/notifications/toast.py +264 -0
- octostar/api/ontology/__init__.py +0 -0
- octostar/api/ontology/fetch_ontology_data.py +275 -0
- octostar/api/ontology/get_ontologies.py +237 -0
- octostar/api/ontology/multi_query.py +297 -0
- octostar/api/ontology/query.py +276 -0
- octostar/api/pipeline/__init__.py +1 -0
- octostar/api/pipeline/get_processing_status.py +185 -0
- octostar/api/pipeline/update_processing_status.py +164 -0
- octostar/api/search/__init__.py +0 -0
- octostar/api/search/get_annotations.py +153 -0
- octostar/api/workspace_data/__init__.py +0 -0
- octostar/api/workspace_data/delete_blob.py +212 -0
- octostar/api/workspace_data/delete_entities.py +326 -0
- octostar/api/workspace_data/download_blob.py +235 -0
- octostar/api/workspace_data/get_attachment.py +336 -0
- octostar/api/workspace_data/get_files_tree.py +397 -0
- octostar/api/workspace_data/upload_blob.py +235 -0
- octostar/api/workspace_data/upsert_entities.py +284 -0
- octostar/api/workspace_permissions/__init__.py +0 -0
- octostar/api/workspace_permissions/get_permissions.py +325 -0
- octostar/api/workspace_tags/__init__.py +0 -0
- octostar/api/workspace_tags/delete_tag_from_entities.py +141 -0
- octostar/api/workspace_tags/tag_entities.py +180 -0
- octostar/client.py +492 -0
- octostar/errors.py +50 -0
- octostar/models/__init__.py +249 -0
- octostar/models/acknowledgement.py +74 -0
- octostar/models/acknowledgement_with_data.py +82 -0
- octostar/models/app_status.py +239 -0
- octostar/models/app_status_annotations.py +66 -0
- octostar/models/app_status_labels.py +69 -0
- octostar/models/app_with_url.py +82 -0
- octostar/models/child_processing_status.py +118 -0
- octostar/models/delete_entities_response_401.py +74 -0
- octostar/models/delete_entities_response_409.py +82 -0
- octostar/models/delete_entities_response_500.py +82 -0
- octostar/models/delete_stream_response_401.py +74 -0
- octostar/models/delete_tag_from_entities_response_401.py +74 -0
- octostar/models/deploy_app_json_body.py +90 -0
- octostar/models/deploy_app_json_body_secrets.py +65 -0
- octostar/models/deploy_app_response_200.py +98 -0
- octostar/models/deploy_app_response_200_data.py +60 -0
- octostar/models/deploy_app_response_400.py +82 -0
- octostar/models/deploy_app_response_403.py +82 -0
- octostar/models/deploy_app_response_404.py +82 -0
- octostar/models/deploy_app_response_409.py +82 -0
- octostar/models/deploy_app_response_500.py +82 -0
- octostar/models/entity.py +80 -0
- octostar/models/entity_response.py +99 -0
- octostar/models/entity_response_s3_urls.py +93 -0
- octostar/models/entity_response_s3_urls_additional_property.py +105 -0
- octostar/models/entity_response_s3_urls_additional_property_fields.py +114 -0
- octostar/models/execute_app_job_json_body.py +151 -0
- octostar/models/execute_app_job_json_body_annotation.py +65 -0
- octostar/models/execute_app_job_response_401.py +74 -0
- octostar/models/fetch_ontology_data_response_200.py +60 -0
- octostar/models/fetch_ontology_data_response_401.py +74 -0
- octostar/models/fetch_ontology_data_response_500.py +82 -0
- octostar/models/get_app_logs_response_401.py +74 -0
- octostar/models/get_app_logs_response_404.py +74 -0
- octostar/models/get_app_logs_response_500.py +82 -0
- octostar/models/get_apps_url_json_body.py +76 -0
- octostar/models/get_apps_url_response_401.py +74 -0
- octostar/models/get_apps_url_response_500.py +82 -0
- octostar/models/get_attachment_response_200.py +74 -0
- octostar/models/get_attachment_response_401.py +74 -0
- octostar/models/get_files_tree_response_200.py +106 -0
- octostar/models/get_files_tree_response_200_status.py +8 -0
- octostar/models/get_files_tree_response_400.py +111 -0
- octostar/models/get_files_tree_response_400_data.py +60 -0
- octostar/models/get_files_tree_response_400_status.py +8 -0
- octostar/models/get_files_tree_response_401.py +74 -0
- octostar/models/get_files_tree_response_500.py +111 -0
- octostar/models/get_files_tree_response_500_data.py +60 -0
- octostar/models/get_files_tree_response_500_status.py +8 -0
- octostar/models/get_job_logs_response_401.py +74 -0
- octostar/models/get_job_logs_response_404.py +74 -0
- octostar/models/get_job_logs_response_500.py +82 -0
- octostar/models/get_job_progress_response_401.py +74 -0
- octostar/models/get_object_response_401.py +74 -0
- octostar/models/get_ontologies_response_401.py +74 -0
- octostar/models/get_ontologies_response_500.py +81 -0
- octostar/models/get_permissions_response_200.py +98 -0
- octostar/models/get_permissions_response_400.py +82 -0
- octostar/models/get_permissions_response_401.py +74 -0
- octostar/models/get_permissions_response_500.py +82 -0
- octostar/models/get_processing_status_response_200.py +104 -0
- octostar/models/get_processing_status_response_200_data.py +87 -0
- octostar/models/get_processing_status_response_400.py +82 -0
- octostar/models/get_processing_status_response_500.py +82 -0
- octostar/models/get_subscriptions_response_200_item.py +74 -0
- octostar/models/get_version_response_200.py +74 -0
- octostar/models/get_version_response_404.py +74 -0
- octostar/models/get_whoami_response_200.py +129 -0
- octostar/models/get_whoami_response_401.py +74 -0
- octostar/models/insert_entity.py +114 -0
- octostar/models/insert_entity_base.py +266 -0
- octostar/models/insert_entity_relationships_item.py +107 -0
- octostar/models/insert_entity_request.py +94 -0
- octostar/models/internal_server_error.py +82 -0
- octostar/models/job_execution_result.py +146 -0
- octostar/models/job_status.py +196 -0
- octostar/models/job_status_labels.py +60 -0
- octostar/models/job_with_url.py +82 -0
- octostar/models/kill_job_response_401.py +74 -0
- octostar/models/list_app_jobs_response_401.py +74 -0
- octostar/models/list_app_jobs_response_500.py +82 -0
- octostar/models/list_apps_response_401.py +74 -0
- octostar/models/list_apps_response_500.py +82 -0
- octostar/models/multi_query_json_body.py +100 -0
- octostar/models/multi_query_json_body_queries_item.py +80 -0
- octostar/models/multi_query_response_400.py +82 -0
- octostar/models/multi_query_response_401.py +74 -0
- octostar/models/not_found_error.py +74 -0
- octostar/models/octostar_event.py +96 -0
- octostar/models/octostar_event_octostar_payload.py +100 -0
- octostar/models/octostar_event_octostar_payload_level.py +11 -0
- octostar/models/os_notification.py +122 -0
- octostar/models/processing_status.py +262 -0
- octostar/models/processing_status_code.py +14 -0
- octostar/models/progress_request.py +73 -0
- octostar/models/publish_notification_response_401.py +74 -0
- octostar/models/pull_events_from_stream_response_401.py +74 -0
- octostar/models/push_event_to_stream_response_401.py +74 -0
- octostar/models/query_json_body.py +101 -0
- octostar/models/query_json_body_params.py +60 -0
- octostar/models/query_response_400.py +82 -0
- octostar/models/query_response_401.py +74 -0
- octostar/models/set_job_progress_response_401.py +74 -0
- octostar/models/string_to_value_label_map.py +99 -0
- octostar/models/string_to_value_label_map_data.py +89 -0
- octostar/models/string_to_value_label_map_data_additional_property.py +80 -0
- octostar/models/successful_get_tags.py +103 -0
- octostar/models/successful_insertion.py +98 -0
- octostar/models/tag_entities_response_401.py +74 -0
- octostar/models/toast_level.py +11 -0
- octostar/models/toast_response_401.py +74 -0
- octostar/models/undeploy_app_response_401.py +74 -0
- octostar/models/update_processing_status_response_200.py +82 -0
- octostar/models/update_processing_status_response_400.py +82 -0
- octostar/models/update_processing_status_response_500.py +82 -0
- octostar/models/upsert_entities_response_401.py +74 -0
- octostar/models/upsert_entity.py +114 -0
- octostar/models/upsert_entity_base.py +266 -0
- octostar/models/upsert_entity_relationships_item.py +107 -0
- octostar/py.typed +1 -0
- octostar/types.py +54 -0
- octostar/utils/__init__.py +15 -0
- octostar/utils/chat/__init__.py +0 -0
- octostar/utils/chat/chat.py +513 -0
- octostar/utils/chat/detokenize.py +105 -0
- octostar/utils/chat/get_default_model.py +50 -0
- octostar/utils/chat/list_models.py +91 -0
- octostar/utils/chat/tokenize.py +105 -0
- octostar/utils/commons.py +226 -0
- octostar/utils/exceptions.py +134 -0
- octostar/utils/jobs/__init__.py +0 -0
- octostar/utils/jobs/apps/__init__.py +0 -0
- octostar/utils/jobs/apps/deploy_app.py +81 -0
- octostar/utils/jobs/apps/execute_app_job.py +114 -0
- octostar/utils/jobs/apps/get_app_logs.py +113 -0
- octostar/utils/jobs/apps/get_app_secret.py +102 -0
- octostar/utils/jobs/apps/get_apps_url.py +73 -0
- octostar/utils/jobs/apps/list_app_jobs.py +62 -0
- octostar/utils/jobs/apps/list_apps.py +126 -0
- octostar/utils/jobs/apps/undeploy_app.py +48 -0
- octostar/utils/jobs/get_job_logs.py +113 -0
- octostar/utils/jobs/get_job_progress.py +76 -0
- octostar/utils/jobs/kill_job.py +47 -0
- octostar/utils/jobs/set_job_progress.py +67 -0
- octostar/utils/meta/__init__.py +0 -0
- octostar/utils/meta/get_version.py +30 -0
- octostar/utils/meta/get_whoami.py +30 -0
- octostar/utils/notifications/__init__.py +0 -0
- octostar/utils/notifications/delete_stream.py +58 -0
- octostar/utils/notifications/get_my_subscriptions.py +49 -0
- octostar/utils/notifications/publish_notification.py +73 -0
- octostar/utils/notifications/pull_event_from_stream.py +63 -0
- octostar/utils/notifications/pull_events_from_stream.py +64 -0
- octostar/utils/notifications/push_event_to_stream.py +109 -0
- octostar/utils/notifications/push_events_to_stream.py +137 -0
- octostar/utils/notifications/toast.py +92 -0
- octostar/utils/ontology/__init__.py +10 -0
- octostar/utils/ontology/fetch_ontology_data.py +141 -0
- octostar/utils/ontology/get_ontologies.py +55 -0
- octostar/utils/ontology/multiquery_ontology.py +287 -0
- octostar/utils/ontology/query_ontology.py +186 -0
- octostar/utils/pipeline/__init__.py +1 -0
- octostar/utils/pipeline/get_processing_status.py +230 -0
- octostar/utils/pipeline/update_processing_status.py +286 -0
- octostar/utils/search/__init__.py +11 -0
- octostar/utils/search/bulk_update.py +138 -0
- octostar/utils/search/count.py +117 -0
- octostar/utils/search/get_entity_annotations.py +304 -0
- octostar/utils/search/get_index_definition.py +111 -0
- octostar/utils/search/multi_search.py +129 -0
- octostar/utils/workspace/__init__.py +0 -0
- octostar/utils/workspace/delete_entities.py +247 -0
- octostar/utils/workspace/delete_entity.py +81 -0
- octostar/utils/workspace/delete_relationship.py +78 -0
- octostar/utils/workspace/delete_relationships.py +85 -0
- octostar/utils/workspace/delete_temporary_blob.py +85 -0
- octostar/utils/workspace/extract_entities.py +140 -0
- octostar/utils/workspace/get_filepath_from_item.py +85 -0
- octostar/utils/workspace/get_filepaths_from_items.py +100 -0
- octostar/utils/workspace/get_files_tree.py +102 -0
- octostar/utils/workspace/get_item_from_filepath.py +102 -0
- octostar/utils/workspace/get_items_from_filepaths.py +108 -0
- octostar/utils/workspace/linkcharts/__init__.py +0 -0
- octostar/utils/workspace/linkcharts/create_linkchart.py +241 -0
- octostar/utils/workspace/permissions/PermissionLevel.py +8 -0
- octostar/utils/workspace/permissions/__init__.py +1 -0
- octostar/utils/workspace/permissions/get_permissions.py +81 -0
- octostar/utils/workspace/read_attachment.py +284 -0
- octostar/utils/workspace/read_file.py +113 -0
- octostar/utils/workspace/read_temporary_blob.py +428 -0
- octostar/utils/workspace/saved_searches/__init__.py +0 -0
- octostar/utils/workspace/saved_searches/create_saved_search.py +183 -0
- octostar/utils/workspace/tags/__init__.py +0 -0
- octostar/utils/workspace/tags/delete_tag_from_entities.py +96 -0
- octostar/utils/workspace/tags/tag_entities.py +175 -0
- octostar/utils/workspace/upsert_entities.py +268 -0
- octostar/utils/workspace/upsert_entity.py +110 -0
- octostar/utils/workspace/upsert_relationship.py +128 -0
- octostar/utils/workspace/upsert_relationships.py +194 -0
- octostar/utils/workspace/write_attachment.py +263 -0
- octostar/utils/workspace/write_file.py +335 -0
- octostar/utils/workspace/write_temporary_blob.py +218 -0
- octostar_python_client-0.1.759.dist-info/METADATA +159 -0
- octostar_python_client-0.1.759.dist-info/RECORD +257 -0
- octostar_python_client-0.1.759.dist-info/WHEEL +5 -0
- octostar_python_client-0.1.759.dist-info/licenses/LICENSE +21 -0
- octostar_python_client-0.1.759.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
from typing import List, Optional, Any, Union, TypedDict
|
|
2
|
+
import logging
|
|
3
|
+
import uuid
|
|
4
|
+
|
|
5
|
+
_logger = logging.getLogger(__name__)
|
|
6
|
+
|
|
7
|
+
from .. import upsert_entity
|
|
8
|
+
from ...ontology import fetch_ontology_data
|
|
9
|
+
from ....client import Client
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SupersetFilter(TypedDict):
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class SimpleSupersetFilter(SupersetFilter):
|
|
17
|
+
"""
|
|
18
|
+
# Represents a primitive superset filter using a (col, op, val) tuple.
|
|
19
|
+
|
|
20
|
+
## Attributes:
|
|
21
|
+
- **col** (`str`): The timbr column involved in the filter as the first operand.
|
|
22
|
+
- **op** (`str`): The operator name, e.g. `"=="`, `"IN"`, `"LIKE"`.
|
|
23
|
+
- **val** (`Any`, `List[Any]`): The value (or values) involved in the filter as the second operand.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
col: str
|
|
27
|
+
op: str
|
|
28
|
+
val: Union[Any, List[Any]]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ComplexSupersetFilter(SupersetFilter):
|
|
32
|
+
"""
|
|
33
|
+
# Represents a nested superset filter combined via a logical boolean operator.
|
|
34
|
+
|
|
35
|
+
## Attributes:
|
|
36
|
+
- **operator** (`str`): The SQL logical operator to apply to all operands, e.g. `AND`, `OR`.
|
|
37
|
+
- **operands** (`List[SupersetFilter]`): A list of superset filters onto which the logical operator is applied.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
operator: str
|
|
41
|
+
operands: List[SupersetFilter]
|
|
42
|
+
operator: str
|
|
43
|
+
operands: List[SupersetFilter]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def sync(
|
|
47
|
+
os_workspace: str,
|
|
48
|
+
name: str,
|
|
49
|
+
entity_type: str,
|
|
50
|
+
filter: List[SupersetFilter],
|
|
51
|
+
path: str = None,
|
|
52
|
+
os_entity_uid: Optional[str] = None,
|
|
53
|
+
fields: dict = {},
|
|
54
|
+
client: Optional[Client] = None,
|
|
55
|
+
):
|
|
56
|
+
"""
|
|
57
|
+
# Create or update a local saved search in a workspace
|
|
58
|
+
|
|
59
|
+
## Arguments
|
|
60
|
+
- `os_workspace`: The workspace ID
|
|
61
|
+
- `name`: The name for the saved search
|
|
62
|
+
- `entity_type`: The entity type for which to apply the filter
|
|
63
|
+
- `filter`: The superset filter for the saved search
|
|
64
|
+
- `path`: The path to the saved search file in the workspace, excluding the saved search filename
|
|
65
|
+
- `os_entity_uid`: The unique identifier for the saved search
|
|
66
|
+
- `fields`: Additional fields to include in the entity record
|
|
67
|
+
- `client`: The Client with which to connect to Octostar. If None, the default one is used
|
|
68
|
+
|
|
69
|
+
## Returns
|
|
70
|
+
The created/updated entity record
|
|
71
|
+
|
|
72
|
+
## Raises
|
|
73
|
+
- `NotImplementedError`: If the operation is not supported for the ontology
|
|
74
|
+
- `ConnectionError`: If the operation was unsuccessful on the server
|
|
75
|
+
"""
|
|
76
|
+
icon = None
|
|
77
|
+
if not os_entity_uid:
|
|
78
|
+
os_entity_uid = str(uuid.uuid4())
|
|
79
|
+
try:
|
|
80
|
+
ontology = fetch_ontology_data.sync(client=client)
|
|
81
|
+
curr_concept = ontology["concepts"][entity_type]
|
|
82
|
+
while not icon:
|
|
83
|
+
icon = curr_concept["tags"].get("icon")
|
|
84
|
+
if not icon:
|
|
85
|
+
curr_concept = ontology["concepts"][curr_concept["parents"][0]]
|
|
86
|
+
except Exception:
|
|
87
|
+
logging.warning("Warning: Could not assign icon to saved search!")
|
|
88
|
+
return upsert_entity.sync(
|
|
89
|
+
os_workspace=os_workspace,
|
|
90
|
+
os_entity_type="os_wsfs_object",
|
|
91
|
+
os_entity_uid=os_entity_uid,
|
|
92
|
+
fields={
|
|
93
|
+
**fields,
|
|
94
|
+
"os_item_content_type": "os_saved_search",
|
|
95
|
+
"os_item_name": name,
|
|
96
|
+
"os_icon": icon,
|
|
97
|
+
"os_item_content": {
|
|
98
|
+
"concept": entity_type,
|
|
99
|
+
"crossFilters": [
|
|
100
|
+
{
|
|
101
|
+
"id": str(uuid.uuid4()),
|
|
102
|
+
"extraFormData": {
|
|
103
|
+
"filters": filter,
|
|
104
|
+
},
|
|
105
|
+
"filterState": {},
|
|
106
|
+
"ownState": {},
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"filters": [],
|
|
110
|
+
"datasourcesInScope": {},
|
|
111
|
+
},
|
|
112
|
+
"os_parent_folder": os_workspace,
|
|
113
|
+
"#os_path": path or "",
|
|
114
|
+
},
|
|
115
|
+
client=client,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
async def asyncio(
|
|
120
|
+
os_workspace: str,
|
|
121
|
+
name: str,
|
|
122
|
+
entity_type: str,
|
|
123
|
+
filter: List[SupersetFilter],
|
|
124
|
+
path: str = None,
|
|
125
|
+
os_entity_uid: Optional[str] = None,
|
|
126
|
+
fields: dict = {},
|
|
127
|
+
client: Optional[Client] = None,
|
|
128
|
+
):
|
|
129
|
+
"""
|
|
130
|
+
# Create or update asynchronously a local saved search in a workspace
|
|
131
|
+
|
|
132
|
+
## Arguments
|
|
133
|
+
(Same as sync function)
|
|
134
|
+
|
|
135
|
+
## Returns
|
|
136
|
+
The created/updated entity record
|
|
137
|
+
|
|
138
|
+
## Raises
|
|
139
|
+
- `NotImplementedError`: If the operation is not supported for the ontology
|
|
140
|
+
- `ConnectionError`: If the operation was unsuccessful on the server
|
|
141
|
+
"""
|
|
142
|
+
icon = None
|
|
143
|
+
if not os_entity_uid:
|
|
144
|
+
os_entity_uid = str(uuid.uuid4())
|
|
145
|
+
try:
|
|
146
|
+
ontology = fetch_ontology_data.sync(client=client)
|
|
147
|
+
curr_concept = ontology["concepts"][entity_type]
|
|
148
|
+
while not icon:
|
|
149
|
+
icon = curr_concept["tags"].get("icon")
|
|
150
|
+
if not icon:
|
|
151
|
+
curr_concept = ontology["concepts"][curr_concept["parents"][0]]
|
|
152
|
+
except Exception:
|
|
153
|
+
logging.warning("Warning: Could not assign icon to saved search!")
|
|
154
|
+
|
|
155
|
+
return upsert_entity.sync(
|
|
156
|
+
os_workspace=os_workspace,
|
|
157
|
+
os_entity_type="os_wsfs_object",
|
|
158
|
+
os_entity_uid=os_entity_uid,
|
|
159
|
+
fields={
|
|
160
|
+
**fields,
|
|
161
|
+
"os_item_content_type": "os_saved_search",
|
|
162
|
+
"os_item_name": name,
|
|
163
|
+
"os_icon": icon,
|
|
164
|
+
"os_item_content": {
|
|
165
|
+
"concept": entity_type,
|
|
166
|
+
"crossFilters": [
|
|
167
|
+
{
|
|
168
|
+
"id": str(uuid.uuid4()),
|
|
169
|
+
"extraFormData": {
|
|
170
|
+
"filters": filter,
|
|
171
|
+
},
|
|
172
|
+
"filterState": {},
|
|
173
|
+
"ownState": {},
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
"filters": [],
|
|
177
|
+
"datasourcesInScope": {},
|
|
178
|
+
},
|
|
179
|
+
"os_parent_folder": os_workspace,
|
|
180
|
+
"#os_path": path or "",
|
|
181
|
+
},
|
|
182
|
+
client=client,
|
|
183
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from typing import Dict, TypedDict, Union, List, Any, Optional
|
|
2
|
+
import os
|
|
3
|
+
import uuid
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
_logger = logging.getLogger(__name__)
|
|
7
|
+
|
|
8
|
+
from ....api.workspace_tags import delete_tag_from_entities
|
|
9
|
+
from ....models.entity import Entity as TagEntity
|
|
10
|
+
from ....client import Client, get_default_client
|
|
11
|
+
from ....types import UNSET
|
|
12
|
+
from ...exceptions import ApiConnectionError
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Entity(TypedDict):
|
|
16
|
+
os_entity_uid: str
|
|
17
|
+
entity_type: str
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def sync(
|
|
21
|
+
os_workspace: str,
|
|
22
|
+
entities: List[Entity],
|
|
23
|
+
tag_uid: str,
|
|
24
|
+
ontology_name: str = None,
|
|
25
|
+
client: Client = None,
|
|
26
|
+
):
|
|
27
|
+
"""
|
|
28
|
+
# Remove a tag from a list of entities
|
|
29
|
+
|
|
30
|
+
## Arguments
|
|
31
|
+
- `os_workspace`: The workspace ID of the tag
|
|
32
|
+
- `entities`: The entities to tag, as a list of dictionaries
|
|
33
|
+
Each dictionary must contain:
|
|
34
|
+
- `os_entity_uid`: The unique ID for the entity
|
|
35
|
+
- `entity_type`: The concept name for the entity
|
|
36
|
+
- `tag_uid`: The unique ID of the tag
|
|
37
|
+
- `ontology_name`: The name of the ontology
|
|
38
|
+
- `client`: The Client with which to connect to Octostar. If None, the default one is used
|
|
39
|
+
|
|
40
|
+
## Raises
|
|
41
|
+
- `NotImplementedError`: If the operation is not supported for the ontology
|
|
42
|
+
- `ApiConnectionError`: If the operation was unsuccessful on the server
|
|
43
|
+
"""
|
|
44
|
+
assert len(entities) > 0
|
|
45
|
+
if not ontology_name:
|
|
46
|
+
if not client:
|
|
47
|
+
client = get_default_client()
|
|
48
|
+
ontology_name = client.ontology
|
|
49
|
+
if ontology_name != client.ontology:
|
|
50
|
+
raise NotImplementedError(
|
|
51
|
+
"This operation is currently only supported on the current ontology!"
|
|
52
|
+
)
|
|
53
|
+
entities_to_untag = [
|
|
54
|
+
TagEntity(entity["os_entity_uid"], entity["entity_type"]) for entity in entities
|
|
55
|
+
]
|
|
56
|
+
response = delete_tag_from_entities.sync_detailed(
|
|
57
|
+
os_workspace, tag_uid, json_body=entities_to_untag, client=client
|
|
58
|
+
)
|
|
59
|
+
if response.status_code != 200:
|
|
60
|
+
raise ApiConnectionError("delete_tag_from_entities", response, client)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
async def asyncio(
|
|
64
|
+
os_workspace: str,
|
|
65
|
+
entities: List[Entity],
|
|
66
|
+
tag_uid: str,
|
|
67
|
+
ontology_name: str = None,
|
|
68
|
+
client: Client = None,
|
|
69
|
+
):
|
|
70
|
+
"""
|
|
71
|
+
# Remove asynchronously a tag from a list of entities
|
|
72
|
+
|
|
73
|
+
## Arguments
|
|
74
|
+
(Same as sync function)
|
|
75
|
+
|
|
76
|
+
## Raises
|
|
77
|
+
- `NotImplementedError`: If the operation is not supported for the ontology
|
|
78
|
+
- `ApiConnectionError`: If the operation was unsuccessful on the server
|
|
79
|
+
"""
|
|
80
|
+
assert len(entities) > 0
|
|
81
|
+
if not ontology_name:
|
|
82
|
+
if not client:
|
|
83
|
+
client = get_default_client()
|
|
84
|
+
ontology_name = client.ontology
|
|
85
|
+
if ontology_name != client.ontology:
|
|
86
|
+
raise NotImplementedError(
|
|
87
|
+
"This operation is currently only supported on the current ontology!"
|
|
88
|
+
)
|
|
89
|
+
entities_to_untag = [
|
|
90
|
+
TagEntity(entity["os_entity_uid"], entity["entity_type"]) for entity in entities
|
|
91
|
+
]
|
|
92
|
+
response = await delete_tag_from_entities.asyncio_detailed(
|
|
93
|
+
os_workspace, tag_uid, json_body=entities_to_untag, client=client
|
|
94
|
+
)
|
|
95
|
+
if response.status_code != 200:
|
|
96
|
+
raise ApiConnectionError("delete_tag_from_entities", response, client)
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
from typing import TypedDict, List, Optional
|
|
2
|
+
|
|
3
|
+
from ...ontology import query_ontology
|
|
4
|
+
from ....api.workspace_tags import tag_entities
|
|
5
|
+
from ....models.entity import Entity as TagEntity
|
|
6
|
+
from ....client import Client, get_default_client
|
|
7
|
+
from ....types import UNSET
|
|
8
|
+
from ...exceptions import ApiConnectionError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Entity(TypedDict):
|
|
12
|
+
os_entity_uid: str
|
|
13
|
+
entity_type: str
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def sync(
|
|
17
|
+
os_workspace: str,
|
|
18
|
+
entities: List[Entity],
|
|
19
|
+
existing_tag_uid: Optional[str] = None,
|
|
20
|
+
tag_name: Optional[str] = None,
|
|
21
|
+
new_tag_color: Optional[str] = None,
|
|
22
|
+
tag_group: Optional[str] = None,
|
|
23
|
+
new_tag_order: Optional[int] = -1,
|
|
24
|
+
ontology_name: str = None,
|
|
25
|
+
client: Client = None,
|
|
26
|
+
):
|
|
27
|
+
"""
|
|
28
|
+
# Tag a list of entities with a tag
|
|
29
|
+
|
|
30
|
+
The tag can be a new tag or an existing one.
|
|
31
|
+
|
|
32
|
+
## Arguments
|
|
33
|
+
- `os_workspace`: The workspace ID in which to write the tag relationships (and the tag itself, if a new one is created)
|
|
34
|
+
- `entities`: The entities to tag, as a list of dictionaries
|
|
35
|
+
Each dictionary must contain:
|
|
36
|
+
- `os_entity_uid`: The unique ID for the entity
|
|
37
|
+
- `entity_type`: The concept name for the entity
|
|
38
|
+
- `existing_tag_uid`: The unique ID of the tag, if an existing tag is used
|
|
39
|
+
- `tag_name`: A label for the tag. If no tag with this name and group pair exists, it is created
|
|
40
|
+
- `new_tag_color`: A color (in hex "#ffffff" format) for the tag, if a new tag is used
|
|
41
|
+
- `tag_group`: A label used to group the tag with other tags. If no tag with this name and group pair exists, it is created
|
|
42
|
+
- `new_tag_order`: The order of the tag within its group, if a new tag is used
|
|
43
|
+
- `ontology_name`: The name of the ontology
|
|
44
|
+
- `client`: The Client with which to connect to Octostar. If None, the default one is used
|
|
45
|
+
|
|
46
|
+
## Returns
|
|
47
|
+
The tag record
|
|
48
|
+
|
|
49
|
+
## Raises
|
|
50
|
+
- `NotImplementedError`: If the operation is not supported for the ontology
|
|
51
|
+
- `ApiConnectionError`: If the operation was unsuccessful on the server
|
|
52
|
+
- `ConnectionError`: If the tag returned from the response is ambiguous
|
|
53
|
+
"""
|
|
54
|
+
assert len(entities) > 0
|
|
55
|
+
assert bool(existing_tag_uid) ^ bool(tag_name) # xor
|
|
56
|
+
if not ontology_name:
|
|
57
|
+
if not client:
|
|
58
|
+
client = get_default_client()
|
|
59
|
+
ontology_name = client.ontology
|
|
60
|
+
if ontology_name != client.ontology:
|
|
61
|
+
raise NotImplementedError(
|
|
62
|
+
"This operation is currently only supported on the current ontology!"
|
|
63
|
+
)
|
|
64
|
+
entities_to_tag = [
|
|
65
|
+
TagEntity(entity["os_entity_uid"], entity["entity_type"]) for entity in entities
|
|
66
|
+
]
|
|
67
|
+
response = tag_entities.sync_detailed(
|
|
68
|
+
os_workspace,
|
|
69
|
+
tag=existing_tag_uid or tag_name,
|
|
70
|
+
json_body=entities_to_tag,
|
|
71
|
+
color=new_tag_color or UNSET,
|
|
72
|
+
group=tag_group or UNSET,
|
|
73
|
+
order=new_tag_order or UNSET,
|
|
74
|
+
client=client,
|
|
75
|
+
)
|
|
76
|
+
if response.status_code != 200 or (
|
|
77
|
+
response.parsed and response.parsed.get("status") != "success"
|
|
78
|
+
):
|
|
79
|
+
raise ApiConnectionError("tag_entities", response, client)
|
|
80
|
+
assigned_tag = list(
|
|
81
|
+
{entity["os_entity_uid_to"] for entity in (response.parsed.get("data") or [])}
|
|
82
|
+
)
|
|
83
|
+
if not len(assigned_tag) == 1:
|
|
84
|
+
raise ConnectionError(
|
|
85
|
+
f"tag_entities failed, tag upsertion ambiguous or failed! Returned the following tags: "
|
|
86
|
+
+ str(assigned_tag)
|
|
87
|
+
)
|
|
88
|
+
assigned_tag = assigned_tag[0]
|
|
89
|
+
full_assigned_tag = query_ontology.sync(
|
|
90
|
+
f"SELECT * FROM dtimbr.os_tag WHERE entity_id='{assigned_tag}'",
|
|
91
|
+
ontology_name=ontology_name,
|
|
92
|
+
client=client,
|
|
93
|
+
)
|
|
94
|
+
return full_assigned_tag[0]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
async def asyncio(
|
|
98
|
+
os_workspace: str,
|
|
99
|
+
entities: List[Entity],
|
|
100
|
+
existing_tag_uid: Optional[str] = None,
|
|
101
|
+
tag_name: Optional[str] = None,
|
|
102
|
+
new_tag_color: Optional[str] = None,
|
|
103
|
+
tag_group: Optional[str] = None,
|
|
104
|
+
new_tag_order: Optional[int] = -1,
|
|
105
|
+
ontology_name: str = None,
|
|
106
|
+
client: Client = None,
|
|
107
|
+
):
|
|
108
|
+
"""
|
|
109
|
+
# Tag asynchronously a list of entities with a tag
|
|
110
|
+
|
|
111
|
+
The tag can be a new tag or an existing one.
|
|
112
|
+
|
|
113
|
+
## Arguments
|
|
114
|
+
- `os_workspace`: The workspace ID in which to write the tag relationships (and the tag itself, if a new one is created)
|
|
115
|
+
- `entities`: The entities to tag, as a list of dictionaries
|
|
116
|
+
Each dictionary must contain:
|
|
117
|
+
- `os_entity_uid`: The unique ID for the entity
|
|
118
|
+
- `entity_type`: The concept name for the entity
|
|
119
|
+
- `existing_tag_uid`: The unique ID of the tag, if an existing tag is used
|
|
120
|
+
- `tag_name`: A label for the tag. If no tag with this name and group pair exists, it is created
|
|
121
|
+
- `new_tag_color`: A color (in hex "#ffffff" format) for the tag, if a new tag is used
|
|
122
|
+
- `tag_group`: A label used to group the tag with other tags. If no tag with this name and group pair exists, it is created
|
|
123
|
+
- `new_tag_order`: The order of the tag within its group, if a new tag is used
|
|
124
|
+
- `ontology_name`: The name of the ontology
|
|
125
|
+
- `client`: The Client with which to connect to Octostar. If None, the default one is used
|
|
126
|
+
|
|
127
|
+
## Returns
|
|
128
|
+
The tag record
|
|
129
|
+
|
|
130
|
+
## Raises
|
|
131
|
+
- `NotImplementedError`: If the operation is not supported for the ontology
|
|
132
|
+
- `ApiConnectionError`: If the operation was unsuccessful on the server
|
|
133
|
+
- `ConnectionError`: If the tag returned from the response is ambiguous
|
|
134
|
+
"""
|
|
135
|
+
assert len(entities) > 0
|
|
136
|
+
assert bool(existing_tag_uid) ^ bool(tag_name) # xor
|
|
137
|
+
if not ontology_name:
|
|
138
|
+
if not client:
|
|
139
|
+
client = get_default_client()
|
|
140
|
+
ontology_name = client.ontology
|
|
141
|
+
if ontology_name != client.ontology:
|
|
142
|
+
raise NotImplementedError(
|
|
143
|
+
"This operation is currently only supported on the current ontology!"
|
|
144
|
+
)
|
|
145
|
+
entities_to_tag = [
|
|
146
|
+
TagEntity(entity["os_entity_uid"], entity["entity_type"]) for entity in entities
|
|
147
|
+
]
|
|
148
|
+
response = await tag_entities.asyncio_detailed(
|
|
149
|
+
os_workspace,
|
|
150
|
+
tag=existing_tag_uid or tag_name,
|
|
151
|
+
json_body=entities_to_tag,
|
|
152
|
+
color=new_tag_color or UNSET,
|
|
153
|
+
group=tag_group or UNSET,
|
|
154
|
+
order=new_tag_order or UNSET,
|
|
155
|
+
client=client,
|
|
156
|
+
)
|
|
157
|
+
if response.status_code != 200 or (
|
|
158
|
+
response.parsed and response.parsed.get("status") != "success"
|
|
159
|
+
):
|
|
160
|
+
raise ApiConnectionError("tag_entities", response, client)
|
|
161
|
+
assigned_tag = list(
|
|
162
|
+
{entity["os_entity_uid_to"] for entity in (response.parsed.get("data") or [])}
|
|
163
|
+
)
|
|
164
|
+
if not len(assigned_tag) == 1:
|
|
165
|
+
raise ConnectionError(
|
|
166
|
+
f"tag_entities failed, tag upsertion ambiguous or failed! Returned the following tags: "
|
|
167
|
+
+ str(assigned_tag)
|
|
168
|
+
)
|
|
169
|
+
assigned_tag = assigned_tag[0]
|
|
170
|
+
full_assigned_tag = await query_ontology.asyncio(
|
|
171
|
+
f"SELECT * FROM dtimbr.os_tag WHERE entity_id='{assigned_tag}'",
|
|
172
|
+
ontology_name=ontology_name,
|
|
173
|
+
client=client,
|
|
174
|
+
)
|
|
175
|
+
return full_assigned_tag[0]
|