diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-14 23:00:15 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-15 12:45:54 -0500 |
commit | acd1173848b4db1c733af7d3f53d24aab900b542 (patch) | |
tree | b0a1151e390c6063169325bc4520d7b79ac50d9e /src/bin/rbw-agent | |
parent | cc20037ff21a259419c7c00f6fce82ded3888d1e (diff) | |
download | rbw-acd1173848b4db1c733af7d3f53d24aab900b542.tar.gz rbw-acd1173848b4db1c733af7d3f53d24aab900b542.zip |
clippy
Diffstat (limited to 'src/bin/rbw-agent')
-rw-r--r-- | src/bin/rbw-agent/actions.rs | 46 | ||||
-rw-r--r-- | src/bin/rbw-agent/agent.rs | 10 | ||||
-rw-r--r-- | src/bin/rbw-agent/main.rs | 19 | ||||
-rw-r--r-- | src/bin/rbw-agent/sock.rs | 2 |
4 files changed, 37 insertions, 40 deletions
diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs index 1cc71c3..87a8276 100644 --- a/src/bin/rbw-agent/actions.rs +++ b/src/bin/rbw-agent/actions.rs @@ -61,10 +61,9 @@ pub async fn register( message, }) .context("failed to log in to bitwarden instance"); - } else { - err_msg = Some(message); - continue; } + err_msg = Some(message); + continue; } Err(e) => { return Err(e) @@ -172,9 +171,8 @@ pub async fn login( ) .await?; break; - } else { - return Err(anyhow::anyhow!("TODO")); } + return Err(anyhow::anyhow!("TODO")); } Err(rbw::error::Error::IncorrectPassword { message }) => { if i == 3 { @@ -182,10 +180,9 @@ pub async fn login( message, }) .context("failed to log in to bitwarden instance"); - } else { - err_msg = Some(message); - continue; } + err_msg = Some(message); + continue; } Err(e) => { return Err(e) @@ -249,10 +246,9 @@ async fn two_factor( message, }) .context("failed to log in to bitwarden instance"); - } else { - err_msg = Some(message); - continue; } + err_msg = Some(message); + continue; } // can get this if the user passes an empty string Err(rbw::error::Error::TwoFactorRequired { .. }) => { @@ -262,10 +258,9 @@ async fn two_factor( message, }) .context("failed to log in to bitwarden instance"); - } else { - err_msg = Some(message); - continue; } + err_msg = Some(message); + continue; } Err(e) => { return Err(e) @@ -313,8 +308,7 @@ async fn login_success( &protected_key, &protected_private_key, &db.protected_org_keys, - ) - .await; + ); match res { Ok((keys, org_keys)) => { @@ -362,7 +356,7 @@ pub async fn unlock( let email = config_email().await?; let mut err_msg = None; - for i in 1u8..=3 { + for i in 1_u8..=3 { let err = if i > 1 { // this unwrap is safe because we only ever continue the loop // if we have set err_msg @@ -387,9 +381,7 @@ pub async fn unlock( &protected_key, &protected_private_key, &db.protected_org_keys, - ) - .await - { + ) { Ok((keys, org_keys)) => { unlock_success(state, keys, org_keys).await?; break; @@ -400,10 +392,9 @@ pub async fn unlock( message, }) .context("failed to unlock database"); - } else { - err_msg = Some(message); - continue; } + err_msg = Some(message); + continue; } Err(e) => return Err(e).context("failed to unlock database"), } @@ -579,11 +570,10 @@ async fn respond_encrypt( async fn config_email() -> anyhow::Result<String> { let config = rbw::config::Config::load_async().await?; - if let Some(email) = config.email { - Ok(email) - } else { - Err(anyhow::anyhow!("failed to find email address in config")) - } + config.email.map_or_else( + || Err(anyhow::anyhow!("failed to find email address in config")), + Ok, + ) } async fn load_db() -> anyhow::Result<rbw::db::Db> { diff --git a/src/bin/rbw-agent/agent.rs b/src/bin/rbw-agent/agent.rs index fae8c7b..d64bf21 100644 --- a/src/bin/rbw-agent/agent.rs +++ b/src/bin/rbw-agent/agent.rs @@ -32,7 +32,7 @@ impl State { pub fn clear(&mut self) { self.priv_key = None; - self.org_keys = Default::default(); + self.org_keys = None; // no real better option to unwrap here self.timeout_chan.send(TimeoutEvent::Clear).unwrap(); } @@ -57,7 +57,7 @@ impl Agent { timeout_chan: r, state: std::sync::Arc::new(tokio::sync::RwLock::new(State { priv_key: None, - org_keys: Default::default(), + org_keys: None, timeout_chan: w, })), }) @@ -81,11 +81,7 @@ impl Agent { tokio::time::Duration::from_secs(60 * 60 * 24 * 365 * 2), )); loop { - let timeout = if let Some(timeout) = &mut self.timeout { - timeout - } else { - &mut forever - }; + let timeout = self.timeout.as_mut().unwrap_or(&mut forever); tokio::select! { sock = listener.accept() => { let mut sock = crate::sock::Sock::new( diff --git a/src/bin/rbw-agent/main.rs b/src/bin/rbw-agent/main.rs index 69411ae..f5d478d 100644 --- a/src/bin/rbw-agent/main.rs +++ b/src/bin/rbw-agent/main.rs @@ -1,4 +1,15 @@ +#![warn(clippy::cargo)] +#![warn(clippy::pedantic)] +#![warn(clippy::nursery)] +#![warn(clippy::as_conversions)] +#![warn(clippy::get_unwrap)] +#![allow(clippy::cognitive_complexity)] +#![allow(clippy::missing_const_for_fn)] +#![allow(clippy::similar_names)] +#![allow(clippy::struct_excessive_bools)] #![allow(clippy::too_many_arguments)] +#![allow(clippy::too_many_lines)] +#![allow(clippy::type_complexity)] use anyhow::Context as _; @@ -29,11 +40,9 @@ fn real_main() -> anyhow::Result<()> { ) .init(); - let no_daemonize = if let Some(arg) = std::env::args().nth(1) { - arg == "--no-daemonize" - } else { - false - }; + let no_daemonize = std::env::args() + .nth(1) + .map_or(false, |arg| arg == "--no-daemonize"); let startup_ack = if no_daemonize { None diff --git a/src/bin/rbw-agent/sock.rs b/src/bin/rbw-agent/sock.rs index 311176c..9458239 100644 --- a/src/bin/rbw-agent/sock.rs +++ b/src/bin/rbw-agent/sock.rs @@ -45,6 +45,8 @@ impl Sock { pub fn listen() -> anyhow::Result<tokio::net::UnixListener> { let path = rbw::dirs::socket_file(); // if the socket already doesn't exist, that's fine + // https://github.com/rust-lang/rust-clippy/issues/8003 + #[allow(clippy::let_underscore_drop)] let _ = std::fs::remove_file(&path); let sock = tokio::net::UnixListener::bind(&path) .context("failed to listen on socket")?; |