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

Commit 10feec6

Browse files
[client] Add keep_original_id option
1 parent 465fb4a commit 10feec6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pycti/utils/opencti_stix2.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ def pick_aliases(self, stix_object: Dict) -> Optional[List]:
176176
return None
177177

178178
def import_bundle_from_file(
179-
self, file_path: str, update: bool = False, types: List = None
179+
self,
180+
file_path: str,
181+
update: bool = False,
182+
types: List = None,
183+
keep_original_id: bool = False,
180184
) -> Optional[List]:
181185
"""import a stix2 bundle from a file
182186
@@ -186,6 +190,8 @@ def import_bundle_from_file(
186190
:type update: bool, optional
187191
:param types: list of stix2 types, defaults to None
188192
:type types: list, optional
193+
:param keep_original_id: import need to keep original id
194+
:type keep_original_id: bool, optional
189195
:return: list of imported stix2 objects
190196
:rtype: List
191197
"""
@@ -194,7 +200,7 @@ def import_bundle_from_file(
194200
return None
195201
with open(os.path.join(file_path), encoding="utf-8") as file:
196202
data = json.load(file)
197-
return self.import_bundle(data, update, types)
203+
return self.import_bundle(data, update, types, None, keep_original_id)
198204

199205
def import_bundle_from_json(
200206
self,
@@ -2670,6 +2676,7 @@ def import_bundle(
26702676
update: bool = False,
26712677
types: List = None,
26722678
work_id: str = None,
2679+
keep_original_id: bool = False,
26732680
) -> List:
26742681
# Check if the bundle is correctly formatted
26752682
if "type" not in stix_bundle or stix_bundle["type"] != "bundle":
@@ -2684,7 +2691,7 @@ def import_bundle(
26842691

26852692
# Bundle ids must be rewritten
26862693
stix_bundle = self.prepare_bundle_ids(
2687-
bundle=stix_bundle, use_json=False, keep_original_id=False
2694+
bundle=stix_bundle, use_json=False, keep_original_id=keep_original_id
26882695
)
26892696

26902697
stix2_splitter = OpenCTIStix2Splitter()

0 commit comments

Comments
 (0)