fix(fill_html_overview_statistics): Handle if file exists (#1718)

This commit is contained in:
Pepe Fagoaga
2023-01-17 11:40:05 +01:00
committed by GitHub
parent c08342f40c
commit ef0d4fe34b
2 changed files with 24 additions and 17 deletions

View File

@@ -298,7 +298,10 @@ def run_check(check: Check, output_options: Provider_Output_Options) -> list:
try:
findings = check.execute()
except Exception as error:
print(f"Something went wrong in {check.CheckID}, please use --log-level ERROR")
if not output_options.only_logs:
print(
f"Something went wrong in {check.CheckID}, please use --log-level ERROR"
)
logger.error(
f"{check.CheckID} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)

View File

@@ -1,5 +1,6 @@
import sys
from os import path
from prowler.config.config import (
html_file_suffix,
html_logo_img,
@@ -235,23 +236,26 @@ def fill_html_overview_statistics(stats, output_filename, output_directory):
try:
filename = f"{output_directory}/{output_filename}{html_file_suffix}"
# Read file
with open(filename, "r") as file:
filedata = file.read()
if path.isfile(filename):
with open(filename, "r") as file:
filedata = file.read()
# Replace statistics
# TOTAL_FINDINGS
filedata = filedata.replace("TOTAL_FINDINGS", str(stats.get("findings_count")))
# TOTAL_RESOURCES
filedata = filedata.replace(
"TOTAL_RESOURCES", str(stats.get("resources_count"))
)
# TOTAL_PASS
filedata = filedata.replace("TOTAL_PASS", str(stats.get("total_pass")))
# TOTAL_FAIL
filedata = filedata.replace("TOTAL_FAIL", str(stats.get("total_fail")))
# Write file
with open(filename, "w") as file:
file.write(filedata)
# Replace statistics
# TOTAL_FINDINGS
filedata = filedata.replace(
"TOTAL_FINDINGS", str(stats.get("findings_count"))
)
# TOTAL_RESOURCES
filedata = filedata.replace(
"TOTAL_RESOURCES", str(stats.get("resources_count"))
)
# TOTAL_PASS
filedata = filedata.replace("TOTAL_PASS", str(stats.get("total_pass")))
# TOTAL_FAIL
filedata = filedata.replace("TOTAL_FAIL", str(stats.get("total_fail")))
# Write file
with open(filename, "w") as file:
file.write(filedata)
except Exception as error:
logger.critical(