From: Filip Schauer <f.schauer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH vma-to-pbs 1/9] Add the ability to provide credentials via files
Date: Wed, 3 Apr 2024 11:49:05 +0200 [thread overview]
Message-ID: <20240403094913.107177-2-f.schauer@proxmox.com> (raw)
In-Reply-To: <20240403094913.107177-1-f.schauer@proxmox.com>
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
src/main.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 2 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index 8d95b11..578c38e 100644
--- a/src/main.rs
+++ b/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,
};
--
2.39.2
next prev parent reply other threads:[~2024-04-03 9:50 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-03 9:49 [pbs-devel] [PATCH vma-to-pbs 0/9] Implement vma-to-pbs tool Filip Schauer
2024-04-03 9:49 ` Filip Schauer [this message]
2024-04-03 9:49 ` [pbs-devel] [PATCH vma-to-pbs 2/9] bump proxmox-backup-qemu Filip Schauer
2024-04-03 9:49 ` [pbs-devel] [PATCH vma-to-pbs 3/9] remove unnecessary "extern crate" declarations Filip Schauer
2024-04-03 9:49 ` [pbs-devel] [PATCH vma-to-pbs 4/9] add support for streaming the VMA file via stdin Filip Schauer
2024-04-03 14:52 ` Max Carrara
2024-04-09 12:16 ` Filip Schauer
2024-04-09 13:06 ` Max Carrara
2024-04-03 9:49 ` [pbs-devel] [PATCH vma-to-pbs 5/9] add a fallback for the --fingerprint argument Filip Schauer
2024-04-03 14:52 ` Max Carrara
2024-04-03 9:49 ` [pbs-devel] [PATCH vma-to-pbs 6/9] refactor error handling Filip Schauer
2024-04-03 14:52 ` Max Carrara
2024-04-03 9:49 ` [pbs-devel] [PATCH vma-to-pbs 7/9] makefile: remove reference to unused submodule Filip Schauer
2024-04-03 9:49 ` [pbs-devel] [PATCH vma-to-pbs 8/9] switch argument handling from clap to pico-args Filip Schauer
2024-04-03 14:52 ` Max Carrara
2024-04-09 12:16 ` Filip Schauer
2024-04-03 9:49 ` [pbs-devel] [PATCH vma-to-pbs 9/9] reformat command line arguments to kebab-case Filip Schauer
2024-04-03 9:57 ` [pbs-devel] [PATCH vma-to-pbs 0/9] Implement vma-to-pbs tool Filip Schauer
2024-04-03 14:51 ` Max Carrara
2024-04-09 12:17 ` Filip Schauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240403094913.107177-2-f.schauer@proxmox.com \
--to=f.schauer@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox