@@ -554,14 +554,17 @@ def extract_embedded_relationships(
554
554
)["id" ]
555
555
if "x_opencti_files" in external_reference :
556
556
for file in external_reference ["x_opencti_files" ]:
557
- self .opencti .external_reference .add_file (
558
- id = external_reference_id ,
559
- file_name = file ["name" ],
560
- version = file .get ("version" , None ),
561
- data = base64 .b64decode (file ["data" ]),
562
- mime_type = file ["mime_type" ],
563
- no_trigger_import = file .get ("no_trigger_import" , False ),
564
- )
557
+ if "data" in file :
558
+ self .opencti .external_reference .add_file (
559
+ id = external_reference_id ,
560
+ file_name = file ["name" ],
561
+ version = file .get ("version" , None ),
562
+ data = base64 .b64decode (file ["data" ]),
563
+ mime_type = file ["mime_type" ],
564
+ no_trigger_import = file .get (
565
+ "no_trigger_import" , False
566
+ ),
567
+ )
565
568
if (
566
569
self .opencti .get_attribute_in_extension (
567
570
"files" , external_reference
@@ -571,14 +574,17 @@ def extract_embedded_relationships(
571
574
for file in self .opencti .get_attribute_in_extension (
572
575
"files" , external_reference
573
576
):
574
- self .opencti .external_reference .add_file (
575
- id = external_reference_id ,
576
- file_name = file ["name" ],
577
- version = file .get ("version" , None ),
578
- data = base64 .b64decode (file ["data" ]),
579
- mime_type = file ["mime_type" ],
580
- no_trigger_import = file .get ("no_trigger_import" , False ),
581
- )
577
+ if "data" in file :
578
+ self .opencti .external_reference .add_file (
579
+ id = external_reference_id ,
580
+ file_name = file ["name" ],
581
+ version = file .get ("version" , None ),
582
+ data = base64 .b64decode (file ["data" ]),
583
+ mime_type = file ["mime_type" ],
584
+ no_trigger_import = file .get (
585
+ "no_trigger_import" , False
586
+ ),
587
+ )
582
588
self .mapping_cache [generated_ref_id ] = generated_ref_id
583
589
external_references_ids .append (external_reference_id )
584
590
if stix_object ["type" ] in [
@@ -722,29 +728,31 @@ def extract_embedded_relationships(
722
728
)["id" ]
723
729
if "x_opencti_files" in external_reference :
724
730
for file in external_reference ["x_opencti_files" ]:
725
- self .opencti .external_reference .add_file (
726
- id = external_reference_id ,
727
- file_name = file ["name" ],
728
- version = file .get ("version" , None ),
729
- data = base64 .b64decode (file ["data" ]),
730
- mime_type = file ["mime_type" ],
731
- no_trigger_import = file .get ("no_trigger_import" , False ),
732
- )
731
+ if "data" in file :
732
+ self .opencti .external_reference .add_file (
733
+ id = external_reference_id ,
734
+ file_name = file ["name" ],
735
+ version = file .get ("version" , None ),
736
+ data = base64 .b64decode (file ["data" ]),
737
+ mime_type = file ["mime_type" ],
738
+ no_trigger_import = file .get ("no_trigger_import" , False ),
739
+ )
733
740
if (
734
741
self .opencti .get_attribute_in_extension ("files" , external_reference )
735
742
is not None
736
743
):
737
744
for file in self .opencti .get_attribute_in_extension (
738
745
"files" , external_reference
739
746
):
740
- self .opencti .external_reference .add_file (
741
- id = external_reference_id ,
742
- file_name = file ["name" ],
743
- version = file .get ("version" , None ),
744
- data = base64 .b64decode (file ["data" ]),
745
- mime_type = file ["mime_type" ],
746
- no_trigger_import = file .get ("no_trigger_import" , False ),
747
- )
747
+ if "data" in file :
748
+ self .opencti .external_reference .add_file (
749
+ id = external_reference_id ,
750
+ file_name = file ["name" ],
751
+ version = file .get ("version" , None ),
752
+ data = base64 .b64decode (file ["data" ]),
753
+ mime_type = file ["mime_type" ],
754
+ no_trigger_import = file .get ("no_trigger_import" , False ),
755
+ )
748
756
self .mapping_cache [generated_ref_id ] = generated_ref_id
749
757
external_references_ids .append (external_reference_id )
750
758
# Granted refs
@@ -948,29 +956,31 @@ def import_object(
948
956
# Add files
949
957
if "x_opencti_files" in stix_object :
950
958
for file in stix_object ["x_opencti_files" ]:
951
- self .opencti .stix_domain_object .add_file (
952
- id = stix_object_result ["id" ],
953
- file_name = file ["name" ],
954
- version = file .get ("version" , None ),
955
- data = base64 .b64decode (file ["data" ]),
956
- mime_type = file ["mime_type" ],
957
- no_trigger_import = file .get ("no_trigger_import" , False ),
958
- )
959
+ if "data" in file :
960
+ self .opencti .stix_domain_object .add_file (
961
+ id = stix_object_result ["id" ],
962
+ file_name = file ["name" ],
963
+ version = file .get ("version" , None ),
964
+ data = base64 .b64decode (file ["data" ]),
965
+ mime_type = file ["mime_type" ],
966
+ no_trigger_import = file .get ("no_trigger_import" , False ),
967
+ )
959
968
if (
960
969
self .opencti .get_attribute_in_extension ("files" , stix_object )
961
970
is not None
962
971
):
963
972
for file in self .opencti .get_attribute_in_extension (
964
973
"files" , stix_object
965
974
):
966
- self .opencti .stix_domain_object .add_file (
967
- id = stix_object_result ["id" ],
968
- file_name = file ["name" ],
969
- version = file .get ("version" , None ),
970
- data = base64 .b64decode (file ["data" ]),
971
- mime_type = file ["mime_type" ],
972
- no_trigger_import = file .get ("no_trigger_import" , False ),
973
- )
975
+ if "data" in file :
976
+ self .opencti .stix_domain_object .add_file (
977
+ id = stix_object_result ["id" ],
978
+ file_name = file ["name" ],
979
+ version = file .get ("version" , None ),
980
+ data = base64 .b64decode (file ["data" ]),
981
+ mime_type = file ["mime_type" ],
982
+ no_trigger_import = file .get ("no_trigger_import" , False ),
983
+ )
974
984
return stix_object_results
975
985
976
986
def import_observable (
@@ -1071,29 +1081,31 @@ def import_observable(
1071
1081
# Add files
1072
1082
if "x_opencti_files" in stix_object :
1073
1083
for file in stix_object ["x_opencti_files" ]:
1074
- self .opencti .stix_cyber_observable .add_file (
1075
- id = stix_observable_result ["id" ],
1076
- file_name = file ["name" ],
1077
- version = file .get ("version" , None ),
1078
- data = base64 .b64decode (file ["data" ]),
1079
- mime_type = file ["mime_type" ],
1080
- no_trigger_import = file .get ("no_trigger_import" , False ),
1081
- )
1084
+ if "data" in file :
1085
+ self .opencti .stix_cyber_observable .add_file (
1086
+ id = stix_observable_result ["id" ],
1087
+ file_name = file ["name" ],
1088
+ version = file .get ("version" , None ),
1089
+ data = base64 .b64decode (file ["data" ]),
1090
+ mime_type = file ["mime_type" ],
1091
+ no_trigger_import = file .get ("no_trigger_import" , False ),
1092
+ )
1082
1093
if (
1083
1094
self .opencti .get_attribute_in_extension ("files" , stix_object )
1084
1095
is not None
1085
1096
):
1086
1097
for file in self .opencti .get_attribute_in_extension (
1087
1098
"files" , stix_object
1088
1099
):
1089
- self .opencti .stix_cyber_observable .add_file (
1090
- id = stix_observable_result ["id" ],
1091
- file_name = file ["name" ],
1092
- version = file .get ("version" , None ),
1093
- data = base64 .b64decode (file ["data" ]),
1094
- mime_type = file ["mime_type" ],
1095
- no_trigger_import = file .get ("no_trigger_import" , False ),
1096
- )
1100
+ if "data" in file :
1101
+ self .opencti .stix_cyber_observable .add_file (
1102
+ id = stix_observable_result ["id" ],
1103
+ file_name = file ["name" ],
1104
+ version = file .get ("version" , None ),
1105
+ data = base64 .b64decode (file ["data" ]),
1106
+ mime_type = file ["mime_type" ],
1107
+ no_trigger_import = file .get ("no_trigger_import" , False ),
1108
+ )
1097
1109
if "id" in stix_object :
1098
1110
self .mapping_cache [stix_object ["id" ]] = {
1099
1111
"id" : stix_observable_result ["id" ],
0 commit comments