feat: Support export and import with different password #30
3 changed files with 7 additions and 4 deletions
|
@ -38,7 +38,7 @@ pub struct Add {
|
||||||
|
|
||||||
impl LprsCommand for Add {
|
impl LprsCommand for Add {
|
||||||
fn run(mut self, mut vault_manager: Vaults) -> LprsResult<()> {
|
fn run(mut self, mut vault_manager: Vaults) -> LprsResult<()> {
|
||||||
self.vault_info.password = utils::user_password(self.password)?;
|
self.vault_info.password = utils::user_password(self.password, "Vault password:")?;
|
||||||
vault_manager.add_vault(self.vault_info);
|
vault_manager.add_vault(self.vault_info);
|
||||||
vault_manager.try_export()
|
vault_manager.try_export()
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ impl LprsCommand for Edit {
|
||||||
*vault = Vault::new(
|
*vault = Vault::new(
|
||||||
self.name.as_ref().unwrap_or(&vault.name),
|
self.name.as_ref().unwrap_or(&vault.name),
|
||||||
self.username.as_ref().or(vault.username.as_ref()),
|
self.username.as_ref().or(vault.username.as_ref()),
|
||||||
utils::user_password(self.password)?
|
utils::user_password(self.password, "New vault password:")?
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.or(vault.password.as_ref()),
|
.or(vault.password.as_ref()),
|
||||||
self.service.as_ref().or(vault.service.as_ref()),
|
self.service.as_ref().or(vault.service.as_ref()),
|
||||||
|
|
|
@ -52,14 +52,17 @@ pub fn local_project_file(filename: &str) -> LprsResult<PathBuf> {
|
||||||
///
|
///
|
||||||
/// ## Errors
|
/// ## Errors
|
||||||
/// - When failed to get the password from stdin
|
/// - When failed to get the password from stdin
|
||||||
pub fn user_password(password: Option<Option<String>>) -> LprsResult<Option<String>> {
|
pub fn user_password(
|
||||||
|
password: Option<Option<String>>,
|
||||||
|
prompt_message: &str,
|
||||||
|
) -> LprsResult<Option<String>> {
|
||||||
Ok(match password {
|
Ok(match password {
|
||||||
None => None,
|
None => None,
|
||||||
Some(Some(p)) => Some(p),
|
Some(Some(p)) => Some(p),
|
||||||
Some(None) => {
|
Some(None) => {
|
||||||
log::debug!("User didn't provide a password, prompting it");
|
log::debug!("User didn't provide a password, prompting it");
|
||||||
Some(
|
Some(
|
||||||
Password::new("Vault password:")
|
Password::new(prompt_message)
|
||||||
.without_confirmation()
|
.without_confirmation()
|
||||||
.with_formatter(&|p| "*".repeat(p.chars().count()))
|
.with_formatter(&|p| "*".repeat(p.chars().count()))
|
||||||
.with_display_mode(PasswordDisplayMode::Masked)
|
.with_display_mode(PasswordDisplayMode::Masked)
|
||||||
|
|
Loading…
Reference in a new issue