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

Commit 680e656

Browse files
author
Samuel Hassine
committed
[client] Take into account tag id in import
1 parent bfd467c commit 680e656

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pycti/entities/opencti_tag.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def create_raw(self, **kwargs):
120120
tag_type = kwargs.get("tag_type", None)
121121
value = kwargs.get("value", None)
122122
color = kwargs.get("color", None)
123+
id = kwargs.get("id", None)
123124

124125
if tag_type is not None and value is not None and color is not None:
125126
query = (
@@ -134,7 +135,15 @@ def create_raw(self, **kwargs):
134135
"""
135136
)
136137
result = self.opencti.query(
137-
query, {"input": {"tag_type": tag_type, "value": value, "color": color}}
138+
query,
139+
{
140+
"input": {
141+
"tag_type": tag_type,
142+
"value": value,
143+
"color": color,
144+
"internal_id_key": id,
145+
}
146+
},
138147
)
139148
return self.opencti.process_multiple_fields(result["data"]["tagAdd"])
140149
else:
@@ -156,9 +165,10 @@ def create(self, **kwargs):
156165
tag_type = kwargs.get("tag_type", None)
157166
value = kwargs.get("value", None)
158167
color = kwargs.get("color", None)
168+
id = kwargs.get("id", None)
159169

160170
object_result = self.read(filters=[{"key": "value", "values": [value]}])
161171
if object_result is not None:
162172
return object_result
163173
else:
164-
return self.create_raw(tag_type=tag_type, value=value, color=color,)
174+
return self.create_raw(tag_type=tag_type, value=value, color=color, id=id)

pycti/utils/opencti_stix2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def extract_embedded_relationships(self, stix_object, types=None):
180180
tag_type=tag["tag_type"],
181181
value=tag["value"],
182182
color=tag["color"],
183+
id=tag["id"] if "id" in tag else None,
183184
)
184185
if tag_result is not None:
185186
tags_ids.append(tag_result["id"])

0 commit comments

Comments
 (0)