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
9 changes: 7 additions & 2 deletions dvc_ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ def _strip_protocol(cls, path: str) -> str:

def unstrip_protocol(self, path: str) -> str:
host = self.fs_args["host"]
port = self.fs_args["port"]
port = self.fs_args.get("port")
path = path.lstrip("/")
return f"ssh://{host}:{port}/{path}"

url = f"ssh://{host}"
if port:
url += f":{port}"
url += f"/{path}"
return url

def _prepare_credentials(self, **config):
from .client import InteractiveSSHClient
Expand Down
14 changes: 14 additions & 0 deletions dvc_ssh/tests/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,17 @@ def test_ssh_keyfile(config, expected_keyfile):
def test_ssh_gss_auth(config, expected_gss_auth):
fs = SSHFileSystem(**config)
assert fs.fs_args["gss_auth"] == expected_gss_auth


@pytest.mark.parametrize(
"config,path,expected_path",
[
({"host": "example.com"}, "path", "ssh://example.com/path"),
({"host": "example.com"}, "/path", "ssh://example.com/path"),
({"host": "example.com", "port": 1234}, "path", "ssh://example.com:1234/path"),
({"host": "example.com", "port": 1234}, "/path", "ssh://example.com:1234/path"),
],
)
def test_unstrip_protocol(mocker, config, path, expected_path):
fs = SSHFileSystem(**config, fs=mocker.MagicMock())
assert fs.unstrip_protocol(path) == expected_path
Loading