diff --git a/nettacker/api/engine.py b/nettacker/api/engine.py index 215bf91b..5a71f0d2 100644 --- a/nettacker/api/engine.py +++ b/nettacker/api/engine.py @@ -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( @@ -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"]) diff --git a/nettacker/core/app.py b/nettacker/core/app.py index 06f0ca37..cc63fb6e 100644 --- a/nettacker/core/app.py +++ b/nettacker/core/app.py @@ -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 diff --git a/nettacker/core/graph.py b/nettacker/core/graph.py index 87f79583..9d594caf 100644 --- a/nettacker/core/graph.py +++ b/nettacker/core/graph.py @@ -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): @@ -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: @@ -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) @@ -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"):