Skip to content

Commit

Permalink
[import-document] Fix self file is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelHassine committed May 26, 2022
1 parent 849a0a8 commit c7f36d9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal-import-file/import-document/src/reportimporter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def __init__(self) -> None:
else:
raise FileNotFoundError(f"{entity_config_file} was not found")

self.file = None

def _process_message(self, data: Dict) -> str:
self.helper.log_info("Processing new message")
file_name = self._download_import_file(data)
Expand All @@ -86,6 +88,7 @@ def _process_message(self, data: Dict) -> str:

# Parse report
parser = ReportParser(self.helper, entity_indicators, self.observable_config)

if data["file_id"].startswith("import/global"):
file_data = open(file_name, "rb").read()
file_data_encoded = base64.b64encode(file_data)
Expand Down Expand Up @@ -355,7 +358,9 @@ def _process_parsed_objects(
report_types=entity["report_types"],
object_refs=observables + entities,
allow_custom=True,
custom_properties={"x_opencti_files": [self.file]},
custom_properties={
"x_opencti_files": [self.file] if self.file is not None else []
},
)
observables.append(report)
elif entity is not None:
Expand All @@ -375,7 +380,9 @@ def _process_parsed_objects(
report_types=["threat-report"],
object_refs=observables + entities,
allow_custom=True,
custom_properties={"x_opencti_files": [self.file]},
custom_properties={
"x_opencti_files": [self.file] if self.file is not None else []
},
)
observables.append(report)
bundles_sent = []
Expand Down

0 comments on commit c7f36d9

Please sign in to comment.