diff options
author | Chris Opland <christian.opland@here.com> | 2019-04-12 10:48:39 -0500 |
---|---|---|
committer | Chris Opland <christian.opland@here.com> | 2019-04-12 10:48:41 -0500 |
commit | c36cfd0b059fc2b3c8ab84db5179cc8c8e7143c6 (patch) | |
tree | 32b2e21a35421d60c15fc848bfce0b040b553c8d /pygerrit/ssh.py | |
parent | 89578cb65abc4cdaa41304663ed9ef206794b681 (diff) | |
download | pygerrit-c36cfd0b059fc2b3c8ab84db5179cc8c8e7143c6.tar.gz |
Add support for automatically adding known_hosts
Currently, if a server is not in the known_hosts file then
the client will fail with an error like:
paramiko.SSHException: Server '[<host>]:<port>' not found in known_hosts
This change allows users to configure paramiko with the AutoAddPolicy().
It should be noted that using this policy opens users to
man-in-the-middle attacks, which is why it is an optional setting and
defaults to False.
Diffstat (limited to 'pygerrit/ssh.py')
-rw-r--r-- | pygerrit/ssh.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/pygerrit/ssh.py b/pygerrit/ssh.py index fbc5a29..03952e3 100644 --- a/pygerrit/ssh.py +++ b/pygerrit/ssh.py @@ -29,7 +29,7 @@ from threading import Event, Lock from .error import GerritError -from paramiko import SSHClient, SSHConfig, ProxyCommand +from paramiko import AutoAddPolicy, SSHClient, SSHConfig, ProxyCommand from paramiko.ssh_exception import SSHException @@ -65,7 +65,8 @@ class GerritSSHClient(SSHClient): """ Gerrit SSH Client, wrapping the paramiko SSH Client. """ - def __init__(self, hostname, username=None, port=None, keepalive=None): + def __init__(self, hostname, username=None, port=None, + keepalive=None, auto_add_hosts=False): """ Initialise and connect to SSH. """ super(GerritSSHClient, self).__init__() self.remote_version = None @@ -77,6 +78,8 @@ class GerritSSHClient(SSHClient): self.lock = Lock() self.proxy = None self.keepalive = keepalive + if auto_add_hosts: + self.set_missing_host_key_policy(AutoAddPolicy()) def _configure(self): """ Configure the ssh parameters from the config file. """ |