From 0682511a05896cd77e03e65e08b06bcd351c08dd Mon Sep 17 00:00:00 2001 From: Gioacchino Vino <gioacchino.vino@infn.it> Date: Wed, 24 Apr 2024 18:22:30 +0200 Subject: [PATCH] Reviewed code --- files/gvm_library.py | 37 +------------------------------------ files/scan.py | 8 ++++---- 2 files changed, 5 insertions(+), 40 deletions(-) diff --git a/files/gvm_library.py b/files/gvm_library.py index dfef5bc..4dfd993 100644 --- a/files/gvm_library.py +++ b/files/gvm_library.py @@ -521,39 +521,4 @@ class GVMClient(): def get_version(self) -> str: res = self.client.get_version() - return str(res.xpath('version/text()')[0]) - - def delete_port_list(self, pl: PortList): - res = self.client.delete_port_list(pl.id) - status = res.xpath(GVM_XPATH_STATUS)[0] - status_text = res.xpath(GVM_XPATH_STATUS_TEXT)[0] - if status == GVM_STATUS_OK: - logging.info(f"Port_list {pl} DELETED") - else: - logging.error(f"ERROR {status}: {status_text}") - - def delete_target(self, target: Target): - res = self.client.delete_target(target.id) - status = res.xpath(GVM_XPATH_STATUS)[0] - status_text = res.xpath(GVM_XPATH_STATUS_TEXT)[0] - if status == GVM_STATUS_OK: - logging.info(f"Target {target} DELETED") - else: - logging.error(f"ERROR {status}: {status_text}") - - def search_and_delete_target(self, target_name: str): - targets = self.get_targets(target_name) - if len(targets) == 1: - self.delete_target(targets[0]['id']) - else: - raise GvmException("Multiple results for search") - - def search_and_delete_all_targets(self, target_name: str): - targets = self.get_targets(target_name) - for target in targets: - self.delete_target(target) - - def delete_all_tasks(self, filter: str): - tasks = self.get_tasks(filter) - for task in tasks: - self.delete_task(task) \ No newline at end of file + return str(res.xpath('version/text()')[0]) \ No newline at end of file diff --git a/files/scan.py b/files/scan.py index 0aa8191..ae845f6 100644 --- a/files/scan.py +++ b/files/scan.py @@ -96,19 +96,19 @@ for host,ports in endpoints.items(): summary_filename = f"{output_dir}/summary-report.json" # Create PortList obj related to endpoint - port_list = PortList(client = gvm.get_client(), + port_list = PortList(client = gvm.client, name = port_list_name, ports = ports) logging.info(f"Port list:\n {port_list}") # Create Target obj related to endpoint - target = Target(client = gvm.get_client(), + target = Target(client = gvm.client, name = target_name, host = host, - port_list =port_list) + port_list = port_list) logging.info(f"Target:\n {target}") - task = Task(client= gvm.get_client(), + task = Task(client= gvm.client, name = task_name, target = target) logging.info(f"Task:\n {task}") -- GitLab