|
8 | 8 | import os |
9 | 9 | import threading |
10 | 10 | from concurrent.futures import ThreadPoolExecutor |
11 | | -from contextlib import closing |
12 | | -from contextlib import contextmanager |
| 11 | +from contextlib import closing, contextmanager |
| 12 | + |
| 13 | +from funcy import memoize, wrap_with |
13 | 14 |
|
14 | 15 | import dvc.prompt as prompt |
15 | 16 | from dvc.config import Config |
|
24 | 25 | logger = logging.getLogger(__name__) |
25 | 26 |
|
26 | 27 |
|
27 | | -saved_passwords = {} |
28 | | -saved_passwords_lock = threading.Lock() |
| 28 | +@wrap_with(threading.Lock()) |
| 29 | +@memoize |
| 30 | +def ask_password(host, user, port): |
| 31 | + return prompt.password( |
| 32 | + "Enter a private key passphrase or a password for " |
| 33 | + "host '{host}' port '{port}' user '{user}'".format( |
| 34 | + host=host, port=port, user=user |
| 35 | + ) |
| 36 | + ) |
29 | 37 |
|
30 | 38 |
|
31 | 39 | class RemoteSSH(RemoteBASE): |
@@ -120,21 +128,11 @@ def _try_get_ssh_config_keyfile(user_ssh_config): |
120 | 128 | def ensure_credentials(self, path_info=None): |
121 | 129 | if path_info is None: |
122 | 130 | path_info = self.path_info |
123 | | - host, user, port = path_info.host, path_info.user, path_info.port |
| 131 | + |
124 | 132 | # NOTE: we use the same password regardless of the server :( |
125 | 133 | if self.ask_password and self.password is None: |
126 | | - with saved_passwords_lock: |
127 | | - server_key = (host, user, port) |
128 | | - password = saved_passwords.get(server_key) |
129 | | - |
130 | | - if password is None: |
131 | | - saved_passwords[server_key] = password = prompt.password( |
132 | | - "Enter a private key passphrase or a password for " |
133 | | - "host '{host}' port '{port}' user '{user}'".format( |
134 | | - host=host, port=port, user=user |
135 | | - ) |
136 | | - ) |
137 | | - self.password = password |
| 134 | + host, user, port = path_info.host, path_info.user, path_info.port |
| 135 | + self.password = ask_password(host, user, port) |
138 | 136 |
|
139 | 137 | def ssh(self, path_info): |
140 | 138 | self.ensure_credentials(path_info) |
|
0 commit comments