Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 13861b4

Browse files
committed
[client] Add helper for enrichment connectors
1 parent fcd9047 commit 13861b4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pycti/connector/opencti_connector_helper.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import base64
3+
import copy
34
import datetime
45
import json
56
import logging
@@ -1310,3 +1311,20 @@ def get_attribute_in_mitre_extension(key, object) -> any:
13101311
"extension-definition--322b8f77-262a-4cb8-a915-1e441e00329b"
13111312
][key]
13121313
return None
1314+
1315+
def get_data_from_enrichment(self, data, opencti_entity):
1316+
stix_id = data["entity_id"]
1317+
bundle = data.get("bundle", None)
1318+
# Extract IPv4, IPv6 and Domain from entity data
1319+
if bundle is None:
1320+
# Generate bundle
1321+
stix_objects = self.api.stix2.prepare_export(
1322+
self.api.stix2.generate_export(copy.copy(opencti_entity))
1323+
)
1324+
else:
1325+
stix_objects = bundle["objects"]
1326+
stix_entity = [e for e in stix_objects if e["id"] == stix_id][0]
1327+
return {
1328+
"stix_entity": stix_entity,
1329+
"stix_objects": stix_objects,
1330+
}

pycti/utils/opencti_stix2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,10 @@ def import_bundle(
24122412
def put_attribute_in_extension(
24132413
object, extension_id, key, value, multiple=False
24142414
) -> any:
2415+
if ("x_opencti_" + key) in object:
2416+
del object["x_opencti_" + key]
2417+
if ("x_mitre_" + key) in object:
2418+
del object["x_mitre_" + key]
24152419
if "extensions" not in object:
24162420
object["extensions"] = {}
24172421
if extension_id not in object["extensions"]:

0 commit comments

Comments
 (0)