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
12
src/main.rs
12
src/main.rs
@ -212,6 +212,8 @@ fn ask_user_pass(opt: &Opt) -> Result<(String, String)> {
|
|||||||
};
|
};
|
||||||
#[cfg(feature = "keyring-auth")]
|
#[cfg(feature = "keyring-auth")]
|
||||||
let (pass, should_store);
|
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"))]
|
#[cfg(not(feature = "keyring-auth"))]
|
||||||
let pass;
|
let pass;
|
||||||
cfg_if::cfg_if! { // TODO: deduplicate the logic below
|
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();
|
pass = password.clone();
|
||||||
should_store = true;
|
should_store = true;
|
||||||
} else if opt.keyring {
|
} else if opt.keyring {
|
||||||
let keyring = keyring::Keyring::new(env!("CARGO_PKG_NAME"), &user);
|
match keyring.get_password() {
|
||||||
if let Ok(password) = keyring.get_password() {
|
Ok(password) => {
|
||||||
pass = password;
|
pass = password;
|
||||||
should_store = false;
|
should_store = false;
|
||||||
} else {
|
},
|
||||||
|
Err(e) => {
|
||||||
|
error!(e);
|
||||||
pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?;
|
pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?;
|
||||||
should_store = true;
|
should_store = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?;
|
pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?;
|
||||||
should_store = true;
|
should_store = true;
|
||||||
@ -242,7 +247,6 @@ fn ask_user_pass(opt: &Opt) -> Result<(String, String)> {
|
|||||||
};
|
};
|
||||||
#[cfg(feature = "keyring-auth")]
|
#[cfg(feature = "keyring-auth")]
|
||||||
if should_store && opt.keyring {
|
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()))?;
|
keyring.set_password(&pass).map_err(|x| anyhow!(x.to_string()))?;
|
||||||
}
|
}
|
||||||
Ok((user, pass))
|
Ok((user, pass))
|
||||||
|
@ -8,6 +8,7 @@ use std::path::Path;
|
|||||||
|
|
||||||
use crate::Result;
|
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<()>
|
pub async fn write_file_data<R: ?Sized>(path: impl AsRef<Path>, data: &mut R) -> Result<()>
|
||||||
where R: AsyncRead + Unpin {
|
where R: AsyncRead + Unpin {
|
||||||
let file = AsyncFile::create(path.as_ref()).await.context("failed to create file")?;
|
let file = AsyncFile::create(path.as_ref()).await.context("failed to create file")?;
|
||||||
|
Loading…
Reference in New Issue
Block a user