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

Commit c1c0c5d

Browse files
author
Samuel Hassine
committed
[client] Fix some bugs and take into account the update of existing data
1 parent b9045e4 commit c1c0c5d

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

pycti/api/opencti_api_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ def create_marking_definition_if_not_exists(self,
580580
):
581581
object_result = None
582582
if stix_id_key is not None:
583-
object_result = self.marking_definition.read(filters=[{'key': 'stix_id_key', 'values': [stix_id_key]}])
583+
object_result = self.marking_definition.read(id=stix_id_key)
584584
if object_result is None:
585585
object_result = self.marking_definition.read(filters=[
586586
{'key': 'definition_type', 'values': [definition_type]},
@@ -1977,7 +1977,7 @@ def get_reports(self, limit=10000):
19771977

19781978
@deprecated(version='2.1.0', reason="Replaced by the Report class in pycti")
19791979
def get_reports_by_stix_entity_stix_id(self, stix_entity_stix_id, limit=10000):
1980-
stix_entity_result = self.stix_entity.read(filters=[{'key': 'stix_id_key', 'values': [stix_entity_stix_id]}])
1980+
stix_entity_result = self.stix_entity.read(id=stix_entity_stix_id)
19811981
if stix_entity_result is not None:
19821982
return self.report.list(filters=[
19831983
{'key': 'knowledgeContains', 'values': [stix_entity_result['id']]},

pycti/connector/opencti_connector_helper.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def date_now(self):
166166
return datetime.datetime.utcnow().replace(microsecond=0, tzinfo=datetime.timezone.utc).isoformat()
167167

168168
# Push Stix2 helper
169-
def send_stix2_bundle(self, bundle, entities_types=None):
169+
def send_stix2_bundle(self, bundle, entities_types=None, update=False, confidence_level=1):
170170
if entities_types is None:
171171
entities_types = []
172172
bundles = self.split_stix2_bundle(bundle)
@@ -175,11 +175,11 @@ def send_stix2_bundle(self, bundle, entities_types=None):
175175
pika_connection = pika.BlockingConnection(pika.URLParameters(self.config['uri']))
176176
channel = pika_connection.channel()
177177
for bundle in bundles:
178-
self._send_bundle(channel, bundle, entities_types)
178+
self._send_bundle(channel, bundle, entities_types, update, confidence_level)
179179
channel.close()
180180
return bundles
181181

182-
def _send_bundle(self, channel, bundle, entities_types=None):
182+
def _send_bundle(self, channel, bundle, entities_types=None, update=False, confidence_level=1):
183183
"""
184184
This method send a STIX2 bundle to RabbitMQ to be consumed by workers
185185
:param bundle: A valid STIX2 bundle
@@ -205,6 +205,8 @@ def _send_bundle(self, channel, bundle, entities_types=None):
205205
message = {
206206
'job_id': job_id,
207207
'entities_types': entities_types,
208+
'update': update,
209+
'confidence_level': confidence_level,
208210
'content': base64.b64encode(bundle.encode('utf-8')).decode('utf-8')
209211
}
210212

pycti/entities/opencti_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def get_by_stix_id_or_name(self, **kwargs):
213213
published = kwargs.get('published', None)
214214
object_result = None
215215
if stix_id_key is not None:
216-
object_result = self.read(filters=[{'key': 'stix_id_key', 'values': [stix_id_key]}])
216+
object_result = self.read(id=stix_id_key)
217217
if object_result is None and name is not None and published is not None:
218218
published_final = parse(published).strftime('%Y-%m-%d')
219219
object_result = self.read(filters=[

pycti/utils/opencti_stix2.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,15 +1276,13 @@ def create_indicator(self, stix_object, update=False):
12761276

12771277
# check that the indicator type and value have been set before creating the indicator
12781278
if indicator_type and indicator_value:
1279-
return self.opencti.create_stix_observable_if_not_exists(
1280-
indicator_type,
1281-
indicator_value,
1282-
self.convert_markdown(stix_object['description']) if 'description' in stix_object else '',
1283-
stix_object[CustomProperties.ID] if CustomProperties.ID in stix_object else None,
1284-
stix_object['id'] if 'id' in stix_object else None,
1285-
stix_object['created'] if 'created' in stix_object else None,
1286-
stix_object['modified'] if 'modified' in stix_object else None,
1287-
update
1279+
return self.opencti.stix_observable.create(
1280+
type=indicator_type,
1281+
observable_value=indicator_value,
1282+
description=self.convert_markdown(stix_object['description']) if 'description' in stix_object else '',
1283+
id=stix_object[CustomProperties.ID] if CustomProperties.ID in stix_object else None,
1284+
stix_id_key=stix_object['id'] if 'id' in stix_object else None,
1285+
update=update
12881286
)
12891287
else:
12901288
# log that the indicator could not be parsed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
print("warning: pypandoc module not found, could not convert Markdown to RST")
1414
read_md = lambda f: open(f, 'r').read()
1515

16-
VERSION = "2.1.1"
16+
VERSION = "2.1.2"
1717

1818

1919
class VerifyVersionCommand(install):

0 commit comments

Comments
 (0)