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

Commit 0d4910d

Browse files
committed
[client] report error expection when element is ignored during import
1 parent cf01faa commit 0d4910d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

pycti/utils/opencti_stix2.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,16 +2748,24 @@ def import_bundle(
27482748
)
27492749

27502750
stix2_splitter = OpenCTIStix2Splitter()
2751-
_, nb_incompatible_elements, bundles = (
2751+
_, incompatible_elements, bundles = (
27522752
stix2_splitter.split_bundle_with_expectations(
27532753
stix_bundle, False, event_version
27542754
)
27552755
)
27562756

27572757
# Report every element ignored during bundle splitting
27582758
if work_id is not None:
2759-
for i in range(nb_incompatible_elements):
2760-
self.opencti.work.report_expectation(work_id, None)
2759+
for incompatible_element in incompatible_elements:
2760+
self.opencti.work.report_expectation(
2761+
work_id,
2762+
{
2763+
"error": "Incompatible element in bundle",
2764+
"source": "Element "
2765+
+ incompatible_element["id"]
2766+
+ " is incompatible and couldn't be processed",
2767+
},
2768+
)
27612769

27622770
# Import every element in a specific order
27632771
imported_elements = []

pycti/utils/opencti_stix2_splitter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self):
3535
self.cache_index = {}
3636
self.cache_refs = {}
3737
self.elements = []
38-
self.nb_incompatible_items = 0
38+
self.incompatible_items = []
3939

4040
def get_internal_ids_in_extension(self, item):
4141
ids = []
@@ -191,7 +191,7 @@ def enlist_element(
191191
if is_compatible:
192192
self.elements.append(item)
193193
else:
194-
self.nb_incompatible_items = self.nb_incompatible_items + 1
194+
self.incompatible_items.append(item)
195195
self.cache_index[item_id] = item
196196
for internal_id in self.get_internal_ids_in_extension(item):
197197
self.cache_index[internal_id] = item
@@ -204,7 +204,7 @@ def split_bundle_with_expectations(
204204
use_json=True,
205205
event_version=None,
206206
cleanup_inconsistent_bundle=False,
207-
) -> Tuple[int, int, list]:
207+
) -> Tuple[int, list, list]:
208208
"""splits a valid stix2 bundle into a list of bundles"""
209209
if use_json:
210210
try:
@@ -254,7 +254,7 @@ def by_dep_size(elem):
254254
)
255255
)
256256

257-
return number_expectations, self.nb_incompatible_items, bundles
257+
return number_expectations, self.incompatible_items, bundles
258258

259259
@deprecated("Use split_bundle_with_expectations instead")
260260
def split_bundle(self, bundle, use_json=True, event_version=None) -> list:

0 commit comments

Comments
 (0)