fix(remote): resolve remembered explicit-port endpoints
- Resolve bare remote hosts through the remote registry when one explicit port is stored. - Preserve bare host behavior when no unique explicit-port registry match exists. - Route requested remote targets through the new registry resolver. - Add registry tests for unique and ambiguous explicit-port matches. - Bump package and extension versions to 0.16.6.
This commit is contained in:
@@ -5,8 +5,8 @@ import uuid
|
||||
from typing import Any
|
||||
|
||||
from browser_cli import transport
|
||||
from browser_cli.endpoints import _normalize_endpoint
|
||||
from browser_cli.errors import BrowserNotConnected
|
||||
from browser_cli.remote.registry import resolve_remote_endpoint
|
||||
|
||||
def base_message(command: str, args: dict | None) -> dict:
|
||||
return {"id": str(uuid.uuid4()), "command": command, "args": args or {}}
|
||||
@@ -14,7 +14,7 @@ def base_message(command: str, args: dict | None) -> dict:
|
||||
def requested_target(profile: str | None, remote: str | None) -> tuple[str | None, str | None]:
|
||||
requested_profile = profile or os.environ.get("BROWSER_CLI_PROFILE")
|
||||
remote_endpoint = remote or os.environ.get("BROWSER_CLI_REMOTE")
|
||||
return requested_profile, _normalize_endpoint(remote_endpoint) if remote_endpoint else None
|
||||
return requested_profile, resolve_remote_endpoint(remote_endpoint) if remote_endpoint else None
|
||||
|
||||
def encode_payload(msg: dict) -> bytes:
|
||||
return json.dumps(msg).encode("utf-8")
|
||||
|
||||
@@ -22,6 +22,32 @@ def load_remotes() -> dict[str, dict[str, str]]:
|
||||
# Normalize keys so old entries stored as "domain:443" match current lookups.
|
||||
return {_normalize_endpoint(str(endpoint)): cfg for endpoint, cfg in data.items() if isinstance(cfg, dict)}
|
||||
|
||||
def resolve_remote_endpoint(endpoint: str | None) -> str | None:
|
||||
"""Resolve a user-supplied remote alias to a remembered endpoint.
|
||||
|
||||
Domain-like remotes without an explicit port still default to :443 when no
|
||||
matching remembered remote exists. If the user remembered exactly one
|
||||
explicit-port remote for the same host (for example
|
||||
``browser-host.example:8765``), use that endpoint so ``--remote
|
||||
browser-host.example`` targets the stored service instead of assuming HTTPS.
|
||||
"""
|
||||
if not endpoint:
|
||||
return None
|
||||
normalized = _normalize_endpoint(endpoint)
|
||||
host, sep, _port = normalized.rpartition(":")
|
||||
if sep:
|
||||
return normalized
|
||||
|
||||
remotes = load_remotes()
|
||||
explicit_matches = []
|
||||
for remote_endpoint in remotes:
|
||||
remote_host, remote_sep, remote_port = remote_endpoint.rpartition(":")
|
||||
if remote_sep and remote_host == normalized and remote_port != "443":
|
||||
explicit_matches.append(remote_endpoint)
|
||||
if len(explicit_matches) == 1:
|
||||
return explicit_matches[0]
|
||||
return normalized
|
||||
|
||||
def is_valid_key_spec(value: str) -> bool:
|
||||
"""Return True for 'agent', 'agent:<selector>', or a plausible key file path."""
|
||||
return value == "agent" or value.startswith("agent:") or (
|
||||
|
||||
Reference in New Issue
Block a user