feat: Ability to pass the master password as option
All checks were successful
Rust CI / Rust CI (pull_request) Successful in 2m1s
Write changelog / write-changelog (push) Successful in 3s
Rust CI / Rust CI (push) Successful in 2m7s

This commit is contained in:
Awiteb 2024-05-10 13:11:34 +03:00
parent a38c91c328
commit 62d4060bb8
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F

View file

@ -17,6 +17,7 @@
use std::{fs, path::PathBuf}; use std::{fs, path::PathBuf};
use clap::Parser; use clap::Parser;
use sha2::{Digest, Sha256};
use crate::{impl_commands, utils, vault::Vaults, LprsCommand, LprsResult}; use crate::{impl_commands, utils, vault::Vaults, LprsCommand, LprsResult};
@ -78,6 +79,9 @@ pub struct Cli {
/// Show the logs in the stdout /// Show the logs in the stdout
#[arg(short, long)] #[arg(short, long)]
pub verbose: bool, pub verbose: bool,
/// The master password, or you will prompt it
#[arg(short, long)]
pub master_password: Option<String>,
#[command(subcommand)] #[command(subcommand)]
/// The provided command to run /// The provided command to run
@ -121,8 +125,11 @@ impl Cli {
} }
} else { } else {
log::info!("Reloading the vaults file"); log::info!("Reloading the vaults file");
let master_password = let master_password = if let Some(plain_master_password) = self.master_password {
utils::master_password_prompt(fs::read(&vaults_file)?.is_empty())?; Sha256::digest(plain_master_password).into()
} else {
utils::master_password_prompt(fs::read(&vaults_file)?.is_empty())?
};
Vaults::try_reload(vaults_file, master_password)? Vaults::try_reload(vaults_file, master_password)?
}; };