summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-03-06 13:34:16 -0600
committerGitHub <noreply@github.com>2024-03-06 13:34:16 -0600
commit38fdc27ee2b3253053b2794e3e7ec5d8e0d5aa02 (patch)
tree78cf549f9985281ae0b11d48d0e5080ed8b541e1
parent836adb807651a7c6bf5042aa81012a9b44e3161d (diff)
parent73e215dc338c8c3a6c9b3d10c952477ba00b923b (diff)
downloadvyos-1x-38fdc27ee2b3253053b2794e3e7ec5d8e0d5aa02.tar.gz
vyos-1x-38fdc27ee2b3253053b2794e3e7ec5d8e0d5aa02.zip
Merge pull request #3100 from jestabro/non-interactive-upload
remote: T6104: fix logic of failure case in MissingHostKeyPolicy
-rw-r--r--python/vyos/remote.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/python/vyos/remote.py b/python/vyos/remote.py
index 129e65772..d87fd24f6 100644
--- a/python/vyos/remote.py
+++ b/python/vyos/remote.py
@@ -43,6 +43,7 @@ from vyos.utils.io import print_error
from vyos.utils.misc import begin
from vyos.utils.process import cmd, rc_cmd
from vyos.version import get_version
+from vyos.base import Warning
CHUNK_SIZE = 8192
@@ -54,13 +55,16 @@ class InteractivePolicy(MissingHostKeyPolicy):
def missing_host_key(self, client, hostname, key):
print_error(f"Host '{hostname}' not found in known hosts.")
print_error('Fingerprint: ' + key.get_fingerprint().hex())
- if sys.stdin.isatty() and ask_yes_no('Do you wish to continue?'):
- if client._host_keys_filename\
- and ask_yes_no('Do you wish to permanently add this host/key pair to known hosts?'):
- client._host_keys.add(hostname, key.get_name(), key)
- client.save_host_keys(client._host_keys_filename)
- else:
+ if not sys.stdin.isatty():
+ return
+ if not ask_yes_no('Do you wish to continue?'):
raise SSHException(f"Cannot connect to unknown host '{hostname}'.")
+ if client._host_keys_filename is None:
+ Warning('no \'known_hosts\' file; create to store keys permanently')
+ return
+ if ask_yes_no('Do you wish to permanently add this host/key pair to known_hosts file?'):
+ client._host_keys.add(hostname, key.get_name(), key)
+ client.save_host_keys(client._host_keys_filename)
class SourceAdapter(HTTPAdapter):
"""