8dece7800f
Testing / remote-protocol-compat (0.9.3) (push) Successful in 52s
Testing / test (push) Successful in 1m2s
Testing / remote-protocol-compat (0.9.5) (push) Successful in 1m0s
Package Extension / package-extension (push) Successful in 1m11s
Build & Publish Package / publish (push) Successful in 1m7s
- Add browser source grouping metadata to SDK-created tabs, groups, list results, and aggregate count results. - Render grouped local/remote browser tables consistently for clients, tabs, groups, windows, sessions, and remote status output. - Document remote control, auth, HTTP gateway usage, and the refreshed project structure in the README. - Add coverage for grouped output and BrowserCounts browser_groups. - Bump the Python package, extension manifest, and lockfile to 0.15.6. - Add a just publish helper for building and publishing release artifacts.
79 lines
2.7 KiB
Python
79 lines
2.7 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
import click
|
|
from rich.console import Console
|
|
from rich.table import Table
|
|
|
|
from browser_cli import BrowserCLI
|
|
from browser_cli.commands import handle_errors
|
|
from browser_cli.commands.rendering import print_browser_grouped_table_rows
|
|
from browser_cli.remote.registry import REMOTE_REGISTRY_PATH, load_remotes, save_remote_key
|
|
|
|
console = Console()
|
|
|
|
@click.group("remote")
|
|
def remote_group():
|
|
"""Manage remembered browser-cli remote endpoints."""
|
|
|
|
@remote_group.command("status")
|
|
@click.argument("endpoint")
|
|
@click.option("--key", default=None, help="Key spec/path to use for this probe")
|
|
@handle_errors
|
|
def remote_status(endpoint, key):
|
|
"""Probe a remote endpoint and show server/client status."""
|
|
client = BrowserCLI(remote=endpoint, key=key)
|
|
clients = [
|
|
{**item, "profileLabel": item.get("profile", ""), "profileGroup": endpoint}
|
|
for item in client.clients()
|
|
]
|
|
columns = [
|
|
("Browser", lambda item: item.get("name", "")),
|
|
("Extension", lambda item: item.get("extensionVersion", "")),
|
|
]
|
|
print_browser_grouped_table_rows(
|
|
clients,
|
|
columns,
|
|
console=console,
|
|
empty_message="[yellow]No browser clients found[/yellow]",
|
|
browser_getter=lambda item: item.get("profileLabel", ""),
|
|
group_getter=lambda item: item.get("profileGroup", ""),
|
|
browser_header="Profile",
|
|
)
|
|
|
|
@remote_group.command("trust")
|
|
@click.argument("endpoint")
|
|
@click.argument("key_spec")
|
|
def remote_trust(endpoint, key_spec):
|
|
"""Remember which key spec to use for ENDPOINT."""
|
|
save_remote_key(endpoint, key_spec)
|
|
console.print(f"[green]Trusted remote {endpoint} with key {key_spec}[/green]")
|
|
|
|
@remote_group.command("keys")
|
|
def remote_keys():
|
|
"""List remembered remote key specs."""
|
|
remotes = load_remotes()
|
|
if not remotes:
|
|
console.print("[yellow]No remembered remotes[/yellow]")
|
|
return
|
|
table = Table(show_header=True, header_style="bold cyan")
|
|
table.add_column("Endpoint")
|
|
table.add_column("Key")
|
|
for endpoint, cfg in sorted(remotes.items()):
|
|
table.add_row(endpoint, str(cfg.get("key", "")))
|
|
console.print(table)
|
|
|
|
@remote_group.command("revoke")
|
|
@click.argument("endpoint")
|
|
def remote_revoke(endpoint):
|
|
"""Remove remembered key/config for ENDPOINT."""
|
|
remotes = load_remotes()
|
|
if endpoint not in remotes:
|
|
console.print(f"[yellow]Remote {endpoint} not remembered[/yellow]")
|
|
return
|
|
del remotes[endpoint]
|
|
REMOTE_REGISTRY_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
REMOTE_REGISTRY_PATH.write_text(json.dumps(remotes, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
console.print(f"[green]Revoked {endpoint}[/green]")
|