Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,27 @@ Tencent Cloud COS through the `cos-release` GitHub environment. It requires
`TENCENT_CLOUD_SECRET_ID` and `TENCENT_CLOUD_SECRET_KEY` secrets plus
`COS_BUCKET`, `COS_REGION`, `COS_PUBLIC_BASE_URL`, and `COS_OBJECT_PREFIX`
variables.

## OPS website login

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bump the release version before shipping OPS

The parent release already assigns version 1.3.0 to the local-tunnel feature, but this user-visible OPS addition leaves Cargo.toml, Cargo.lock, and both Skill bootstrap defaults at 1.3.0. A fresh version tag will fail the release workflow's version validation, while republishing v1.3.0 would replace previously versioned binaries and checksums, which the repository's release checklist explicitly forbids. Bump all four version locations together so OPS can be safely distributed and bootstrap clients install a binary that contains these commands.

Useful? React with 👍 / 👎.


Use a project API key and a project with an active OPS credential connection.
Choose the Chrome image configured for the target environment.

```sh
browser-cli ops connections
browser-cli ops items --connection-id CONNECTION --site-origin https://example.com
browser-cli ops session --custom-image-id IMAGE
browser-cli ops start --session-id SESSION --connection-id CONNECTION --site-origin https://example.com
browser-cli ops wait --task-id TASK
```

Add both `--vault-id` and `--item-id` to `ops start` when account selection is
required. To retry an explicit start after an uncertain response, use the same
`--idempotency-key`, session, connection, site, and item. Without a key, each
invocation starts a new login intent.

If the task state is `awaiting_user`, run `browser-cli ops verify --task-id TASK`,
complete verification in the browser, then run `browser-cli ops resume --task-id TASK`
and wait again. `ops get` reads the current state, and `ops cancel` requests
cancellation. Close the session with `browser-cli session close --session-id SESSION`
when you finish using it.
21 changes: 18 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,22 @@ impl ClientBuilder {
base_url,
region,
http,
ops_http: HttpClient::builder()
.timeout(self.timeout)
.redirect(reqwest::redirect::Policy::none())
.build()?,
})
}
}

#[derive(Debug, Clone)]
pub struct Client {
api_key: String,
pub(crate) api_key: String,
project_id: String,
base_url: String,
region: Option<String>,
http: HttpClient,
pub(crate) ops_http: HttpClient,
}

