Skip to content

Commit 721191f

Browse files
author
Samuel Hassine
committed
[client] Fix report creation (no duplicates)
1 parent cd4325d commit 721191f

12 files changed

+23
-40
lines changed

examples/add_organization_to_sector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Variables
88
api_url = 'https://demo.opencti.io'
9-
api_token = '616e214c-8d86-4226-a653-c521f4ec90d9'
9+
api_token = '8f053d6e-cc8f-4ae3-ae24-107130510795'
1010

1111
# OpenCTI initialization
1212
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/create_incident_with_ttps_and_observables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# Variables
99
api_url = 'https://demo.opencti.io'
10-
api_token = '616e214c-8d86-4226-a653-c521f4ec90d9'
10+
api_token = '8f053d6e-cc8f-4ae3-ae24-107130510795'
1111

1212
# OpenCTI initialization
1313
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/create_intrusion_set.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Variables
77
api_url = 'https://demo.opencti.io'
8-
api_token = '616e214c-8d86-4226-a653-c521f4ec90d9'
8+
api_token = '8f053d6e-cc8f-4ae3-ae24-107130510795'
99

1010
# OpenCTI initialization
1111
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/export_intrusion_set_stix2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Variables
77
api_url = 'https://demo.opencti.io'
8-
api_token = '616e214c-8d86-4226-a653-c521f4ec90d9'
8+
api_token = '8f053d6e-cc8f-4ae3-ae24-107130510795'
99

1010
# OpenCTI initialization
1111
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/export_report_stix2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Variables
77
api_url = 'https://demo.opencti.io'
8-
api_token = '616e214c-8d86-4226-a653-c521f4ec90d9'
8+
api_token = '8f053d6e-cc8f-4ae3-ae24-107130510795'
99

1010
# OpenCTI initialization
1111
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/get_attack_pattern_by_mitre_id.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Variables
66
api_url = 'https://demo.opencti.io'
7-
api_token = '616e214c-8d86-4226-a653-c521f4ec90d9'
7+
api_token = '8f053d6e-cc8f-4ae3-ae24-107130510795'
88

99
# OpenCTI initialization
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/get_malwares_of_intrusion_set.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Variables
66
api_url = 'https://demo.opencti.io'
7-
api_token = '616e214c-8d86-4226-a653-c521f4ec90d9'
7+
api_token = '8f053d6e-cc8f-4ae3-ae24-107130510795'
88

99
# OpenCTI initialization
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/get_marking_definitions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Variables
66
api_url = 'https://demo.opencti.io'
7-
api_token = '616e214c-8d86-4226-a653-c521f4ec90d9'
7+
api_token = '8f053d6e-cc8f-4ae3-ae24-107130510795'
88

99
# OpenCTI initialization
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/get_reports_about_intrusion_set.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Variables
66
api_url = 'https://demo.opencti.io'
7-
api_token = '616e214c-8d86-4226-a653-c521f4ec90d9'
7+
api_token = '8f053d6e-cc8f-4ae3-ae24-107130510795'
88

99
# OpenCTI initialization
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/import_stix2_file.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from pycti import OpenCTIApiClient
44

55
# Variables
6-
api_url = 'https://demo.opencti.io'
7-
api_token = '616e214c-8d86-4226-a653-c521f4ec90d9'
6+
api_url = 'https//demo.opencti.io'
7+
api_token = '8f053d6e-cc8f-4ae3-ae24-107130510795'
88

99
# OpenCTI initialization
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)

pycti/entities/opencti_report.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,14 @@ def create(self, **kwargs):
292292
modified = kwargs.get('modified', None)
293293
update = kwargs.get('update', False)
294294

295-
object_result = self.get_by_stix_id_or_name(stix_id_key=stix_id_key, name=name, published=published)
296-
if object_result is None and external_reference_id is not None:
297-
self.opencti.stix_domain_entity.read(
295+
object_result = None
296+
if external_reference_id is not None:
297+
object_result = self.opencti.stix_domain_entity.read(
298298
types=['Report'],
299299
filters=[{'key': 'hasExternalReference', 'values': [external_reference_id]}]
300300
)
301+
if object_result is None and name is not None:
302+
object_result = self.get_by_stix_id_or_name(stix_id_key=stix_id_key, name=name, published=published)
301303
if object_result is not None:
302304
if update:
303305
self.opencti.stix_domain_entity.update_field(id=object_result['id'], key='name', value=name)

pycti/utils/opencti_stix2.py

+7-26
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def extract_embedded_relationships(self, stix_object, types=None):
139139
# TODO Import tags
140140
# Object Tags
141141
tags_ids = []
142-
#if CustomProperties.TAG_TYPE in stix_object:
142+
# if CustomProperties.TAG_TYPE in stix_object:
143143
# for tag in stix_object[CustomProperties.TAG_TYPE]:
144144
# if tag['id'] in self.mapping_cache:
145145
# tag_result = self.mapping_cache[tag['id']]
@@ -220,25 +220,16 @@ def extract_embedded_relationships(self, stix_object, types=None):
220220
'intrusion-set',
221221
'campaign',
222222
'incident',
223-
'malware'
223+
'malware',
224+
'attack-pattern'
224225
] and (types is None or 'report' in types):
225226
# Add a corresponding report
226227
# Extract date
227228
try:
228229
if 'description' in external_reference:
229-
matches = list(datefinder.find_dates(
230-
external_reference['description'],
231-
False,
232-
False,
233-
False,
234-
))
230+
matches = list(datefinder.find_dates(external_reference['description']))
235231
else:
236-
matches = list(datefinder.find_dates(
237-
source_name,
238-
False,
239-
False,
240-
False,
241-
))
232+
matches = list(datefinder.find_dates(source_name))
242233
except:
243234
matches = []
244235
if len(matches) > 0:
@@ -441,19 +432,9 @@ def import_relationship(self, stix_relation, update=False, types=None):
441432
for external_reference in stix_relation['external_references']:
442433
try:
443434
if 'description' in external_reference:
444-
matches = list(datefinder.find_dates(
445-
external_reference['description'],
446-
False,
447-
False,
448-
False,
449-
))
435+
matches = list(datefinder.find_dates(external_reference['description']))
450436
else:
451-
matches = list(datefinder.find_dates(
452-
external_reference['source_name'],
453-
False,
454-
False,
455-
False,
456-
))
437+
matches = list(datefinder.find_dates(external_reference['source_name']))
457438
except:
458439
matches = []
459440
if len(matches) > 0:

0 commit comments

Comments
 (0)