1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Browser bridge CLI commands.
pub(crate) mod bridge;
pub(crate) mod harvest;
pub(crate) mod request;
use std::path::Path;
use anyhow::Result;
use clap::{Parser, Subcommand};
use crate::browser::auth;
/// Resolves a thin-client session token for `request` / `harvest`.
///
/// Tries `--token-file` then `OMNI_BRIDGE_TOKEN` (via
/// [`auth::resolve_existing_token`]); if neither is set, falls back to the
/// daemon-written token file ([`crate::daemon::paths::token_path`]) when it
/// exists, so clients work transparently against a daemon-hosted bridge. The
/// original "no token" error is preserved when nothing resolves.
pub(crate) fn resolve_client_token(token_file: Option<&Path>) -> Result<String> {
match auth::resolve_existing_token(token_file) {
Ok(token) => Ok(token),
Err(e) => {
if token_file.is_none() {
if let Ok(path) = crate::daemon::paths::token_path() {
if path.exists() {
return auth::resolve_existing_token(Some(&path));
}
}
}
Err(e)
}
}
}
/// Browser bridge: drive authenticated requests through a browser tab.
#[derive(Parser)]
pub struct BrowserCommand {
/// The browser subcommand to execute.
#[command(subcommand)]
pub command: BrowserSubcommands,
}
/// Browser subcommands.
#[derive(Subcommand)]
pub enum BrowserSubcommands {
/// Bridge: run the server (`serve`) or send a request through it (`request`).
Bridge(bridge::BridgeCommand),
}
impl BrowserCommand {
/// Executes the browser command.
pub async fn execute(self) -> Result<()> {
match self.command {
BrowserSubcommands::Bridge(cmd) => cmd.execute().await,
}
}
}