Skip to content

Commit

Permalink
Merge pull request iterative#2315 from Suor/ask
Browse files Browse the repository at this point in the history
ssh: do not ask for same password repeatedly
  • Loading branch information
efiop authored Jul 23, 2019
2 parents 12461cf + 59eb929 commit 507879e
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions dvc/remote/ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import itertools
import errno
from concurrent.futures import ThreadPoolExecutor
import threading

try:
import paramiko
Expand All @@ -26,6 +27,10 @@
logger = logging.getLogger(__name__)


saved_passwords = {}
saved_passwords_lock = threading.Lock()


class RemoteSSH(RemoteBASE):
scheme = Schemes.SSH
REQUIRES = {"paramiko": paramiko}
Expand Down Expand Up @@ -115,13 +120,19 @@ def ssh(self, path_info):
host, user, port = path_info.host, path_info.user, path_info.port

# NOTE: we use the same password regardless of the server :(
if self.ask_password and not self.password:
self.password = prompt.password(
"Enter a private key passphrase or a password for "
"host '{host}' port '{port}' user '{user}'".format(
host=host, port=port, user=user
)
)
if self.ask_password and self.password is None:
with saved_passwords_lock:
server_key = (host, user, port)
password = saved_passwords.get(server_key)

if password is None:
saved_passwords[server_key] = password = prompt.password(
"Enter a private key passphrase or a password for "
"host '{host}' port '{port}' user '{user}'".format(
host=host, port=port, user=user
)
)
self.password = password

return get_connection(
SSHConnection,
Expand Down

0 comments on commit 507879e

Please sign in to comment.