From 47968ec94ee172f5ae8924f2bb3850142e77dcd3 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 7 Apr 2020 01:00:09 -0400 Subject: allow stopping the agent --- src/agent.rs | 1 + src/bin/agent.rs | 1 + src/bin/rbw.rs | 13 +++++++++++++ 3 files changed, 15 insertions(+) (limited to 'src') diff --git a/src/agent.rs b/src/agent.rs index c64acc9..1aec70c 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -14,6 +14,7 @@ pub enum Action { // add // update // remove + Quit, } #[derive(serde::Serialize, serde::Deserialize, Debug)] diff --git a/src/bin/agent.rs b/src/bin/agent.rs index 9081988..96de0c2 100644 --- a/src/bin/agent.rs +++ b/src/bin/agent.rs @@ -140,6 +140,7 @@ async fn handle_sock( rbw::agent::Action::Decrypt { cipherstring } => { decrypt(&mut sock, state.clone(), &cipherstring).await } + rbw::agent::Action::Quit => std::process::exit(0), } } diff --git a/src/bin/rbw.rs b/src/bin/rbw.rs index b309550..0cb9fe7 100644 --- a/src/bin/rbw.rs +++ b/src/bin/rbw.rs @@ -128,6 +128,17 @@ fn purge() { todo!() } +fn stop_agent() { + let mut sock = connect(); + send( + &mut sock, + &rbw::agent::Request { + tty: std::env::var("TTY").ok(), + action: rbw::agent::Action::Quit, + }, + ); +} + fn main() { let matches = clap::App::new("rbw") .about("unofficial bitwarden cli") @@ -144,6 +155,7 @@ fn main() { .subcommand(clap::SubCommand::with_name("remove")) .subcommand(clap::SubCommand::with_name("lock")) .subcommand(clap::SubCommand::with_name("purge")) + .subcommand(clap::SubCommand::with_name("stop-agent")) .get_matches(); ensure_agent(); @@ -160,6 +172,7 @@ fn main() { ("remove", Some(_)) => remove(), ("lock", Some(_)) => lock(), ("purge", Some(_)) => purge(), + ("stop-agent", Some(_)) => stop_agent(), _ => unimplemented!(), } } -- cgit v1.2.3-54-g00ecf