From fae4d39a109ecd0db6bf03f8f51dfc97eb6e4b11 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Thu, 19 Jun 2025 17:55:56 +0200 Subject: [PATCH] clan-lib: machines.py: Remove host_key attribute --- pkgs/clan-cli/clan_cli/machines/hardware.py | 14 ++++---------- pkgs/clan-cli/clan_cli/machines/install.py | 6 ++---- pkgs/clan-cli/clan_cli/machines/update.py | 8 ++------ pkgs/clan-cli/clan_cli/ssh/deploy_info.py | 12 ++++-------- pkgs/clan-cli/clan_lib/machines/machines.py | 15 +++------------ pkgs/clan-cli/clan_lib/ssh/parse.py | 4 ---- pkgs/clan-cli/clan_lib/ssh/remote.py | 2 -- pkgs/clan-cli/clan_lib/ssh/remote_test.py | 7 +++---- pkgs/clan-cli/clan_lib/tests/test_create.py | 8 ++++---- 9 files changed, 22 insertions(+), 54 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index a4a6fa3f7..4815f46f0 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -159,11 +159,7 @@ def generate_machine_hardware_info( def update_hardware_config_command(args: argparse.Namespace) -> None: host_key_check = HostKeyCheck.from_str(args.host_key_check) - machine = Machine( - flake=args.flake, - name=args.machine, - host_key_check=host_key_check, - ) + machine = Machine(flake=args.flake, name=args.machine) opts = HardwareGenerateOptions( machine=machine, password=args.password, @@ -172,12 +168,10 @@ def update_hardware_config_command(args: argparse.Namespace) -> None: if args.target_host: target_host = Remote.from_deployment_address( - machine_name=machine.name, - address=args.target_host, - host_key_check=host_key_check, - ) + machine_name=machine.name, address=args.target_host + ).override(host_key_check=host_key_check) else: - target_host = machine.target_host() + target_host = machine.target_host().override(host_key_check=host_key_check) generate_machine_hardware_info(opts, target_host) diff --git a/pkgs/clan-cli/clan_cli/machines/install.py b/pkgs/clan-cli/clan_cli/machines/install.py index e3f682f02..d54e58f1e 100644 --- a/pkgs/clan-cli/clan_cli/machines/install.py +++ b/pkgs/clan-cli/clan_cli/machines/install.py @@ -189,10 +189,8 @@ def install_command(args: argparse.Namespace) -> None: ) if target_host_str is not None: target_host = Remote.from_deployment_address( - machine_name=machine.name, - address=target_host_str, - host_key_check=host_key_check, - ) + machine_name=machine.name, address=target_host_str + ).override(host_key_check=host_key_check) else: target_host = machine.target_host().override(host_key_check=host_key_check) diff --git a/pkgs/clan-cli/clan_cli/machines/update.py b/pkgs/clan-cli/clan_cli/machines/update.py index 9965fb77f..23d4d9bb2 100644 --- a/pkgs/clan-cli/clan_cli/machines/update.py +++ b/pkgs/clan-cli/clan_cli/machines/update.py @@ -220,10 +220,7 @@ def update_command(args: argparse.Namespace) -> None: for machine_name in selected_machines: machine = Machine( - name=machine_name, - flake=args.flake, - nix_options=args.option, - host_key_check=HostKeyCheck.from_str(args.host_key_check), + name=machine_name, flake=args.flake, nix_options=args.option ) machines.append(machine) @@ -281,8 +278,7 @@ def update_command(args: argparse.Namespace) -> None: target_host = Remote.from_deployment_address( machine_name=machine.name, address=args.target_host, - host_key_check=host_key_check, - ) + ).override(host_key_check=host_key_check) else: target_host = machine.target_host() runtime.async_run( diff --git a/pkgs/clan-cli/clan_cli/ssh/deploy_info.py b/pkgs/clan-cli/clan_cli/ssh/deploy_info.py index fdb94945f..12e96a9e2 100644 --- a/pkgs/clan-cli/clan_cli/ssh/deploy_info.py +++ b/pkgs/clan-cli/clan_cli/ssh/deploy_info.py @@ -47,10 +47,8 @@ class DeployInfo: msg = "Hostname cannot be empty." raise ClanError(msg) remote = Remote.from_deployment_address( - machine_name="clan-installer", - address=host, - host_key_check=host_key_check, - ) + machine_name="clan-installer", address=host + ).override(host_key_check=host_key_check) remotes.append(remote) return DeployInfo(addrs=remotes) @@ -64,9 +62,8 @@ class DeployInfo: remote = Remote.from_deployment_address( machine_name="clan-installer", address=addr, - host_key_check=host_key_check, password=password, - ) + ).override(host_key_check=host_key_check) addrs.append(remote) else: msg = f"Invalid address format: {addr}" @@ -75,10 +72,9 @@ class DeployInfo: remote = Remote.from_deployment_address( machine_name="clan-installer", address=tor_addr, - host_key_check=host_key_check, password=password, tor_socks=True, - ) + ).override(host_key_check=host_key_check) addrs.append(remote) return DeployInfo(addrs=addrs) diff --git a/pkgs/clan-cli/clan_lib/machines/machines.py b/pkgs/clan-cli/clan_lib/machines/machines.py index 56e28d00e..4d3148370 100644 --- a/pkgs/clan-cli/clan_lib/machines/machines.py +++ b/pkgs/clan-cli/clan_lib/machines/machines.py @@ -9,7 +9,6 @@ from typing import TYPE_CHECKING, Any, Literal from clan_cli.facts import public_modules as facts_public_modules from clan_cli.facts import secret_modules as facts_secret_modules -from clan_cli.ssh.host_key import HostKeyCheck from clan_cli.vars._types import StoreBase from clan_lib.api import API @@ -33,8 +32,6 @@ class Machine: nix_options: list[str] = field(default_factory=list) - host_key_check: HostKeyCheck = HostKeyCheck.STRICT - def get_inv_machine(self) -> "InventoryMachine": return get_machine(self.flake, self.name) @@ -149,9 +146,7 @@ class Machine: description="See https://docs.clan.lol/guides/getting-started/deploy/#setting-the-target-host for more information.", ) data = remote.data - return data.override( - host_key_check=self.host_key_check, - ) + return data def build_host(self) -> Remote | None: """ @@ -162,9 +157,7 @@ class Machine: if remote: data = remote.data - return data.override( - host_key_check=self.host_key_check, - ) + return data return None @@ -266,9 +259,7 @@ def get_host( return RemoteSource( data=Remote.from_deployment_address( - machine_name=machine.name, - address=host_str, - host_key_check=machine.host_key_check, + machine_name=machine.name, address=host_str ), source=source, ) diff --git a/pkgs/clan-cli/clan_lib/ssh/parse.py b/pkgs/clan-cli/clan_lib/ssh/parse.py index 928763117..3f6867e6a 100644 --- a/pkgs/clan-cli/clan_lib/ssh/parse.py +++ b/pkgs/clan-cli/clan_lib/ssh/parse.py @@ -3,8 +3,6 @@ import urllib.parse from pathlib import Path from typing import TYPE_CHECKING, Any -from clan_cli.ssh.host_key import HostKeyCheck - from clan_lib.errors import ClanError if TYPE_CHECKING: @@ -15,7 +13,6 @@ def parse_deployment_address( *, machine_name: str, address: str, - host_key_check: HostKeyCheck, forward_agent: bool = True, meta: dict[str, Any] | None = None, private_key: Path | None = None, @@ -73,7 +70,6 @@ def parse_deployment_address( port=port, private_key=private_key, password=password, - host_key_check=host_key_check, command_prefix=machine_name, forward_agent=forward_agent, ssh_options=options, diff --git a/pkgs/clan-cli/clan_lib/ssh/remote.py b/pkgs/clan-cli/clan_lib/ssh/remote.py index e2d7d20e9..8c73dbdc8 100644 --- a/pkgs/clan-cli/clan_lib/ssh/remote.py +++ b/pkgs/clan-cli/clan_lib/ssh/remote.py @@ -91,7 +91,6 @@ class Remote: *, machine_name: str, address: str, - host_key_check: HostKeyCheck, forward_agent: bool = True, private_key: Path | None = None, password: str | None = None, @@ -104,7 +103,6 @@ class Remote: return parse_deployment_address( machine_name=machine_name, address=address, - host_key_check=host_key_check, forward_agent=forward_agent, private_key=private_key, password=password, diff --git a/pkgs/clan-cli/clan_lib/ssh/remote_test.py b/pkgs/clan-cli/clan_lib/ssh/remote_test.py index 04441f3a6..34baa952e 100644 --- a/pkgs/clan-cli/clan_lib/ssh/remote_test.py +++ b/pkgs/clan-cli/clan_lib/ssh/remote_test.py @@ -114,8 +114,7 @@ def test_parse_deployment_address( result = Remote.from_deployment_address( machine_name=machine_name, address=test_addr, - host_key_check=HostKeyCheck.STRICT, - ) + ).override(host_key_check=HostKeyCheck.STRICT) if expected_exception: return @@ -132,8 +131,8 @@ def test_parse_deployment_address( def test_parse_ssh_options() -> None: addr = "root@example.com:2222?IdentityFile=/path/to/private/key&StrictRemoteKeyChecking=yes" - host = Remote.from_deployment_address( - machine_name="foo", address=addr, host_key_check=HostKeyCheck.STRICT + host = Remote.from_deployment_address(machine_name="foo", address=addr).override( + host_key_check=HostKeyCheck.STRICT ) assert host.address == "example.com" assert host.port == 2222 diff --git a/pkgs/clan-cli/clan_lib/tests/test_create.py b/pkgs/clan-cli/clan_lib/tests/test_create.py index 7d846ec2e..4c8b7fd0c 100644 --- a/pkgs/clan-cli/clan_lib/tests/test_create.py +++ b/pkgs/clan-cli/clan_lib/tests/test_create.py @@ -191,16 +191,16 @@ def test_clan_create_api( clan_dir_flake, inv_machine, target_host=f"{host.target}:{ssh_port_var}" ) ) - machine = Machine( - name=vm_name, flake=clan_dir_flake, host_key_check=HostKeyCheck.NONE - ) + machine = Machine(name=vm_name, flake=clan_dir_flake) machines.append(machine) assert len(machines) == 1 # Invalidate cache because of new machine creation clan_dir_flake.invalidate_cache() - target_host = machine.target_host().override(private_key=private_key) + target_host = machine.target_host().override( + private_key=private_key, host_key_check=HostKeyCheck.NONE + ) result = check_machine_online(target_host) assert result == "Online", f"Machine {machine.name} is not online"