Adds updating notes and urls and warning about TOTP (which can't be updated through pass-cli)

This commit is contained in:
2026-07-20 20:50:20 +02:00
parent 22568554af
commit d3e971fecd
2 changed files with 32 additions and 17 deletions
+28 -14
View File
@@ -13,10 +13,16 @@ const ENV_VAR_DEFAULT_VAULT: &str = "PASS_VAULT";
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]
struct Cli {} struct Cli {}
fn ask_consent(question: String, line1: String, line2: String) -> Result<bool, Error> { fn ask_consent(
question: String,
line1: String,
line2: String,
line3: String,
) -> Result<bool, Error> {
println!("{}", question); println!("{}", question);
println!("\t{}", line1); println!("\t{}", line1);
println!("\t{}", line2); println!("\t{}", line2);
println!("\t{}", line3);
print!("Proceed? [y/N] "); print!("Proceed? [y/N] ");
io::stdout().flush()?; io::stdout().flush()?;
let mut input = String::new(); let mut input = String::new();
@@ -101,19 +107,18 @@ fn sync() -> Result<(), Error> {
}; };
let pass_user_is_actually_email = pass_user == pass_login.email; let pass_user_is_actually_email = pass_user == pass_login.email;
println!( let bw_notes = bw_item.notes.clone().unwrap_or("".to_string());
"{}: {} -> {} and {} -> {}", let pass_notes = pass_login.notes.clone();
bw_item.name,
pass_user, if bw_user != pass_user
bw_user, || (bw_password != pass_password && bw_password != "".to_string())
bw_password.clone(), || bw_notes != pass_notes
pass_password {
);
if bw_user != pass_user || (bw_password != pass_password && bw_password != "".to_string()) {
let consent = ask_consent( let consent = ask_consent(
format!("Attempting to update {}:", bw_item.name), format!("Attempting to update {}:", bw_item.name),
format!("{} -> {}", pass_user, bw_user.clone()), format!("{} -> {}", pass_user, bw_user.clone()),
format!("{} -> {}", pass_password, bw_password.clone()), format!("{} -> {}", pass_password, bw_password.clone()),
format!("{} -> {}", bw_notes, pass_notes),
)?; )?;
if consent { if consent {
let updated_pass_login = pass::LoginItem { let updated_pass_login = pass::LoginItem {
@@ -122,23 +127,30 @@ fn sync() -> Result<(), Error> {
username: bw_user.clone(), username: bw_user.clone(),
email: bw_user.clone(), email: bw_user.clone(),
password: bw_password, password: bw_password,
notes: pass_login.notes.clone(), notes: bw_notes,
urls: pass_login.urls.clone(), urls: Some(bw_login.uris.iter().map(|x| x.uri.clone()).collect()),
totp: pass_login.totp.clone(), totp: pass_login.totp.clone(),
}; };
pass::update(&vault, updated_pass_login, pass_user_is_actually_email); pass::update(&vault, updated_pass_login, pass_user_is_actually_email);
} }
} }
let bw_totp = bw_login.totp.clone().unwrap_or("".to_string());
let pass_totp = pass_login.totp.clone().unwrap_or("".to_string());
if bw_totp != "".to_string() && pass_totp == "".to_string() {
println!(
"TOTP found for {} but not in pass, you need to manually change it to {}",
bw_item.name, bw_totp
);
}
let bw_index = bw_items.iter().position(|x| x.id == bw_item.id).unwrap(); let bw_index = bw_items.iter().position(|x| x.id == bw_item.id).unwrap();
println!("found bw index {}", bw_index);
bw_items.remove(bw_index); bw_items.remove(bw_index);
let pass_index = pass_logins let pass_index = pass_logins
.iter() .iter()
.position(|x| x.id == pass_login.id) .position(|x| x.id == pass_login.id)
.unwrap(); .unwrap();
println!("found pass index {}", pass_index);
pass_logins.remove(pass_index); pass_logins.remove(pass_index);
} }
@@ -156,6 +168,7 @@ fn sync() -> Result<(), Error> {
format!("Attempting to create {}:", bw_item.name), format!("Attempting to create {}:", bw_item.name),
format!("{}", login.username.clone().unwrap_or("".to_string())), format!("{}", login.username.clone().unwrap_or("".to_string())),
format!("{}", login.password.clone().unwrap_or("".to_string())), format!("{}", login.password.clone().unwrap_or("".to_string())),
format!("{}", bw_item.notes.clone().unwrap_or("".to_string())),
)?; )?;
if consent { if consent {
pass::create( pass::create(
@@ -179,6 +192,7 @@ fn sync() -> Result<(), Error> {
} }
), ),
format!("{}", pass_login.password), format!("{}", pass_login.password),
format!("{}", pass_login.notes),
)?; )?;
if consent { if consent {
pass::trash(&vault, pass_login.id); pass::trash(&vault, pass_login.id);
+4 -3
View File
@@ -148,7 +148,7 @@ pub fn update(vault: &String, item: LoginItem, user_is_actually_email: bool) {
let maybe_urls = if let Some(urls) = item.urls { let maybe_urls = if let Some(urls) = item.urls {
let mut it = "".to_string(); let mut it = "".to_string();
for url in urls { for url in urls {
it = format!("{} --field 'url={}'", it, url); it = format!("{} --field 'urls={}'", it, url);
} }
it it
} else { } else {
@@ -160,10 +160,11 @@ pub fn update(vault: &String, item: LoginItem, user_is_actually_email: bool) {
format!("--field 'note={}'", item.notes) format!("--field 'note={}'", item.notes)
}; };
let output = sh::sh(format!( let cmd = format!(
"{} item update --vault-name '{}' --item-id '{}' --field 'password={}' --field '{}' {} {}", "{} item update --vault-name '{}' --item-id '{}' --field 'password={}' --field '{}' {} {}",
EXECUTABLE, vault, item.id, item.password, user_field_update, maybe_urls, maybe_notes EXECUTABLE, vault, item.id, item.password, user_field_update, maybe_urls, maybe_notes
)); );
let output = sh::sh(cmd.clone());
println!("> {}", output); println!("> {}", output);
} }