Skip to content

Commit

Permalink
[client] Add more caching in sightings
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelHassine committed Sep 10, 2024
1 parent bf9aeb9 commit e0c3a8e
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions pycti/utils/opencti_stix2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,9 +1315,45 @@ def import_sighting(

# Create the sighting

final_from_id = from_id
final_to_id = to_id
### Get the FROM
if from_id in self.mapping_cache:
final_from_id = self.mapping_cache[from_id]["id"]
else:
stix_object_result = (
self.opencti.opencti_stix_object_or_stix_relationship.read(id=from_id)
)
if stix_object_result is not None:
final_from_id = stix_object_result["id"]
self.mapping_cache[from_id] = {
"id": stix_object_result["id"],
"entity_type": stix_object_result["entity_type"],
}
else:
self.opencti.app_logger.error(
"From ref of the sighting not found, doing nothing..."
)
return None

### Get the TO
final_to_id = None
if to_id:
if to_id in self.mapping_cache:
final_to_id = self.mapping_cache[to_id]["id"]
else:
stix_object_result = (
self.opencti.opencti_stix_object_or_stix_relationship.read(id=to_id)
)
if stix_object_result is not None:
final_to_id = stix_object_result["id"]
self.mapping_cache[to_id] = {
"id": stix_object_result["id"],
"entity_type": stix_object_result["entity_type"],
}
else:
self.opencti.app_logger.error(
"To ref of the sighting not found, doing nothing..."
)
return None
if (
"x_opencti_negative" not in stix_sighting
and self.opencti.get_attribute_in_extension("negative", stix_sighting)
Expand Down

0 comments on commit e0c3a8e

Please sign in to comment.