diff --git a/eNMS/models/services/file_transfer/generic_file_transfer.py b/eNMS/models/services/file_transfer/generic_file_transfer.py index 74359f966..c69d04e83 100644 --- a/eNMS/models/services/file_transfer/generic_file_transfer.py +++ b/eNMS/models/services/file_transfer/generic_file_transfer.py @@ -48,8 +48,7 @@ def job(self, run, device): ssh_client.load_system_host_keys() source = run.sub(run.source_file, locals()) destination = run.sub(run.destination_file, locals()) - credentials = run.get_credentials(device) - credentials.pop("secret", None) + credentials = run.get_credentials(device, add_secret=False) ssh_client.connect(device.ip_address, look_for_keys=False, **credentials) if run.source_file_includes_globbing: glob_source_file_list = glob(source, recursive=False) diff --git a/eNMS/runner.py b/eNMS/runner.py index 0b4e9a188..c44d9d71f 100644 --- a/eNMS/runner.py +++ b/eNMS/runner.py @@ -701,7 +701,7 @@ def notify(self, results): results["notification"] = {"success": True, "result": result} return results - def get_credentials(self, device): + def get_credentials(self, device, add_secret=True): result, credential_type = {}, self.main_run.service.credential_type credential = db.get_credential( self.creator, @@ -709,7 +709,7 @@ def get_credentials(self, device): credential_type=credential_type, optional=self.credentials != "device", ) - if device and credential: + if add_secret and device and credential: log = f"Using '{credential.name}' credential for '{device.name}'" self.log("info", log) result["secret"] = env.get_password(credential.enable_password) @@ -1014,7 +1014,7 @@ def netmiko_connection(self, device): gateways = sorted(device.gateways, key=attrgetter("priority"), reverse=True) for gateway in gateways: try: - credentials = self.get_credentials(gateway) + credentials = self.get_credentials(gateway, add_secret=False) connection_log = f"Trying to establish connection to {gateway}" self.log("info", connection_log, device, logger="security") client = SSHClient() @@ -1022,8 +1022,7 @@ def netmiko_connection(self, device): client.connect( hostname=gateway.ip_address, port=gateway.port, - username=credentials["username"], - password=credentials["password"], + **credentials ) sock = client.get_transport().open_channel( "direct-tcpip", (device.ip_address, device.port), ("", 0)