Display keyring errors

This commit is contained in:
FliegendeWurst 2021-05-07 15:49:34 +02:00
parent bc8bc9ed0d
commit 1e9adafae1
2 changed files with 13 additions and 8 deletions

View File

@ -212,6 +212,8 @@ fn ask_user_pass(opt: &Opt) -> Result<(String, String)> {
};
#[cfg(feature = "keyring-auth")]
let (pass, should_store);
#[cfg(feature = "keyring-auth")]
let keyring = Lazy::new(|| keyring::Keyring::new(env!("CARGO_PKG_NAME"), &user));
#[cfg(not(feature = "keyring-auth"))]
let pass;
cfg_if::cfg_if! { // TODO: deduplicate the logic below
@ -220,14 +222,17 @@ fn ask_user_pass(opt: &Opt) -> Result<(String, String)> {
pass = password.clone();
should_store = true;
} else if opt.keyring {
let keyring = keyring::Keyring::new(env!("CARGO_PKG_NAME"), &user);
if let Ok(password) = keyring.get_password() {
match keyring.get_password() {
Ok(password) => {
pass = password;
should_store = false;
} else {
},
Err(e) => {
error!(e);
pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?;
should_store = true;
}
}
} else {
pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?;
should_store = true;
@ -242,7 +247,6 @@ fn ask_user_pass(opt: &Opt) -> Result<(String, String)> {
};
#[cfg(feature = "keyring-auth")]
if should_store && opt.keyring {
let keyring = keyring::Keyring::new(env!("CARGO_PKG_NAME"), &user);
keyring.set_password(&pass).map_err(|x| anyhow!(x.to_string()))?;
}
Ok((user, pass))

View File

@ -8,6 +8,7 @@ use std::path::Path;
use crate::Result;
/// Write all data to the specified path. Will overwrite previous file data.
pub async fn write_file_data<R: ?Sized>(path: impl AsRef<Path>, data: &mut R) -> Result<()>
where R: AsyncRead + Unpin {
let file = AsyncFile::create(path.as_ref()).await.context("failed to create file")?;