🐛 Fixes parsing bw output
This commit is contained in:
+27
-2
@@ -31,6 +31,7 @@ pub struct Item {
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct ItemContent {
|
||||
pub title: String,
|
||||
pub note: String,
|
||||
pub content: ItemContentContent,
|
||||
}
|
||||
|
||||
@@ -46,6 +47,8 @@ pub struct ItemLogin {
|
||||
pub email: String,
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
pub urls: Vec<String>,
|
||||
pub totp_uri: Option<String>,
|
||||
}
|
||||
|
||||
// our own custom structure, a counterpart to rbw::LoginItem
|
||||
@@ -56,6 +59,9 @@ pub struct LoginItem {
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
pub urls: Option<Vec<String>>,
|
||||
pub notes: String,
|
||||
pub totp: Option<String>,
|
||||
}
|
||||
|
||||
pub fn check_pass() -> Result<(), Error> {
|
||||
@@ -124,6 +130,9 @@ pub fn get_logins(items: Items) -> Vec<LoginItem> {
|
||||
username: login.username,
|
||||
email: login.email,
|
||||
password: login.password,
|
||||
notes: item.content.note.clone(),
|
||||
urls: Some(login.urls),
|
||||
totp: login.totp_uri,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
@@ -135,9 +144,25 @@ pub fn update(vault: &String, item: LoginItem, user_is_actually_email: bool) {
|
||||
} else {
|
||||
format!("usename={}", item.username)
|
||||
};
|
||||
|
||||
let maybe_urls = if let Some(urls) = item.urls {
|
||||
let mut it = "".to_string();
|
||||
for url in urls {
|
||||
it = format!("{} --field 'url={}'", it, url);
|
||||
}
|
||||
it
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
let maybe_notes = if item.notes.is_empty() {
|
||||
"".to_string()
|
||||
} else {
|
||||
format!("--field 'note={}'", item.notes)
|
||||
};
|
||||
|
||||
let output = sh::sh(format!(
|
||||
"{} item update --vault-name '{}' --item-id '{}' --field 'password={}' --field '{}'",
|
||||
EXECUTABLE, vault, item.id, item.password, user_field_update
|
||||
"{} item update --vault-name '{}' --item-id '{}' --field 'password={}' --field '{}' {} {}",
|
||||
EXECUTABLE, vault, item.id, item.password, user_field_update, maybe_urls, maybe_notes
|
||||
));
|
||||
println!("> {}", output);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user