Skip to content

Commit

Permalink
CodeQL recommended changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Captain-T2004 committed Sep 11, 2024
1 parent 10fd8af commit d94f118
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
9 changes: 6 additions & 3 deletions nettacker/api/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,12 @@ def compare_scans():
compare_report_path_filename = get_value(flask_request, "compare_report_path")
if not compare_report_path_filename:
compare_report_path_filename = nettacker_application_config["compare_report_path_filename"]

compare_options = {
"scan_compare_id": scan_id_second,
"compare_report_path_filename": compare_report_path_filename,
}
try:
result = create_compare_report(scan_id_first, scan_id_second, compare_report_path_filename)
result = create_compare_report(compare_options, scan_id_first)
if result:
return jsonify(
structure(
Expand All @@ -242,7 +245,7 @@ def compare_scans():
), 200
return jsonify(structure(status="error", msg="Scan ID not found")), 404
except (FileNotFoundError, PermissionError, IOError):
return jsonify(structure(status="error", msg="Not a valid filepath")), 500
return jsonify(structure(status="error", msg="Invalid file path")), 500


@app.route("/session/check", methods=["GET"])
Expand Down
6 changes: 1 addition & 5 deletions nettacker/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,7 @@ def run(self):
exit_code = self.start_scan(scan_id)
create_report(self.arguments, scan_id)
if self.arguments.scan_compare_id is not None:
create_compare_report(
scan_id,
self.arguments.scan_compare_id,
self.arguments.compare_report_path_filename,
)
create_compare_report(self.arguments, scan_id)
log.info(_("done"))

return exit_code
Expand Down
19 changes: 12 additions & 7 deletions nettacker/core/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ def build_text_table(events):


def create_compare_text_table(results):
_table = texttable.Texttable()
table = texttable.Texttable()
table_headers = list(results.keys())
_table.add_rows([table_headers])
_table.add_rows(
table.add_rows([table_headers])
table.add_rows(
[
table_headers,
[results[col] for col in table_headers],
]
)
_table.set_cols_width([len(i) for i in table_headers])
return _table.draw() + "\n\n"
table.set_cols_width([len(i) for i in table_headers])
return table.draw() + "\n\n"


def create_report(options, scan_id):
Expand Down Expand Up @@ -205,7 +205,7 @@ def create_report(options, scan_id):
return True


def create_compare_report(scan_id, comp_id, filepath):
def create_compare_report(options, scan_id):
"""
if compare_id is given then create the report of comparision b/w scans
Args:
Expand All @@ -214,6 +214,7 @@ def create_compare_report(scan_id, comp_id, filepath):
Returns:
True if success otherwise None
"""
comp_id = options["scan_compare_id"] if isinstance(options, dict) else options.scan_compare_id
scan_log_curr = get_logs_by_scan_id(scan_id)
scan_logs_comp = get_logs_by_scan_id(comp_id)

Expand Down Expand Up @@ -249,7 +250,11 @@ def get_modules_ports(item):
"new_targets_discovered": tuple(curr_modules_ports - comp_modules_ports),
"old_targets_not_detected": tuple(comp_modules_ports - curr_modules_ports),
}
compare_report_path_filename = filepath
compare_report_path_filename = (
options["compare_report_path_filename"]
if isinstance(options, dict)
else options.compare_report_path_filename
)
if (
len(compare_report_path_filename) >= 5 and compare_report_path_filename[-5:] == ".html"
) or (len(compare_report_path_filename) >= 4 and compare_report_path_filename[-4:] == ".htm"):
Expand Down

0 comments on commit d94f118

Please sign in to comment.