[pbs-devel] [PATCH vma-to-pbs 04/10] Add the ability to provide credentials via files

Max Carrara m.carrara at proxmox.com
Mon Mar 25 13:33:51 CET 2024


On Wed Mar 20, 2024 at 3:15 PM CET, Filip Schauer wrote:
> Signed-off-by: Filip Schauer <f.schauer at proxmox.com>
> ---
>  src/main.rs | 31 +++++++++++++++++++++++++++++--
>  1 file changed, 29 insertions(+), 2 deletions(-)
>
> diff --git a/src/main.rs b/src/main.rs
> index 8d95b11..b58387b 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();

One thing I had noticed when using the CLI: Would it maaaybe be nicer to
use e.g. --password-file instead of --password_file? AFAIR @Wolfgang
mentioned something regarding this off list.

>  
> @@ -296,10 +308,25 @@ 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) => {
> +            std::fs::read_to_string(password_file).expect("Could not read password file")

You changed this later and got rid of the undying, but that fix could've
perhaps been in here already.

> +        }
> +        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) => std::fs::read_to_string(key_password_file)
> +                    .expect("Could not read key password file"),

Same as above.

> +                None => String::from_utf8(tty::read_password("Key Password: ")?)?,
> +            })
> +        }
>          None => None,
>      };
>  

[0]: https://docs.rs/anyhow/1.0.79/anyhow/trait.Context.html




More information about the pbs-devel mailing list