Support null bitwarden login, username and password

This commit is contained in:
TheAwiteb 2024-01-07 22:16:39 +03:00
parent bfc6f74f4d
commit 1474bc9fe3
No known key found for this signature in database
GPG key ID: ABF818BD15DC2D34

View file

@ -4,8 +4,8 @@ use super::{Password, Passwords};
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BitWardenLoginData { pub struct BitWardenLoginData {
pub username: String, pub username: Option<String>,
pub password: String, pub password: Option<String>,
pub uris: Option<Vec<BitWardenUri>>, pub uris: Option<Vec<BitWardenUri>>,
} }
@ -27,7 +27,7 @@ pub struct BitWardenPassword {
#[serde(rename = "type")] #[serde(rename = "type")]
pub ty: i32, pub ty: i32,
pub name: String, pub name: String,
pub login: BitWardenLoginData, pub login: Option<BitWardenLoginData>,
pub notes: Option<String>, pub notes: Option<String>,
} }
@ -43,12 +43,17 @@ impl From<BitWardenPassword> for Password {
fn from(value: BitWardenPassword) -> Self { fn from(value: BitWardenPassword) -> Self {
Self { Self {
name: value.name, name: value.name,
username: value.login.username, username: value
password: value.login.password, .login
.as_ref()
.map_or_else(String::new, |l| l.username.to_owned().unwrap_or_default()),
password: value
.login
.as_ref()
.map_or_else(String::new, |l| l.password.to_owned().unwrap_or_default()),
service: value service: value
.login .login
.uris .and_then(|l| l.uris.and_then(|p| p.first().map(|u| u.uri.clone()))),
.and_then(|p| p.first().map(|u| u.uri.clone())),
note: value.notes, note: value.notes,
} }
} }
@ -59,13 +64,13 @@ impl From<Password> for BitWardenPassword {
Self { Self {
ty: 1, ty: 1,
name: value.name, name: value.name,
login: BitWardenLoginData { login: Some(BitWardenLoginData {
username: value.username, username: Some(value.username),
password: value.password, password: Some(value.password),
uris: value uris: value
.service .service
.map(|s| vec![BitWardenUri { mt: None, uri: s }]), .map(|s| vec![BitWardenUri { mt: None, uri: s }]),
}, }),
notes: value.note, notes: value.note,
} }
} }