Adds updating fields

Signed-off-by: Ash Svitan <selfsigned-ash@proton.me>
This commit is contained in:
2026-04-30 21:07:11 +02:00
parent cad0caf379
commit efb661c32a
3 changed files with 36 additions and 22 deletions
+19 -8
View File
@@ -28,7 +28,6 @@ pub struct Item {
#[derive(Deserialize, Debug, Clone)]
pub struct ItemContent {
pub title: String,
pub note: String,
pub content: ItemContentContent,
}
@@ -44,8 +43,6 @@ pub struct ItemLogin {
pub email: String,
pub username: String,
pub password: String,
pub urls: Vec<String>,
pub totp_uri: String,
}
// our own custom structure, a counterpart to rbw::LoginItem
@@ -56,8 +53,6 @@ pub struct LoginItem {
pub username: String,
pub email: String,
pub password: String,
pub urls: Vec<String>,
pub totp_uri: String,
}
pub fn check_pass() -> Result<(), Error> {
@@ -92,7 +87,10 @@ pub fn get_vaults() -> Result<Vaults, Error> {
}
pub fn get_items(vault: &String) -> Result<Items, Error> {
let items_raw = sh::sh(format!("{} item list {} --output json", EXECUTABLE, vault));
let items_raw = sh::sh(format!(
"{} item list '{}' --output json",
EXECUTABLE, vault
));
return match serde_json::from_str(items_raw.as_str()) {
Ok(val) => Ok(val),
Err(e) => Err(Error::new(
@@ -121,9 +119,22 @@ pub fn get_logins(items: Items) -> Vec<LoginItem> {
username: login.username,
email: login.email,
password: login.password,
urls: login.urls,
totp_uri: login.totp_uri,
}
})
.collect()
}
pub fn update(vault: &String, item: LoginItem, user_is_actually_email: bool) -> Result<(), Error> {
let user_field_update = if user_is_actually_email {
format!("email={}", item.email)
} else {
format!("usename={}", item.username)
};
let output = sh::sh(format!(
"{} item update --vault-name '{}' --item-id '{}' --field 'password={}' --field '{}'",
EXECUTABLE, vault, item.id, item.password, user_field_update
));
println!("> {}", output);
return Ok(());
}