impl Client {
Expand All @@ -123,7 +128,7 @@ impl Client {
&self.base_url
}

fn body_with_region(&self, mut body: Value) -> Value {
pub(crate) fn body_with_region(&self, mut body: Value) -> Value {
if let (Some(region), Some(object)) = (&self.region, body.as_object_mut()) {
object.insert("region_id".into(), Value::String(region.clone()));
}
Expand Down Expand Up @@ -259,6 +264,15 @@ impl Client {
if let Some(region) = region {
body["region_id"] = region["region_id"].clone();
}
self.create_session_from_body(body, poll_timeout, true)
}

pub(crate) fn create_session_from_body(
&self,
body: Value,
poll_timeout: Duration,
hydrate: bool,
) -> Result<Session> {
let accepted: Value = self.json(Method::POST, "/instance/v2", Some(body))?;
let session_id = accepted
.get("session_id")
Expand All @@ -272,7 +286,8 @@ impl Client {
loop {
let session = self.get_session(session_id)?;
match session.status.as_str() {
"active" => return self.hydrate_ws(session),
"active" if hydrate => return self.hydrate_ws(session),
"active" => return Ok(session),
"create_failed" => {
return Err(Error::Api {
status: 500,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod cdp;
pub mod client;
pub mod error;
pub mod models;
pub mod ops;
pub mod tunnels;

pub use client::{Client, ClientBuilder};
Expand Down
160 changes: 160 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use lexmount_browser::{
Client, Error, Result, auth,
cdp::{Cdp, WaitTextOptions},
models::CreateSession,
ops::{CreateLogin, LoginItemRef},
};
use serde_json::{Value, json};

Expand Down Expand Up @@ -41,6 +42,11 @@ enum Command {
#[command(subcommand)]
command: SessionCommand,
},
/// Start and manage OPS website login tasks.
Ops {
#[command(subcommand)]
command: OpsCommand,
},
Context {
#[command(subcommand)]
command: ContextCommand,
Expand Down Expand Up @@ -130,6 +136,74 @@ enum SessionCommand {
},
}

#[derive(Subcommand)]
enum OpsCommand {
/// Create a fresh OPS Chrome session using an explicit image.
Session {
#[arg(long)]
custom_image_id: String,
#[arg(long, default_value_t = 85)]
timeout_seconds: u64,
},
/// List credential connections for the project.
Connections {
#[command(flatten)]
page: OpsPage,
},
/// List credential items matching a website origin.
Items {
#[arg(long)]
connection_id: String,
#[arg(long)]
site_origin: String,
#[command(flatten)]
page: OpsPage,
},
/// Start a login using the only match or an explicitly selected item.
Start {
#[arg(long)]
session_id: String,
#[arg(long)]
connection_id: String,
#[arg(long)]
site_origin: String,
#[arg(long, requires = "item_id")]
vault_id: Option<String>,
#[arg(long, requires = "vault_id")]
item_id: Option<String>,
/// Retry a start request with the same key and explicit item.
#[arg(long, requires_all = ["vault_id", "item_id"])]
idempotency_key: Option<String>,
},
Get(OpsTask),
/// Wait for completion or a request for manual verification.
Wait {
#[command(flatten)]
task: OpsTask,
#[arg(long, default_value_t = 120)]
timeout_seconds: u64,
},
/// Open the manual verification page.
Verify(OpsTask),
/// Resume after completing manual verification in the browser.
Resume(OpsTask),
Cancel(OpsTask),
}

#[derive(Args)]
struct OpsPage {
#[arg(long)]
cursor: Option<String>,
#[arg(long, default_value_t = 50)]
limit: u8,
}

#[derive(Args)]
struct OpsTask {
#[arg(long)]
task_id: String,
}

#[derive(Subcommand)]
enum DownloadsCommand {
List {
Expand Down Expand Up @@ -408,6 +482,7 @@ fn run(cli: Cli) -> Result<Value> {
}
}
Command::Session { command } => run_session(Client::from_env()?, command),
Command::Ops { command } => run_ops(Client::from_env()?, command),
Command::Context { command } => run_context(Client::from_env()?, command),
Command::Action { command, target_id } => {
run_action(Client::from_env()?, command, target_id.as_deref())
Expand Down Expand Up @@ -549,6 +624,91 @@ fn run_session(client: Client, command: SessionCommand) -> Result<Value> {
}
}

fn run_ops(client: Client, command: OpsCommand) -> Result<Value> {
let task = match command {
OpsCommand::Session {
custom_image_id,
timeout_seconds,
} => {
let session = client
.create_ops_session(&custom_image_id, Duration::from_secs(timeout_seconds))?;
return Ok(json!({
"session_id": session.session_id,
"status": session.status,
"region_id": session.region_id,
"requested_image": custom_image_id,
}));
}
OpsCommand::Connections { page } => {
return Ok(serde_json::to_value(client.list_credential_connections(
page.cursor.as_deref(),
page.limit,
)?)?);
}
OpsCommand::Items {
connection_id,
site_origin,
page,
} => {
return Ok(serde_json::to_value(client.list_login_items(
&connection_id,
&site_origin,
page.cursor.as_deref(),
page.limit,
)?)?);
}
OpsCommand::Start {
session_id,
connection_id,
site_origin,
vault_id,
item_id,
idempotency_key,
} => client.create_login_task(CreateLogin {
session_id: &session_id,
connection_id: &connection_id,
site_origin: &site_origin,
item: vault_id
.zip(item_id)
.map(|(vault_id, item_id)| LoginItemRef { vault_id, item_id }),
idempotency_key: idempotency_key.as_deref(),
})?,
OpsCommand::Get(task) => client.get_login_task(&task.task_id)?,
OpsCommand::Wait {
task,
timeout_seconds,
} => client.wait_for_login_task(&task.task_id, Duration::from_secs(timeout_seconds))?,
OpsCommand::Verify(task) => {
let task = client.get_login_task(&task.task_id)?;
let url = task
.requires_action
.as_ref()
.filter(|action| {
task.state == "awaiting_user"
&& !task.cancel_requested
&& action.kind == "manual_verification"
})
.and_then(|action| action.open_url.as_deref())
.and_then(|url| url::Url::parse(url).ok())
.filter(|url| {
url.scheme() == "https"
&& url.host().is_some()
&& url.username().is_empty()
&& url.password().is_none()
})
.ok_or_else(|| {
Error::Config("OPS task has no available manual verification page".into())
})?;
open::that(url.as_str())
.map_err(|_| Error::Config("could not open OPS verification page".into()))?;
task
}
OpsCommand::Resume(task) => client.resume_login_task(&task.task_id)?,
OpsCommand::Cancel(task) => client.cancel_login_task(&task.task_id)?,
};
Ok(serde_json::to_value(task)?)
}

fn run_context(client: Client, command: ContextCommand) -> Result<Value> {
match command {
ContextCommand::Create {
Expand Down
Loading
Loading