Skip to content

Commit a5ab013

Browse files
authored
remote[ssh]: Add the parameter allow_agent (#4623)
This parameter is passed to paramiko. See http://docs.paramiko.org/en/stable/api/client.html?highlight=allow_agent#paramiko.client.SSHClient.connect for more details. Fixes #4186
1 parent a664059 commit a5ab013

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

dvc/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class RelPath(str):
190190
"keyfile": str,
191191
"timeout": Coerce(int),
192192
"gss_auth": Bool,
193+
"allow_agent": Bool,
193194
**REMOTE_COMMON,
194195
},
195196
"hdfs": {"user": str, **REMOTE_COMMON},

dvc/tree/ssh/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def __init__(self, repo, config):
9191
self.sock = paramiko.ProxyCommand(proxy_command)
9292
else:
9393
self.sock = None
94+
self.allow_agent = config.get("allow_agent", True)
9495

9596
@staticmethod
9697
def ssh_config_filename():
@@ -143,6 +144,7 @@ def ssh(self, path_info):
143144
password=self.password,
144145
gss_auth=self.gss_auth,
145146
sock=self.sock,
147+
allow_agent=self.allow_agent,
146148
)
147149

148150
@contextmanager

tests/unit/remote/ssh/test_ssh.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,31 @@ def test_ssh_gss_auth(mock_file, mock_exists, dvc, config, expected_gss_auth):
183183
assert tree.gss_auth == expected_gss_auth
184184

185185

186+
@pytest.mark.parametrize(
187+
"config,expected_allow_agent",
188+
[
189+
({"url": "ssh://example.com"}, True),
190+
({"url": "ssh://not_in_ssh_config.com"}, True),
191+
({"url": "ssh://example.com", "allow_agent": True}, True),
192+
({"url": "ssh://example.com", "allow_agent": False}, False),
193+
],
194+
)
195+
@patch("os.path.exists", return_value=True)
196+
@patch(
197+
f"{builtin_module_name}.open",
198+
new_callable=mock_open,
199+
read_data=mock_ssh_config,
200+
)
201+
def test_ssh_allow_agent(
202+
mock_file, mock_exists, dvc, config, expected_allow_agent
203+
):
204+
tree = SSHTree(dvc, config)
205+
206+
mock_exists.assert_called_with(SSHTree.ssh_config_filename())
207+
mock_file.assert_called_with(SSHTree.ssh_config_filename())
208+
assert tree.allow_agent == expected_allow_agent
209+
210+
186211
def test_hardlink_optimization(dvc, tmp_dir, ssh):
187212
tree = SSHTree(dvc, ssh.config)
188213

0 commit comments

Comments
 (0)