From e1d4843b0549aec5c6ce90e596be0325c5613beb Mon Sep 17 00:00:00 2001 From: "gioacchino.vino" <gioacchino.vino@infn.it> Date: Wed, 6 Dec 2023 16:25:49 +0100 Subject: [PATCH] Changed module names --- files/scan.py | 1 + files/scan_gvm_library.py | 39 +++++++++------------------------------ 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/files/scan.py b/files/scan.py index a032a8f..a3abbfb 100644 --- a/files/scan.py +++ b/files/scan.py @@ -65,6 +65,7 @@ endpoints = utilities.import_dep_info( logging.info(f"endpoints: {endpoints}") # test gmp connection +gvm_library.set_auth(auth_name, auth_passwd) logging.info(f"gvm version: {gvm_library.get_version()}") reports = dict() diff --git a/files/scan_gvm_library.py b/files/scan_gvm_library.py index c7e0e28..7709d83 100644 --- a/files/scan_gvm_library.py +++ b/files/scan_gvm_library.py @@ -13,14 +13,21 @@ transform = EtreeTransform() config = {'id':"9866edc1-8869-4e80-acac-d15d5647b4d9"} scanner = {'id': "08b69003-5fc2-4037-a479-93b440211c73"} ovs_ssh_credential = {'id': "b9af5845-8b87-4378-bca4-cee39a894c17"} +auth_name, auth_passwd = "", "" -def get_version_old(auth_name, auth_passwd): +def set_auth(new_auth_name, new_auth_passwd): + global auth_name + global auth_passwd + auth_name = new_auth_name + auth_passwd = new_auth_passwd + +def get_version_old(): with Gmp(connection, transform=transform) as gmp: gmp.authenticate(auth_name, auth_passwd) pretty_print(gmp.get_version()) -def create_connection(auth_name, auth_passwd): +def create_connection(): connection_retries = 5 retry = connection_retries while(retry > 0): @@ -398,31 +405,3 @@ def process_global_reports_info(reports): reports['global'] = "NOK" return reports -def pretty_json(j): - return json.dumps(j,sort_keys=True,indent=4) - -def import_dep_info(file_path, endpoints_to_scan): - with open(file_path) as f: - data = json.load(f) - endpoints = dict() - for key in data['outputs'].keys(): - if key in endpoints_to_scan: - endpoint = str(data['outputs'][key]) - prefix,url = endpoint.split("://") - if ":" in url: - host,port = url.split(":") - else: - host = url - if prefix == "https": - port = '443' - elif prefix == 'http': - port = '80' - else: - raise Exception(f"Impossible to parse the endpoint port. Endpoint: {endpoint}") - logging.info(f"Endpoint: {host}:{port}") - if host not in endpoints: - endpoints[host] = {"22"} - endpoints[host].add(port) - for host,ports in endpoints.items(): - endpoints[host] = sorted(list(ports)) - return endpoints \ No newline at end of file -- GitLab