diff --git a/pkgs/clan-cli/clan_cli/ssh/cli.py b/pkgs/clan-cli/clan_cli/ssh/cli.py index 9288ca0d5..491afb44c 100644 --- a/pkgs/clan-cli/clan_cli/ssh/cli.py +++ b/pkgs/clan-cli/clan_cli/ssh/cli.py @@ -3,6 +3,7 @@ import json import logging import socket import subprocess +from pathlib import Path from ..nix import nix_shell @@ -84,21 +85,24 @@ def is_reachable(host: str) -> bool: def connect_ssh_from_json(ssh_data: dict[str, str]) -> None: - for address in ssh_data["addrs"]: + for address in ssh_data["local_addresses"]: log.debug(f"Trying to reach host on: {address}") if is_reachable(address): - ssh(host=address, password=ssh_data["pass"]) + ssh(host=address, password=ssh_data["password"]) exit(0) else: log.debug(f"Could not reach host on {address}") log.debug(f'Trying to reach host via torify on {ssh_data["tor"]}') - ssh(host=ssh_data["tor"], password=ssh_data["pass"], torify=True) + ssh(host=ssh_data["tor"], password=ssh_data["password"], torify=True) def main(args: argparse.Namespace) -> None: if args.json: - with open(args.json) as file: - ssh_data = json.load(file) + json_file = Path(args.json) + if json_file.is_file(): + ssh_data = json.loads(json_file.read_text()) + else: + ssh_data = json.loads(args.json) connect_ssh_from_json(ssh_data) elif args.png: ssh_data = json.loads(qrcode_scan(args.png))