clan-lib: Remove override args from parse_deployment_address, instead use the Remote.override method where necessary

This commit is contained in:
Qubasa
2025-06-23 15:20:09 +02:00
parent 6350978ad0
commit 255f2da358
3 changed files with 15 additions and 30 deletions

View File

@@ -62,8 +62,7 @@ class DeployInfo:
remote = Remote.from_deployment_address(
machine_name="clan-installer",
address=addr,
password=password,
).override(host_key_check=host_key_check)
).override(host_key_check=host_key_check, password=password)
addrs.append(remote)
else:
msg = f"Invalid address format: {addr}"
@@ -72,9 +71,7 @@ class DeployInfo:
remote = Remote.from_deployment_address(
machine_name="clan-installer",
address=tor_addr,
password=password,
tor_socks=True,
).override(host_key_check=host_key_check)
).override(host_key_check=host_key_check, tor_socks=True, password=password)
addrs.append(remote)
return DeployInfo(addrs=addrs)

View File

@@ -1,7 +1,6 @@
import re
import urllib.parse
from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING
from clan_lib.errors import ClanError
@@ -13,12 +12,14 @@ def parse_deployment_address(
*,
machine_name: str,
address: str,
forward_agent: bool = True,
meta: dict[str, Any] | None = None,
private_key: Path | None = None,
password: str | None = None,
tor_socks: bool = False,
) -> "Remote":
"""
Parses an SSH URI into a Remote object.
The address can be in the form of:
- `ssh://[user@]hostname[:port]?option=value&option2=value2`
- `[user@]hostname[:port]`
The specification can be found here: https://www.ietf.org/archive/id/draft-salowey-secsh-uri-00.html
"""
if address.startswith("ssh://"):
# Strip the `ssh://` prefix if it exists
address = address[len("ssh://") :]
@@ -68,10 +69,6 @@ def parse_deployment_address(
address=hostname,
user=user,
port=port,
private_key=private_key,
password=password,
command_prefix=machine_name,
forward_agent=forward_agent,
ssh_options=options,
tor_socks=tor_socks,
)

View File

@@ -61,6 +61,8 @@ class Remote:
*,
host_key_check: HostKeyCheck | None = None,
private_key: Path | None = None,
password: str | None = None,
tor_socks: bool | None = None,
) -> "Remote":
"""
Returns a new Remote instance with the same data but with a different host_key_check.
@@ -71,14 +73,14 @@ class Remote:
command_prefix=self.command_prefix,
port=self.port,
private_key=private_key if private_key is not None else self.private_key,
password=self.password,
password=password if password is not None else self.password,
forward_agent=self.forward_agent,
host_key_check=host_key_check
if host_key_check is not None
else self.host_key_check,
verbose_ssh=self.verbose_ssh,
ssh_options=self.ssh_options,
tor_socks=self.tor_socks,
tor_socks=tor_socks if tor_socks is not None else self.tor_socks,
_control_path_dir=self._control_path_dir,
_askpass_path=self._askpass_path,
)
@@ -93,23 +95,12 @@ class Remote:
*,
machine_name: str,
address: str,
forward_agent: bool = True,
private_key: Path | None = None,
password: str | None = None,
tor_socks: bool = False,
) -> "Remote":
"""
Parse a deployment address and return a Host object.
"""
return parse_deployment_address(
machine_name=machine_name,
address=address,
forward_agent=forward_agent,
private_key=private_key,
password=password,
tor_socks=tor_socks,
)
return parse_deployment_address(machine_name=machine_name, address=address)
def run_local(
self,