Skip to content

Commit

Permalink
fix(vpn): fix connect command with --update-hosts flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitrgadiya committed Jan 24, 2025
1 parent a2c6c2c commit 9b882b4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions riocli/vpn/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from munch import Munch
from python_hosts import Hosts, HostsEntry

from riocli.config import get_config_from_context, new_client
from riocli.config import get_config_from_context, new_client, new_v2_client
from riocli.constants import Colors, Symbols
from riocli.utils import run_bash, run_bash_with_return_code
from riocli.v2client import Client as v2Client
Expand Down Expand Up @@ -223,13 +223,14 @@ def update_hosts_file():
and creates an entry in the system's hosts file.
"""
v1_client = new_client(with_project=True)
v2_client = new_v2_client(with_project=True)

device_host_to_name = {}
for device in v1_client.get_all_devices(online_device=True):
vpn = device.get("daemons_status").get("vpn")
if vpn and vpn.get("enable") and vpn.get("status") == "running":
d = v1_client.get_device(device.uuid)
device_host_to_name[d.get("host")] = d.name
device_daemon = v2_client.get_device_daemons(device_guid=device.get("uuid"))
vpn_status = device_daemon.status.get("vpn")
if vpn_status is not None and vpn_status.get("enable", False) and vpn_status.get("status") == "running":
device_host_to_name[device.get("host")] = device.name

status = get_tailscale_status()
peers = status.get("Peer", {})
Expand Down

0 comments on commit 9b882b4

Please sign in to comment.