mirror of
https://git.proxmox.com/git/vma-to-pbs
synced 2025-04-28 16:06:13 +00:00
add the ability to provide credentials via files
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
This commit is contained in:
parent
285019aaf5
commit
324e2f88d9
52
src/main.rs
52
src/main.rs
@ -280,6 +280,18 @@ fn main() -> Result<()> {
|
||||
.help("Encrypt the Backup")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("password-file")
|
||||
.long("password-file")
|
||||
.value_name("PASSWORD_FILE")
|
||||
.help("Password file"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("key-password-file")
|
||||
.long("key-password-file")
|
||||
.value_name("KEY_PASSWORD_FILE")
|
||||
.help("Key password file"),
|
||||
)
|
||||
.arg(Arg::new("vma_file"))
|
||||
.get_matches();
|
||||
|
||||
@ -296,10 +308,46 @@ fn main() -> Result<()> {
|
||||
let encrypt = matches.get_flag("encrypt");
|
||||
|
||||
let vma_file_path = matches.get_one::<String>("vma_file").unwrap().to_string();
|
||||
let password_file = matches.get_one::<String>("password-file");
|
||||
|
||||
let pbs_password = match password_file {
|
||||
Some(password_file) => {
|
||||
let mut password =
|
||||
std::fs::read_to_string(password_file).context("Could not read password file")?;
|
||||
|
||||
if password.ends_with('\n') || password.ends_with('\r') {
|
||||
password.pop();
|
||||
if password.ends_with('\r') {
|
||||
password.pop();
|
||||
}
|
||||
}
|
||||
|
||||
password
|
||||
}
|
||||
None => String::from_utf8(tty::read_password("Password: ")?)?,
|
||||
};
|
||||
|
||||
let pbs_password = String::from_utf8(tty::read_password(&"Password: ").unwrap()).unwrap();
|
||||
let key_password = match keyfile {
|
||||
Some(_) => Some(String::from_utf8(tty::read_password(&"Key Password: ").unwrap()).unwrap()),
|
||||
Some(_) => {
|
||||
let key_password_file = matches.get_one::<String>("key_password_file");
|
||||
|
||||
Some(match key_password_file {
|
||||
Some(key_password_file) => {
|
||||
let mut key_password = std::fs::read_to_string(key_password_file)
|
||||
.context("Could not read key password file")?;
|
||||
|
||||
if key_password.ends_with('\n') || key_password.ends_with('\r') {
|
||||
key_password.pop();
|
||||
if key_password.ends_with('\r') {
|
||||
key_password.pop();
|
||||
}
|
||||
}
|
||||
|
||||
key_password
|
||||
}
|
||||
None => String::from_utf8(tty::read_password("Key Password: ")?)?,
|
||||
})
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user