Fix crash on empty answer to the unknown host key prompt
An empty answer raised IndexError, and running without a terminal (e.g. from cron) raised EOFError. Treat both as "no", and log why the connection was aborted.
This commit is contained in:
@@ -375,12 +375,18 @@ class Backup:
|
||||
|
||||
return ssh
|
||||
except UserWarning:
|
||||
k = input(
|
||||
f'Unknown key for host {self.ssh_host}. Continue anyway? (Y/N) ')
|
||||
try:
|
||||
k = input(
|
||||
f'Unknown key for host {self.ssh_host}. Continue anyway? (Y/N) ')
|
||||
except EOFError:
|
||||
# No terminal available (e.g. cron or systemd)
|
||||
k = ''
|
||||
|
||||
if k[0].upper() == 'Y':
|
||||
if k.strip().upper().startswith('Y'):
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
else:
|
||||
logger.critical('Unknown host key for %s. Connection aborted', self.ssh_host)
|
||||
|
||||
return None
|
||||
except paramiko.BadHostKeyException as e:
|
||||
logger.critical('Can\'t connect to the server.')
|
||||
|
||||
Reference in New Issue
Block a user