fixes and improvements
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user