Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: SSHClientConfig.__init__() missing 2 required positional args #99

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
parse config from sshfs copied and edited
  • Loading branch information
99-NinetyNine authored Jan 7, 2025
commit f8e9f3946d9ce46db3c977232386f71cf9b5d683
57 changes: 47 additions & 10 deletions dvc_ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,53 @@
from dvc_objects.fs.base import FileSystem
from dvc_objects.fs.utils import as_atomic


import getpass
from contextlib import suppress
from pathlib import Path, PurePath
from typing import Sequence, Union
from asyncssh.config import SSHClientConfig

SSH_CONFIG = Path("~", ".ssh", "config").expanduser()
FilePath = Union[str, PurePath]

DEFAULT_PORT = 22

def parse_config(
*, host, user=(), port=(), local_user=None, config_files=None
):
if config_files is None:
config_files = [SSH_CONFIG]

if local_user is None:
with suppress(KeyError):
local_user = getpass.getuser()

last_config = None
reload = False
config = SSHClientConfig(
last_config =last_config,
reload = reload,
canonical = False,
final=False,
local_user = local_user,
user = user,
host = host,
port = port,
)

if config_files:
if isinstance(config_files, (str, PurePath)):
paths: Sequence[FilePath] = [config_files]
else:
paths = config_files

for path in paths:
config.parse(Path(path))
config.loaded = True
return config



@wrap_with(threading.Lock())
@memoize
Expand Down Expand Up @@ -41,7 +86,7 @@ def unstrip_protocol(self, path: str) -> str:
return f"ssh://{host}:{port}/{path}"

def _prepare_credentials(self, **config):
from sshfs.config import parse_config
# from sshfs.config import parse_config

from .client import InteractiveSSHClient

Expand All @@ -52,17 +97,9 @@ def _prepare_credentials(self, **config):
"client_factory", InteractiveSSHClient
)
try:
assert config.get("host") is not None
user_ssh_config = parse_config(
host=config["host"], port=config.get("port", DEFAULT_PORT)
)

user_ssh_config = parse_config(host=config["host"], port=config.get("port", DEFAULT_PORT))
except FileNotFoundError:
user_ssh_config = {}
except AssertionError:
# host could have been None
# just doing this to check if test passes
user_ssh_config = {}

login_info["host"] = user_ssh_config.get("Hostname", config["host"])

Expand Down