clan-cli: Simplify HostKeyCheck to a Literal instead of an Enum
This commit is contained in:
@@ -15,13 +15,12 @@ from shlex import quote
|
||||
from tempfile import TemporaryDirectory
|
||||
from typing import Literal
|
||||
|
||||
from clan_cli.ssh.host_key import HostKeyCheck
|
||||
|
||||
from clan_lib.api import API
|
||||
from clan_lib.cmd import ClanCmdError, ClanCmdTimeoutError, CmdOut, RunOpts, run
|
||||
from clan_lib.colors import AnsiColor
|
||||
from clan_lib.errors import ClanError # Assuming these are available
|
||||
from clan_lib.nix import nix_shell
|
||||
from clan_lib.ssh.host_key import HostKeyCheck, hostkey_to_ssh_opts
|
||||
from clan_lib.ssh.parse import parse_deployment_address
|
||||
from clan_lib.ssh.sudo_askpass_proxy import SudoAskpassProxy
|
||||
|
||||
@@ -40,7 +39,7 @@ class Remote:
|
||||
private_key: Path | None = None
|
||||
password: str | None = None
|
||||
forward_agent: bool = True
|
||||
host_key_check: HostKeyCheck = HostKeyCheck.ASK
|
||||
host_key_check: HostKeyCheck = "ask"
|
||||
verbose_ssh: bool = False
|
||||
ssh_options: dict[str, str] = field(default_factory=dict)
|
||||
tor_socks: bool = False
|
||||
@@ -334,7 +333,7 @@ class Remote:
|
||||
ssh_opts.extend(["-p", str(self.port)])
|
||||
for k, v in self.ssh_options.items():
|
||||
ssh_opts.extend(["-o", f"{k}={shlex.quote(v)}"])
|
||||
ssh_opts.extend(self.host_key_check.to_ssh_opt())
|
||||
ssh_opts.extend(hostkey_to_ssh_opts(self.host_key_check))
|
||||
if self.private_key:
|
||||
ssh_opts.extend(["-i", str(self.private_key)])
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ from collections.abc import Generator
|
||||
from typing import Any, NamedTuple
|
||||
|
||||
import pytest
|
||||
from clan_cli.ssh.host_key import HostKeyCheck
|
||||
|
||||
from clan_lib.async_run import AsyncRuntime
|
||||
from clan_lib.cmd import ClanCmdTimeoutError, Log, RunOpts
|
||||
@@ -114,7 +113,7 @@ def test_parse_deployment_address(
|
||||
result = Remote.from_deployment_address(
|
||||
machine_name=machine_name,
|
||||
address=test_addr,
|
||||
).override(host_key_check=HostKeyCheck.STRICT)
|
||||
).override(host_key_check="strict")
|
||||
|
||||
if expected_exception:
|
||||
return
|
||||
@@ -132,7 +131,7 @@ 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).override(
|
||||
host_key_check=HostKeyCheck.STRICT
|
||||
host_key_check="strict"
|
||||
)
|
||||
assert host.address == "example.com"
|
||||
assert host.port == 2222
|
||||
|
||||
@@ -13,7 +13,6 @@ from clan_cli.machines.create import create_machine
|
||||
from clan_cli.secrets.key import generate_key
|
||||
from clan_cli.secrets.sops import maybe_get_admin_public_keys
|
||||
from clan_cli.secrets.users import add_user
|
||||
from clan_cli.ssh.host_key import HostKeyCheck
|
||||
from clan_cli.vars.generate import generate_vars_for_machine, get_generators_closure
|
||||
|
||||
from clan_lib.api.disk import hw_main_disk_options, set_machine_disk_schema
|
||||
@@ -198,7 +197,7 @@ def test_clan_create_api(
|
||||
clan_dir_flake.invalidate_cache()
|
||||
|
||||
target_host = machine.target_host().override(
|
||||
private_key=private_key, host_key_check=HostKeyCheck.NONE
|
||||
private_key=private_key, host_key_check="none"
|
||||
)
|
||||
result = can_ssh_login(target_host)
|
||||
assert result == "Online", f"Machine {machine.name} is not online"
|
||||
|
||||
Reference in New Issue
Block a user