mirror of
https://github.com/FliegendeWurst/KIT-ILIAS-downloader.git
synced 2024-08-28 04:04:18 +00:00
Display keyring errors
This commit is contained in:
parent
bc8bc9ed0d
commit
1e9adafae1
20
src/main.rs
20
src/main.rs
@ -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,13 +222,16 @@ 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() {
|
||||
pass = password;
|
||||
should_store = false;
|
||||
} else {
|
||||
pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?;
|
||||
should_store = true;
|
||||
match keyring.get_password() {
|
||||
Ok(password) => {
|
||||
pass = password;
|
||||
should_store = false;
|
||||
},
|
||||
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")?;
|
||||
@ -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))
|
||||
|
@ -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")?;
|
||||
|
Loading…
Reference in New Issue
Block a user