fixes and improvements

This commit is contained in:
2026-05-07 20:36:37 +02:00
parent 420dc34272
commit c73cfa27c3
4 changed files with 51 additions and 22 deletions
@@ -41,6 +41,16 @@ def _fetch_server_key(host: str, port: int, timeout: int = 30) -> paramiko.PKey:
sock.close()
def has_known_host(host: str, port: int, known_hosts_path: Path) -> bool:
"""Return whether the given host/port is already present in known_hosts."""
if not host or not known_hosts_path.exists():
return False
host_alias = _host_alias(host, port)
host_keys = paramiko.HostKeys()
host_keys.load(str(known_hosts_path))
return host_keys.lookup(host_alias) is not None
def ensure_known_host(host: str, port: int, known_hosts_path: Path, *, strict: bool = True) -> bool:
"""Ensure a host key entry exists for the given host/port.