Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions dvc_ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@

@wrap_with(threading.Lock())
@memoize
def ask_password(host, user, port):
def ask_password(host, user, port, desc):
return getpass.getpass(
"Enter a private key passphrase or a password for "
f"host '{host}' port '{port}' user '{user}':\n"
f"Enter a {desc} for " f"host '{host}' port '{port}' user '{user}':\n"
)


Expand Down Expand Up @@ -62,13 +61,16 @@ def _prepare_credentials(self, **config):
or DEFAULT_PORT
)

if config.get("ask_password") and config.get("password") is None:
config["password"] = ask_password(
login_info["host"], login_info["username"], login_info["port"]
)
for option in ("password", "passphrase"):
login_info[option] = config.get(option, None)

login_info["password"] = config.get("password")
login_info["passphrase"] = config.get("password")
if config.get(f"ask_{option}") and login_info[option] is None:
login_info[option] = ask_password(
login_info["host"],
login_info["username"],
login_info["port"],
option,
)

raw_keys = []
if config.get("keyfile"):
Expand Down
15 changes: 15 additions & 0 deletions dvc_ssh/tests/test_prepare_credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

from dvc_ssh import SSHFileSystem


@pytest.mark.parametrize("password", [None, "foo"])
@pytest.mark.parametrize("passphrase", [None, "bar"])
def test_passphrase(mocker, password, passphrase):
connect = mocker.patch("asyncssh.connect")

kwargs = {"password": password, "passphrase": passphrase}
_ = SSHFileSystem(host="foo", **kwargs).fs

assert connect.call_args[1]["password"] == password
assert connect.call_args[1]["passphrase"] == passphrase