Make keyring support non-optional

Now that the dbus library isn't needed..
This commit is contained in:
FliegendeWurst 2022-01-06 15:57:50 +01:00
parent bd9a777bb9
commit 126f8500e4
3 changed files with 527 additions and 306 deletions

772
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[package]
name = "KIT-ILIAS-downloader"
version = "0.2.24"
version = "0.3.0"
authors = ["FliegendeWurst <2012gdwu@posteo.de>"]
license = "GPL-3.0-or-later"
edition = "2018"
@ -24,18 +24,14 @@ rprompt = "1.0.5"
ignore = "0.4.14"
anyhow = "1.0.28"
colored = "2.0.0"
keyring = { version = "0.10.1", optional = true }
keyring = "1.0.0"
cfg-if = "1.0.0"
indicatif = "0.16.0"
once_cell = "1.7.2"
atty = "0.2.14"
h2 = "0.3.3"
cookie_store = "0.14.0"
reqwest_cookie_store = "0.1.5"
cookie_store = "0.15.1"
reqwest_cookie_store = "0.2.0"
bytes = "1.0.1"
toml = "0.5.8"
tempfile = "3.2.0"
[features]
default = []
keyring-auth = ["keyring"]

View File

@ -3,7 +3,6 @@
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, AtomicUsize};
#[cfg(feature = "keyring-auth")]
use anyhow::anyhow;
use anyhow::{Context, Result};
use indicatif::ProgressBar;
@ -63,7 +62,6 @@ pub struct Opt {
/// Use the system keyring
#[structopt(long)]
#[cfg(feature = "keyring-auth")]
pub keyring: bool,
/// KIT account username
@ -151,42 +149,27 @@ pub fn ask_user_pass(opt: &Opt) -> Result<(String, String)> {
} else {
rprompt::prompt_reply_stdout("Username: ").context("username prompt")?
};
#[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
if #[cfg(feature = "keyring-auth")] {
if let Some(password) = opt.password.as_ref() {
pass = password.clone();
should_store = true;
} else if opt.keyring {
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 {
let keyring = Lazy::new(|| keyring::Entry::new(env!("CARGO_PKG_NAME"), &user));
if let Some(password) = opt.password.as_ref() {
pass = password.clone();
should_store = true;
} else if opt.keyring {
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 {
if let Some(password) = opt.password.as_ref() {
pass = password.clone();
} else {
pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?;
}
}
};
#[cfg(feature = "keyring-auth")]
} else {
pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?;
should_store = true;
}
if should_store && opt.keyring {
keyring.set_password(&pass).map_err(|x| anyhow!(x.to_string()))?;
}