diff --git a/files/scan.py b/files/scan.py index a032a8f36ab15f3ddbfc6bb86d10c8759491c5b8..a3abbfb5903535498c92635696f1099249586a39 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 c7e0e2883ddd21ad7f023a79d19a3114909e7c84..08599578b40e6cbb84b30b0721bf58ee9b910af0 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(auth_n, auth_p): + global auth_name + global auth_passwd + auth_name = auth_n + auth_passwd = auth_p + +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