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

Commit f518c50

Browse files
[client] As rewrite is not possible, remove this approach
1 parent 35b6ddc commit f518c50

File tree

4 files changed

+0
-216
lines changed

4 files changed

+0
-216
lines changed

pycti/connector/opencti_connector_helper.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,11 +1589,6 @@ def send_stix2_bundle(self, bundle: str, **kwargs) -> list:
15891589
"send_to_directory_retention", self.bundle_send_to_directory_retention
15901590
)
15911591

1592-
# Bundle ids must be rewritten
1593-
bundle = self.api.stix2.prepare_bundle_ids(
1594-
bundle=bundle, use_json=True, keep_original_id=keep_original_id
1595-
)
1596-
15971592
# In case of enrichment ingestion, ensure the sharing if needed
15981593
if self.enrichment_shared_organizations is not None:
15991594
# Every element of the bundle must be enriched with the same organizations

pycti/utils/opencti_stix2.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,62 +2402,6 @@ def export_selected(
24022402

24032403
return bundle
24042404

2405-
def prepare_bundle_ids(self, bundle, use_json=True, keep_original_id=False):
2406-
if use_json:
2407-
try:
2408-
bundle_data = json.loads(bundle)
2409-
except:
2410-
raise Exception("File data is not a valid JSON")
2411-
else:
2412-
bundle_data = bundle
2413-
cache_ids = {}
2414-
# First iteration to cache all entity ids
2415-
stix_helpers = self.get_stix_helper()
2416-
for item in bundle_data["objects"]:
2417-
helper = stix_helpers.get(item["type"])
2418-
if hasattr(helper, "generate_id_from_data"):
2419-
standard_id = helper.generate_id_from_data(item)
2420-
if item["id"] != standard_id:
2421-
cache_ids[item["id"]] = standard_id
2422-
2423-
# If no id to rewrite, return the processed bundle
2424-
if not bool(cache_ids):
2425-
# As rewrite can have multiple roundtrip
2426-
# we kept the first original id in a meta attribute
2427-
# final behavior is to rewrite this in the x_opencti_stix_ids
2428-
for item in bundle_data["objects"]:
2429-
if "x_keep_original_id" in item:
2430-
item["x_opencti_stix_ids"] = item.get("x_opencti_stix_ids", []) + [
2431-
item["x_keep_original_id"]
2432-
]
2433-
del item["x_keep_original_id"]
2434-
return json.dumps(bundle_data) if use_json else bundle_data
2435-
2436-
# Second iteration to replace and remap
2437-
for item in bundle_data["objects"]:
2438-
# For entities, try to replace the main id
2439-
# Keep the current one if needed
2440-
if cache_ids.get(item["id"]):
2441-
original_id = item["id"]
2442-
item["id"] = cache_ids[original_id]
2443-
if keep_original_id and "x_keep_original_id" not in item:
2444-
item["x_keep_original_id"] = original_id
2445-
# For all elements, replace all refs (source_ref, object_refs, ...)
2446-
ref_keys = list(
2447-
filter(lambda i: i.endswith("_ref") or i.endswith("_refs"), item.keys())
2448-
)
2449-
for ref_key in ref_keys:
2450-
if ref_key.endswith("_refs"):
2451-
item[ref_key] = list(
2452-
map(lambda id_ref: cache_ids.get(id_ref, id_ref), item[ref_key])
2453-
)
2454-
else:
2455-
item[ref_key] = cache_ids.get(item[ref_key], item[ref_key])
2456-
2457-
return self.prepare_bundle_ids(
2458-
bundle_data, False, keep_original_id=keep_original_id
2459-
)
2460-
24612405
def import_item(
24622406
self,
24632407
item,
@@ -2709,11 +2653,6 @@ def import_bundle(
27092653
else None
27102654
)
27112655

2712-
# Bundle ids must be rewritten
2713-
stix_bundle = self.prepare_bundle_ids(
2714-
bundle=stix_bundle, use_json=False, keep_original_id=keep_original_id
2715-
)
2716-
27172656
stix2_splitter = OpenCTIStix2Splitter()
27182657
_, bundles = stix2_splitter.split_bundle_with_expectations(
27192658
stix_bundle, False, event_version

tests/01-unit/stix/__init__.py

Whitespace-only changes.

tests/01-unit/stix/test_bundle_ids_rewrite.py

Lines changed: 0 additions & 150 deletions
This file was deleted.

0 commit comments

Comments
 (0)