aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-05-23 22:30:43 -0400
committerJesse Luehrs <doy@tozt.net>2020-05-23 23:10:58 -0400
commitf82345336c1edad86420b3b61ebb8578eb495a3e (patch)
tree9f6da04b1c6ab69680916fc7d028a002d30ac203
parentae16ddeb2adc33b1ec23abfae29a553c920d8af4 (diff)
downloadrbw-f82345336c1edad86420b3b61ebb8578eb495a3e.tar.gz
rbw-f82345336c1edad86420b3b61ebb8578eb495a3e.zip
give a more useful error if rbw is misconfigured
-rw-r--r--src/bin/rbw/commands.rs19
-rw-r--r--src/config.rs8
-rw-r--r--src/error.rs3
3 files changed, 30 insertions, 0 deletions
diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs
index b3caa18..99522d1 100644
--- a/src/bin/rbw/commands.rs
+++ b/src/bin/rbw/commands.rs
@@ -1,5 +1,15 @@
use anyhow::Context as _;
+const MISSING_CONFIG_HELP: &str =
+ "Before using rbw, you must configure the email address you would like to \
+ use to log in to the server by running:\n\n \
+ rbw config set email <email>\n\n\
+ Additionally, if you are using a self-hosted installation, you should \
+ run:\n\n \
+ rbw config set base_url <url>\n\n\
+ and, if your server has a non-default identity url:\n\n \
+ rbw config set identity_url <url>\n";
+
#[derive(Debug, Clone)]
#[cfg_attr(test, derive(Eq, PartialEq))]
struct DecryptedCipher {
@@ -795,6 +805,8 @@ pub fn stop_agent() -> anyhow::Result<()> {
}
fn ensure_agent() -> anyhow::Result<()> {
+ check_config()?;
+
ensure_agent_once()?;
let client_version = rbw::protocol::version();
let agent_version = version_or_quit()?;
@@ -842,6 +854,13 @@ fn ensure_agent_once() -> anyhow::Result<()> {
Ok(())
}
+fn check_config() -> anyhow::Result<()> {
+ rbw::config::Config::validate().map_err(|e| {
+ log::error!("{}", MISSING_CONFIG_HELP);
+ anyhow::Error::new(e)
+ })
+}
+
fn version_or_quit() -> anyhow::Result<u32> {
crate::actions::version().or_else(|e| {
let _ = crate::actions::quit();
diff --git a/src/config.rs b/src/config.rs
index 39044c0..6c6c761 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -70,6 +70,14 @@ impl Config {
Ok(())
}
+ pub fn validate() -> Result<()> {
+ let config = Self::load()?;
+ if config.email.is_none() {
+ return Err(Error::ConfigMissingEmail);
+ }
+ Ok(())
+ }
+
pub fn base_url(&self) -> String {
self.base_url.clone().map_or_else(
|| "https://api.bitwarden.com".to_string(),
diff --git a/src/error.rs b/src/error.rs
index 5e36ed5..418aa3a 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,6 +1,9 @@
#[derive(Debug, snafu::Snafu)]
#[snafu(visibility = "pub")]
pub enum Error {
+ #[snafu(display("email address not set"))]
+ ConfigMissingEmail,
+
#[snafu(display("failed to create block mode decryptor"))]
CreateBlockMode {
source: block_modes::InvalidKeyIvLength,