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

Commit c7f4c65

Browse files
[client] Improve id generation for STIX elements (#789)
Co-authored-by: Helene Nguyen <[email protected]>
1 parent 0a842a9 commit c7f4c65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+548
-81
lines changed

pycti/entities/opencti_attack_pattern.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,19 @@ def __init__(self, opencti):
222222

223223
@staticmethod
224224
def generate_id(name, x_mitre_id=None):
225-
name = name.lower().strip()
226225
if x_mitre_id is not None:
227226
data = {"x_mitre_id": x_mitre_id}
228227
else:
229-
data = {"name": name}
228+
data = {"name": name.lower().strip()}
230229
data = canonicalize(data, utf8=False)
231230
id = str(uuid.uuid5(uuid.UUID("00abedb4-aa42-466c-9c01-fed23315a9b7"), data))
232231
return "attack-pattern--" + id
233232

233+
@staticmethod
234+
def generate_id_from_data(data):
235+
external_id = data.get("x_mitre_id") or data.get("x_opencti_external_id")
236+
return AttackPattern.generate_id(data.get("name"), external_id)
237+
234238
"""
235239
List Attack-Pattern objects
236240

pycti/entities/opencti_campaign.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ def generate_id(name):
216216
id = str(uuid.uuid5(uuid.UUID("00abedb4-aa42-466c-9c01-fed23315a9b7"), data))
217217
return "campaign--" + id
218218

219+
@staticmethod
220+
def generate_id_from_data(data):
221+
return Campaign.generate_id(data["name"])
222+
219223
"""
220224
List Campaign objects
221225

pycti/entities/opencti_case_incident.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ def generate_id(name, created):
461461
id = str(uuid.uuid5(uuid.UUID("00abedb4-aa42-466c-9c01-fed23315a9b7"), data))
462462
return "case-incident--" + id
463463

464+
@staticmethod
465+
def generate_id_from_data(data):
466+
return CaseIncident.generate_id(data["name"], data["created"])
467+
464468
"""
465469
List Case Incident objects
466470

pycti/entities/opencti_case_rfi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ def generate_id(name, created):
457457
id = str(uuid.uuid5(uuid.UUID("00abedb4-aa42-466c-9c01-fed23315a9b7"), data))
458458
return "case-rfi--" + id
459459

460+
@staticmethod
461+
def generate_id_from_data(data):
462+
return CaseRfi.generate_id(data["name"], data["created"])
463+
460464
"""
461465
List Case Rfi objects
462466

pycti/entities/opencti_case_rft.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ def generate_id(name, created):
457457
id = str(uuid.uuid5(uuid.UUID("00abedb4-aa42-466c-9c01-fed23315a9b7"), data))
458458
return "case-rft--" + id
459459

460+
@staticmethod
461+
def generate_id_from_data(data):
462+
return CaseRft.generate_id(data["name"], data["created"])
463+
460464
"""
461465
List Case Rft objects
462466

pycti/entities/opencti_channel.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ def generate_id(name):
212212
id = str(uuid.uuid5(uuid.UUID("00abedb4-aa42-466c-9c01-fed23315a9b7"), data))
213213
return "channel--" + id
214214

215+
@staticmethod
216+
def generate_id_from_data(data):
217+
return Channel.generate_id(data["name"])
218+
215219
"""
216220
List Channel objects
217221

pycti/entities/opencti_course_of_action.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,18 @@ def __init__(self, opencti):
196196

197197
@staticmethod
198198
def generate_id(name, x_mitre_id=None):
199-
name = name.lower().strip()
200199
if x_mitre_id is not None:
201200
data = {"x_mitre_id": x_mitre_id}
202201
else:
203-
data = {"name": name}
202+
data = {"name": name.lower().strip()}
204203
data = canonicalize(data, utf8=False)
205204
id = str(uuid.uuid5(uuid.UUID("00abedb4-aa42-466c-9c01-fed23315a9b7"), data))
206205
return "course-of-action--" + id
207206

207+
@staticmethod
208+
def generate_id_from_data(data):
209+
return CourseOfAction.generate_id(data.get("name"), data.get("x_mitre_id"))
210+
208211
"""
209212
List Course-Of-Action objects
210213

pycti/entities/opencti_data_component.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ def generate_id(name):
246246
id = str(uuid.uuid5(uuid.UUID("00abedb4-aa42-466c-9c01-fed23315a9b7"), data))
247247
return "data-component--" + id
248248

249+
@staticmethod
250+
def generate_id_from_data(data):
251+
return DataComponent.generate_id(data["name"])
252+
249253
"""
250254
List Data-Component objects
251255

pycti/entities/opencti_data_source.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ def generate_id(name):
204204
id = str(uuid.uuid5(uuid.UUID("00abedb4-aa42-466c-9c01-fed23315a9b7"), data))
205205
return "data-source--" + id
206206

207+
@staticmethod
208+
def generate_id_from_data(data):
209+
return DataSource.generate_id(data["name"])
210+
207211
"""
208212
List Data-Source objects
209213

pycti/entities/opencti_event.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ def generate_id(name):
216216
id = str(uuid.uuid5(uuid.UUID("00abedb4-aa42-466c-9c01-fed23315a9b7"), data))
217217
return "event--" + id
218218

219+
@staticmethod
220+
def generate_id_from_data(data):
221+
return Event.generate_id(data["name"])
222+
219223
"""
220224
List Event objects
221225

0 commit comments

Comments
 (0)