diff --git a/pkgs/clan-cli/clan_cli/machines/install.py b/pkgs/clan-cli/clan_cli/machines/install.py index 0196b7378..e3f682f02 100644 --- a/pkgs/clan-cli/clan_cli/machines/install.py +++ b/pkgs/clan-cli/clan_cli/machines/install.py @@ -194,7 +194,7 @@ def install_command(args: argparse.Namespace) -> None: host_key_check=host_key_check, ) else: - target_host = machine.target_host().with_data(host_key_check=host_key_check) + target_host = machine.target_host().override(host_key_check=host_key_check) if machine._class_ == "darwin": msg = "Installing macOS machines is not yet supported" diff --git a/pkgs/clan-cli/clan_lib/machines/machines.py b/pkgs/clan-cli/clan_lib/machines/machines.py index 0b5adf6ec..56e28d00e 100644 --- a/pkgs/clan-cli/clan_lib/machines/machines.py +++ b/pkgs/clan-cli/clan_lib/machines/machines.py @@ -32,7 +32,7 @@ class Machine: flake: Flake nix_options: list[str] = field(default_factory=list) - private_key: Path | None = None + host_key_check: HostKeyCheck = HostKeyCheck.STRICT def get_inv_machine(self) -> "InventoryMachine": @@ -149,18 +149,8 @@ class Machine: description="See https://docs.clan.lol/guides/getting-started/deploy/#setting-the-target-host for more information.", ) data = remote.data - return Remote( - address=data.address, - user=data.user, - command_prefix=data.command_prefix, - port=data.port, - private_key=self.private_key, - password=data.password, - forward_agent=data.forward_agent, + return data.override( host_key_check=self.host_key_check, - verbose_ssh=data.verbose_ssh, - ssh_options=data.ssh_options, - tor_socks=data.tor_socks, ) def build_host(self) -> Remote | None: @@ -172,18 +162,8 @@ class Machine: if remote: data = remote.data - return Remote( - address=data.address, - user=data.user, - command_prefix=data.command_prefix, - port=data.port, - private_key=self.private_key, - password=data.password, - forward_agent=data.forward_agent, + return data.override( host_key_check=self.host_key_check, - verbose_ssh=data.verbose_ssh, - ssh_options=data.ssh_options, - tor_socks=data.tor_socks, ) return None @@ -289,7 +269,6 @@ def get_host( machine_name=machine.name, address=host_str, host_key_check=machine.host_key_check, - private_key=machine.private_key, ), source=source, ) diff --git a/pkgs/clan-cli/clan_lib/ssh/remote.py b/pkgs/clan-cli/clan_lib/ssh/remote.py index f810310ed..e2d7d20e9 100644 --- a/pkgs/clan-cli/clan_lib/ssh/remote.py +++ b/pkgs/clan-cli/clan_lib/ssh/remote.py @@ -54,7 +54,12 @@ class Remote: except ValueError: return False - def with_data(self, host_key_check: HostKeyCheck | None = None) -> "Remote": + def override( + self, + *, + host_key_check: HostKeyCheck | None = None, + private_key: Path | None = None, + ) -> "Remote": """ Returns a new Remote instance with the same data but with a different host_key_check. """ @@ -63,7 +68,7 @@ class Remote: user=self.user, command_prefix=self.command_prefix, port=self.port, - private_key=self.private_key, + private_key=private_key if private_key is not None else self.private_key, password=self.password, forward_agent=self.forward_agent, host_key_check=host_key_check diff --git a/pkgs/clan-cli/clan_lib/tests/test_create.py b/pkgs/clan-cli/clan_lib/tests/test_create.py index 245eb0cf1..7d846ec2e 100644 --- a/pkgs/clan-cli/clan_lib/tests/test_create.py +++ b/pkgs/clan-cli/clan_lib/tests/test_create.py @@ -192,10 +192,7 @@ def test_clan_create_api( ) ) machine = Machine( - name=vm_name, - flake=clan_dir_flake, - host_key_check=HostKeyCheck.NONE, - private_key=private_key, + name=vm_name, flake=clan_dir_flake, host_key_check=HostKeyCheck.NONE ) machines.append(machine) assert len(machines) == 1 @@ -203,7 +200,8 @@ def test_clan_create_api( # Invalidate cache because of new machine creation clan_dir_flake.invalidate_cache() - result = check_machine_online(machine.target_host()) + target_host = machine.target_host().override(private_key=private_key) + result = check_machine_online(target_host) assert result == "Online", f"Machine {machine.name} is not online" ssh_keys = [