src/client/http_client.rs: remove useless password_env
This commit is contained in:
parent
a05c0c6ff6
commit
d1c657276a
@ -37,6 +37,7 @@ use futures::*;
|
|||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
const ENV_VAR_PBS_FINGERPRINT: &str = "PBS_FINGERPRINT";
|
const ENV_VAR_PBS_FINGERPRINT: &str = "PBS_FINGERPRINT";
|
||||||
|
const ENV_VAR_PBS_PASSWORD: &str = "PBS_PASSWORD";
|
||||||
|
|
||||||
proxmox::const_regex! {
|
proxmox::const_regex! {
|
||||||
BACKUPSPEC_REGEX = r"^([a-zA-Z0-9_-]+\.(?:pxar|img|conf|log)):(.+)$";
|
BACKUPSPEC_REGEX = r"^([a-zA-Z0-9_-]+\.(?:pxar|img|conf|log)):(.+)$";
|
||||||
@ -170,9 +171,16 @@ fn connect(server: &str, userid: &str) -> Result<HttpClient, Error> {
|
|||||||
|
|
||||||
let fingerprint = std::env::var(ENV_VAR_PBS_FINGERPRINT).ok();
|
let fingerprint = std::env::var(ENV_VAR_PBS_FINGERPRINT).ok();
|
||||||
|
|
||||||
|
use std::env::VarError::*;
|
||||||
|
let password = match std::env::var(ENV_VAR_PBS_PASSWORD) {
|
||||||
|
Ok(p) => Some(p),
|
||||||
|
Err(NotUnicode(_)) => bail!(format!("{} contains bad characters", ENV_VAR_PBS_PASSWORD)),
|
||||||
|
Err(NotPresent) => None,
|
||||||
|
};
|
||||||
|
|
||||||
let options = HttpClientOptions::new()
|
let options = HttpClientOptions::new()
|
||||||
.prefix(Some("proxmox-backup".to_string()))
|
.prefix(Some("proxmox-backup".to_string()))
|
||||||
.password_env(Some("PBS_PASSWORD".to_string()))
|
.password(password)
|
||||||
.interactive(true)
|
.interactive(true)
|
||||||
.fingerprint(fingerprint)
|
.fingerprint(fingerprint)
|
||||||
.fingerprint_cache(true)
|
.fingerprint_cache(true)
|
||||||
@ -1483,10 +1491,11 @@ async fn status(param: Value) -> Result<Value, Error> {
|
|||||||
async fn try_get(repo: &BackupRepository, url: &str) -> Value {
|
async fn try_get(repo: &BackupRepository, url: &str) -> Value {
|
||||||
|
|
||||||
let fingerprint = std::env::var(ENV_VAR_PBS_FINGERPRINT).ok();
|
let fingerprint = std::env::var(ENV_VAR_PBS_FINGERPRINT).ok();
|
||||||
|
let password = std::env::var(ENV_VAR_PBS_PASSWORD).ok();
|
||||||
|
|
||||||
let options = HttpClientOptions::new()
|
let options = HttpClientOptions::new()
|
||||||
.prefix(Some("proxmox-backup".to_string()))
|
.prefix(Some("proxmox-backup".to_string()))
|
||||||
.password_env(Some("PBS_PASSWORD".to_string()))
|
.password(password)
|
||||||
.interactive(false)
|
.interactive(false)
|
||||||
.fingerprint(fingerprint)
|
.fingerprint(fingerprint)
|
||||||
.fingerprint_cache(true)
|
.fingerprint_cache(true)
|
||||||
|
@ -36,7 +36,6 @@ pub struct AuthInfo {
|
|||||||
pub struct HttpClientOptions {
|
pub struct HttpClientOptions {
|
||||||
prefix: Option<String>,
|
prefix: Option<String>,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
password_env: Option<String>,
|
|
||||||
fingerprint: Option<String>,
|
fingerprint: Option<String>,
|
||||||
interactive: bool,
|
interactive: bool,
|
||||||
ticket_cache: bool,
|
ticket_cache: bool,
|
||||||
@ -50,7 +49,6 @@ impl HttpClientOptions {
|
|||||||
Self {
|
Self {
|
||||||
prefix: None,
|
prefix: None,
|
||||||
password: None,
|
password: None,
|
||||||
password_env: None,
|
|
||||||
fingerprint: None,
|
fingerprint: None,
|
||||||
interactive: false,
|
interactive: false,
|
||||||
ticket_cache: false,
|
ticket_cache: false,
|
||||||
@ -69,11 +67,6 @@ impl HttpClientOptions {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn password_env(mut self, password_env: Option<String>) -> Self {
|
|
||||||
self.password_env = password_env;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fingerprint(mut self, fingerprint: Option<String>) -> Self {
|
pub fn fingerprint(mut self, fingerprint: Option<String>) -> Self {
|
||||||
self.fingerprint = fingerprint;
|
self.fingerprint = fingerprint;
|
||||||
self
|
self
|
||||||
@ -313,7 +306,7 @@ impl HttpClient {
|
|||||||
if let Some((ticket, _token)) = ticket_info {
|
if let Some((ticket, _token)) = ticket_info {
|
||||||
ticket
|
ticket
|
||||||
} else {
|
} else {
|
||||||
Self::get_password(&username, options.interactive, options.password_env.clone())?
|
Self::get_password(&username, options.interactive)?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -357,18 +350,7 @@ impl HttpClient {
|
|||||||
(*self.fingerprint.lock().unwrap()).clone()
|
(*self.fingerprint.lock().unwrap()).clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_password(username: &str, interactive: bool, password_env: Option<String>) -> Result<String, Error> {
|
fn get_password(username: &str, interactive: bool) -> Result<String, Error> {
|
||||||
if let Some(password_env) = password_env {
|
|
||||||
use std::env::VarError::*;
|
|
||||||
match std::env::var(&password_env) {
|
|
||||||
Ok(p) => return Ok(p),
|
|
||||||
Err(NotUnicode(_)) => bail!(format!("{} contains bad characters", password_env)),
|
|
||||||
Err(NotPresent) => {
|
|
||||||
// Try another method
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're on a TTY, query the user for a password
|
// If we're on a TTY, query the user for a password
|
||||||
if interactive && tty::stdin_isatty() {
|
if interactive && tty::stdin_isatty() {
|
||||||
let msg = format!("Password for \"{}\": ", username);
|
let msg = format!("Password for \"{}\": ", username);
|
||||||
|
Loading…
Reference in New Issue
Block a user