✨ Adds updating notes and urls and warning about TOTP (which can't be updated through pass-cli)
This commit is contained in:
+28
-14
@@ -13,10 +13,16 @@ const ENV_VAR_DEFAULT_VAULT: &str = "PASS_VAULT";
|
||||
#[command(version, about, long_about = None)]
|
||||
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!("\t{}", line1);
|
||||
println!("\t{}", line2);
|
||||
println!("\t{}", line3);
|
||||
print!("Proceed? [y/N] ");
|
||||
io::stdout().flush()?;
|
||||
let mut input = String::new();
|
||||
@@ -101,19 +107,18 @@ fn sync() -> Result<(), Error> {
|
||||
};
|
||||
let pass_user_is_actually_email = pass_user == pass_login.email;
|
||||
|
||||
println!(
|
||||
"{}: {} -> {} and {} -> {}",
|
||||
bw_item.name,
|
||||
pass_user,
|
||||
bw_user,
|
||||
bw_password.clone(),
|
||||
pass_password
|
||||
);
|
||||
if bw_user != pass_user || (bw_password != pass_password && bw_password != "".to_string()) {
|
||||
let bw_notes = bw_item.notes.clone().unwrap_or("".to_string());
|
||||
let pass_notes = pass_login.notes.clone();
|
||||
|
||||
if bw_user != pass_user
|
||||
|| (bw_password != pass_password && bw_password != "".to_string())
|
||||
|| bw_notes != pass_notes
|
||||
{
|
||||
let consent = ask_consent(
|
||||
format!("Attempting to update {}:", bw_item.name),
|
||||
format!("{} -> {}", pass_user, bw_user.clone()),
|
||||
format!("{} -> {}", pass_password, bw_password.clone()),
|
||||
format!("{} -> {}", bw_notes, pass_notes),
|
||||
)?;
|
||||
if consent {
|
||||
let updated_pass_login = pass::LoginItem {
|
||||
@@ -122,23 +127,30 @@ fn sync() -> Result<(), Error> {
|
||||
username: bw_user.clone(),
|
||||
email: bw_user.clone(),
|
||||
password: bw_password,
|
||||
notes: pass_login.notes.clone(),
|
||||
urls: pass_login.urls.clone(),
|
||||
notes: bw_notes,
|
||||
urls: Some(bw_login.uris.iter().map(|x| x.uri.clone()).collect()),
|
||||
totp: pass_login.totp.clone(),
|
||||
};
|
||||
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();
|
||||
println!("found bw index {}", bw_index);
|
||||
bw_items.remove(bw_index);
|
||||
|
||||
let pass_index = pass_logins
|
||||
.iter()
|
||||
.position(|x| x.id == pass_login.id)
|
||||
.unwrap();
|
||||
println!("found pass index {}", pass_index);
|
||||
pass_logins.remove(pass_index);
|
||||
}
|
||||
|
||||
@@ -156,6 +168,7 @@ fn sync() -> Result<(), Error> {
|
||||
format!("Attempting to create {}:", bw_item.name),
|
||||
format!("{}", login.username.clone().unwrap_or("".to_string())),
|
||||
format!("{}", login.password.clone().unwrap_or("".to_string())),
|
||||
format!("{}", bw_item.notes.clone().unwrap_or("".to_string())),
|
||||
)?;
|
||||
if consent {
|
||||
pass::create(
|
||||
@@ -179,6 +192,7 @@ fn sync() -> Result<(), Error> {
|
||||
}
|
||||
),
|
||||
format!("{}", pass_login.password),
|
||||
format!("{}", pass_login.notes),
|
||||
)?;
|
||||
if consent {
|
||||
pass::trash(&vault, pass_login.id);
|
||||
|
||||
+4
-3
@@ -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 mut it = "".to_string();
|
||||
for url in urls {
|
||||
it = format!("{} --field 'url={}'", it, url);
|
||||
it = format!("{} --field 'urls={}'", it, url);
|
||||
}
|
||||
it
|
||||
} else {
|
||||
@@ -160,10 +160,11 @@ pub fn update(vault: &String, item: LoginItem, user_is_actually_email: bool) {
|
||||
format!("--field 'note={}'", item.notes)
|
||||
};
|
||||
|
||||
let output = sh::sh(format!(
|
||||
let cmd = format!(
|
||||
"{} item update --vault-name '{}' --item-id '{}' --field 'password={}' --field '{}' {} {}",
|
||||
EXECUTABLE, vault, item.id, item.password, user_field_update, maybe_urls, maybe_notes
|
||||
));
|
||||
);
|
||||
let output = sh::sh(cmd.clone());
|
||||
println!("> {}", output);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user