feat: Remove vault field if its value is empty string
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
90bcf968d4
commit
5d30b8b021
1 changed files with 29 additions and 9 deletions
|
@ -82,24 +82,44 @@ impl LprsCommand for Edit {
|
||||||
if let Some(new_name) = self.name {
|
if let Some(new_name) = self.name {
|
||||||
vault.name = new_name;
|
vault.name = new_name;
|
||||||
}
|
}
|
||||||
if self.password.is_some() {
|
if let Some(ref new_password) = self.password {
|
||||||
|
if new_password.as_deref().is_some_and(|s| s.is_empty()) {
|
||||||
|
vault.password = None;
|
||||||
|
} else {
|
||||||
vault.password = utils::user_secret(self.password, "New vault password:", false)?;
|
vault.password = utils::user_secret(self.password, "New vault password:", false)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if let Some(totp_secret) = utils::user_secret(self.totp_secret, "TOTP Secret:", false)? {
|
if let Some(totp_secret) = utils::user_secret(self.totp_secret, "TOTP Secret:", false)? {
|
||||||
|
if totp_secret.is_empty() {
|
||||||
|
vault.totp_secret = None;
|
||||||
|
} else {
|
||||||
cipher::base32_decode(&totp_secret).map_err(|_| {
|
cipher::base32_decode(&totp_secret).map_err(|_| {
|
||||||
LprsError::Base32("Invalid TOTP secret, must be valid base32 string".to_owned())
|
LprsError::Base32("Invalid TOTP secret, must be valid base32 string".to_owned())
|
||||||
})?;
|
})?;
|
||||||
vault.totp_secret = Some(totp_secret);
|
vault.totp_secret = Some(totp_secret);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if let Some(new_username) = self.username {
|
if let Some(new_username) = self.username {
|
||||||
|
if new_username.is_empty() {
|
||||||
|
vault.username = None;
|
||||||
|
} else {
|
||||||
vault.username = Some(new_username);
|
vault.username = Some(new_username);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if let Some(new_service) = self.service {
|
if let Some(new_service) = self.service {
|
||||||
|
if new_service.is_empty() {
|
||||||
|
vault.service = None;
|
||||||
|
} else {
|
||||||
vault.service = Some(new_service);
|
vault.service = Some(new_service);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if let Some(new_note) = self.note {
|
if let Some(new_note) = self.note {
|
||||||
|
if new_note.is_empty() {
|
||||||
|
vault.note = None;
|
||||||
|
} else {
|
||||||
vault.note = Some(new_note);
|
vault.note = Some(new_note);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
utils::apply_custom_fields(&mut vault.custom_fields, self.custom_fields);
|
utils::apply_custom_fields(&mut vault.custom_fields, self.custom_fields);
|
||||||
|
|
||||||
vault_manager.try_export()
|
vault_manager.try_export()
|
||||||
|
|
Loading…
Reference in a new issue