mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-08-01 22:59:21 +00:00
use IsTerminal trait whenever possible
Continuation of https://lists.proxmox.com/pipermail/pbs-devel/2023-November/007078.html. Signed-off-by: Maximiliano Sandoval R <m.sandoval@proxmox.com>
This commit is contained in:
parent
22b5ae08f3
commit
2711e94e3a
@ -1,4 +1,4 @@
|
|||||||
use std::io::Write;
|
use std::io::{IsTerminal, Write};
|
||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::{Arc, Mutex, RwLock};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@ -458,7 +458,7 @@ impl HttpClient {
|
|||||||
&auth.ticket,
|
&auth.ticket,
|
||||||
&auth.token,
|
&auth.token,
|
||||||
) {
|
) {
|
||||||
if tty::stdout_isatty() {
|
if std::io::stdout().is_terminal() {
|
||||||
log::error!("storing login ticket failed: {}", err);
|
log::error!("storing login ticket failed: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -496,7 +496,7 @@ impl HttpClient {
|
|||||||
&auth.ticket,
|
&auth.ticket,
|
||||||
&auth.token,
|
&auth.token,
|
||||||
) {
|
) {
|
||||||
if tty::stdout_isatty() {
|
if std::io::stdout().is_terminal() {
|
||||||
log::error!("storing login ticket failed: {}", err);
|
log::error!("storing login ticket failed: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -548,7 +548,7 @@ impl HttpClient {
|
|||||||
|
|
||||||
fn get_password(username: &Userid, interactive: bool) -> Result<String, Error> {
|
fn get_password(username: &Userid, interactive: bool) -> Result<String, Error> {
|
||||||
// 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 && std::io::stdin().is_terminal() {
|
||||||
let msg = format!("Password for \"{}\": ", username);
|
let msg = format!("Password for \"{}\": ", username);
|
||||||
return Ok(String::from_utf8(tty::read_password(&msg)?)?);
|
return Ok(String::from_utf8(tty::read_password(&msg)?)?);
|
||||||
}
|
}
|
||||||
@ -599,7 +599,7 @@ impl HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're on a TTY, query the user
|
// If we're on a TTY, query the user
|
||||||
if interactive && tty::stdin_isatty() {
|
if interactive && std::io::stdin().is_terminal() {
|
||||||
log::info!("fingerprint: {}", fp_string);
|
log::info!("fingerprint: {}", fp_string);
|
||||||
loop {
|
loop {
|
||||||
eprint!("Are you sure you want to continue connecting? (y/n): ");
|
eprint!("Are you sure you want to continue connecting? (y/n): ");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::io::Read;
|
use std::io::{IsTerminal, Read};
|
||||||
use std::os::unix::io::{FromRawFd, RawFd};
|
use std::os::unix::io::{FromRawFd, RawFd};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ pub fn get_encryption_key_password() -> Result<Vec<u8>, Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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 tty::stdin_isatty() {
|
if std::io::stdin().is_terminal() {
|
||||||
return tty::read_password("Encryption Key Password: ");
|
return tty::read_password("Encryption Key Password: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use std::io::IsTerminal;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
@ -100,7 +101,7 @@ fn create(kdf: Option<Kdf>, path: Option<String>, hint: Option<String>) -> Resul
|
|||||||
}
|
}
|
||||||
Kdf::Scrypt | Kdf::PBKDF2 => {
|
Kdf::Scrypt | Kdf::PBKDF2 => {
|
||||||
// always read passphrase from tty
|
// always read passphrase from tty
|
||||||
if !tty::stdin_isatty() {
|
if !std::io::stdin().is_terminal() {
|
||||||
bail!("unable to read passphrase - no tty");
|
bail!("unable to read passphrase - no tty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +237,7 @@ fn change_passphrase(
|
|||||||
|
|
||||||
let kdf = kdf.unwrap_or_default();
|
let kdf = kdf.unwrap_or_default();
|
||||||
|
|
||||||
if !tty::stdin_isatty() {
|
if !std::io::stdin().is_terminal() {
|
||||||
bail!("unable to change passphrase - no tty");
|
bail!("unable to change passphrase - no tty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,7 +360,7 @@ fn import_master_pubkey(path: String) -> Result<(), Error> {
|
|||||||
/// encryption key onto the backup server along with each backup.
|
/// encryption key onto the backup server along with each backup.
|
||||||
fn create_master_key() -> Result<(), Error> {
|
fn create_master_key() -> Result<(), Error> {
|
||||||
// we need a TTY to query the new password
|
// we need a TTY to query the new password
|
||||||
if !tty::stdin_isatty() {
|
if !std::io::stdin().is_terminal() {
|
||||||
bail!("unable to create master key - no tty");
|
bail!("unable to create master key - no tty");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::ffi::{OsStr, OsString};
|
use std::ffi::{OsStr, OsString};
|
||||||
use std::io::Write;
|
use std::io::{IsTerminal, Write};
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -601,7 +601,7 @@ impl FileEntryPrinter {
|
|||||||
let color_choice = match output_params.color {
|
let color_choice = match output_params.color {
|
||||||
ColorMode::Always => ColorChoice::Always,
|
ColorMode::Always => ColorChoice::Always,
|
||||||
ColorMode::Auto => {
|
ColorMode::Auto => {
|
||||||
if unsafe { libc::isatty(1) == 1 } {
|
if std::io::stdout().is_terminal() {
|
||||||
// Show colors unless `TERM=dumb` or `NO_COLOR` is set.
|
// Show colors unless `TERM=dumb` or `NO_COLOR` is set.
|
||||||
ColorChoice::Auto
|
ColorChoice::Auto
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::io::IsTerminal;
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
@ -149,7 +151,7 @@ fn change_passphrase(
|
|||||||
mut param: Value,
|
mut param: Value,
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
rpcenv: &mut dyn RpcEnvironment,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
if !tty::stdin_isatty() {
|
if !std::io::stdin().is_terminal() {
|
||||||
bail!("unable to change passphrase - no tty");
|
bail!("unable to change passphrase - no tty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +210,7 @@ async fn restore_key(
|
|||||||
} else if !drive_passed && key.is_none() && key_file.is_none() {
|
} else if !drive_passed && key.is_none() && key_file.is_none() {
|
||||||
bail!("one of either 'drive' or 'key' parameter must be set!");
|
bail!("one of either 'drive' or 'key' parameter must be set!");
|
||||||
}
|
}
|
||||||
if !tty::stdin_isatty() {
|
if !std::io::stdin().is_terminal() {
|
||||||
bail!("no password input mechanism available");
|
bail!("no password input mechanism available");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,7 +285,7 @@ async fn restore_key(
|
|||||||
)]
|
)]
|
||||||
/// Create key (read password from stdin)
|
/// Create key (read password from stdin)
|
||||||
fn create_key(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
|
fn create_key(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
|
||||||
if !tty::stdin_isatty() {
|
if !std::io::stdin().is_terminal() {
|
||||||
bail!("no password input mechanism available");
|
bail!("no password input mechanism available");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user