@@ -280,7 +280,7 @@ def prepare_export(self, entity, stix_object, mode='simple'):
280280
281281 return result
282282
283- def import_object (self , stix_object , update = False ):
283+ def import_object (self , stix_object , update = False , types = None ):
284284 logging .info ('Importing a ' + stix_object ['type' ] + ' (id: ' + stix_object ['id' ] + ')' )
285285 # Reports
286286 reports = {}
@@ -335,7 +335,8 @@ def import_object(self, stix_object, update=False):
335335 self .mapping_cache [url ] = {'id' : external_reference_id }
336336 external_references_ids .append (external_reference_id )
337337
338- if stix_object ['type' ] in ['threat-actor' , 'intrusion-set' , 'campaign' , 'incident' , 'malware' ]:
338+ if stix_object ['type' ] in ['threat-actor' , 'intrusion-set' , 'campaign' , 'incident' , 'malware' ] and (
339+ types is None or 'report' in types ):
339340 # Add a corresponding report
340341 # Extract date
341342 if 'description' in external_reference :
@@ -1228,7 +1229,7 @@ def import_bundle(self, stix_bundle, update=False, types=None) -> List:
12281229 start_time = time .time ()
12291230 for item in stix_bundle ['objects' ]:
12301231 if item ['type' ] == 'marking-definition' :
1231- self .import_object (item , update )
1232+ self .import_object (item , update , types )
12321233 imported_elements .append ({'id' : item ['id' ], 'type' : item ['type' ]})
12331234 end_time = time .time ()
12341235 logging .info ("Marking definitions imported in: %ssecs" % round (end_time - start_time ))
@@ -1237,7 +1238,7 @@ def import_bundle(self, stix_bundle, update=False, types=None) -> List:
12371238 for item in stix_bundle ['objects' ]:
12381239 if item ['type' ] == 'identity' and (len (types ) == 0 or 'identity' in types or (
12391240 CustomProperties .IDENTITY_TYPE in item and item [CustomProperties .IDENTITY_TYPE ] in types )):
1240- self .import_object (item , update )
1241+ self .import_object (item , update , types )
12411242 imported_elements .append ({'id' : item ['id' ], 'type' : item ['type' ]})
12421243 end_time = time .time ()
12431244 logging .info ("Identities imported in: %ssecs" % round (end_time - start_time ))
@@ -1246,23 +1247,23 @@ def import_bundle(self, stix_bundle, update=False, types=None) -> List:
12461247 for item in stix_bundle ['objects' ]:
12471248 if item ['type' ] != 'relationship' and item ['type' ] != 'report' and (
12481249 len (types ) == 0 or item ['type' ] in types ):
1249- self .import_object (item , update )
1250+ self .import_object (item , update , types )
12501251 imported_elements .append ({'id' : item ['id' ], 'type' : item ['type' ]})
12511252 end_time = time .time ()
12521253 logging .info ("Objects imported in: %ssecs" % round (end_time - start_time ))
12531254
12541255 start_time = time .time ()
12551256 for item in stix_bundle ['objects' ]:
12561257 if item ['type' ] == 'relationship' :
1257- self .import_relationship (item , update )
1258+ self .import_relationship (item , update , types )
12581259 imported_elements .append ({'id' : item ['id' ], 'type' : item ['type' ]})
12591260 end_time = time .time ()
12601261 logging .info ("Relationships imported in: %ssecs" % round (end_time - start_time ))
12611262
12621263 start_time = time .time ()
12631264 for item in stix_bundle ['objects' ]:
12641265 if item ['type' ] == 'report' and (len (types ) == 0 or 'report' in types ):
1265- self .import_object (item , update )
1266+ self .import_object (item , update , types )
12661267 imported_elements .append ({'id' : item ['id' ], 'type' : item ['type' ]})
12671268 end_time = time .time ()
12681269 logging .info ("Reports imported in: %ssecs" % round (end_time - start_time ))
0 commit comments