✨ Adds update confirmation check
Signed-off-by: Ash Svitan <selfsigned-ash@proton.me>
This commit is contained in:
+29
-20
@@ -3,7 +3,8 @@ mod rbw;
|
||||
mod sh;
|
||||
|
||||
use std::env;
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::io;
|
||||
use std::io::{Error, ErrorKind, Write};
|
||||
|
||||
const ENV_VAR_DEFAULT_VAULT: &str = "PASS_VAULT";
|
||||
|
||||
@@ -56,14 +57,12 @@ fn main() -> Result<(), Error> {
|
||||
|
||||
'inner: for pass_login_iter in pass_logins.iter() {
|
||||
if rbw_login.name == pass_login_iter.title {
|
||||
println!("found match! {}", rbw_login.name);
|
||||
pass_login = Some(pass_login_iter);
|
||||
break 'inner;
|
||||
}
|
||||
}
|
||||
|
||||
if let None = pass_login {
|
||||
println!("no match found for {}!", rbw_login.name);
|
||||
continue;
|
||||
}
|
||||
let pass_login = pass_login.unwrap();
|
||||
@@ -78,29 +77,39 @@ fn main() -> Result<(), Error> {
|
||||
};
|
||||
let pass_user_is_actually_email = pass_user == pass_login.email;
|
||||
|
||||
if rbw_password == pass_password {
|
||||
let rbw_index = rbw_logins
|
||||
.iter()
|
||||
.position(|x| x.id == rbw_login.id)
|
||||
.unwrap();
|
||||
rbw_logins.remove(rbw_index);
|
||||
if rbw_user != pass_user || rbw_password != pass_password {
|
||||
// TODO: need to update
|
||||
println!("Attempting to update:");
|
||||
println!("\t{} -> {}", pass_user, rbw_user);
|
||||
println!("\t{} -> {}", pass_password, rbw_password);
|
||||
print!("Proceed? [y/N] ");
|
||||
io::stdout().flush()?;
|
||||
let mut input = String::new();
|
||||
io::stdin().read_line(&mut input)?;
|
||||
|
||||
let pass_index = pass_logins
|
||||
.iter()
|
||||
.position(|x| x.id == pass_login.id)
|
||||
.unwrap();
|
||||
pass_logins.remove(pass_index);
|
||||
continue;
|
||||
} else {
|
||||
println!(
|
||||
"password doesn't match! '{}' / '{}'",
|
||||
rbw_password, pass_password
|
||||
);
|
||||
if input.to_lowercase() == "y\n" {
|
||||
println!("UPDATING!!!");
|
||||
}
|
||||
}
|
||||
|
||||
let rbw_index = rbw_logins
|
||||
.iter()
|
||||
.position(|x| x.id == rbw_login.id)
|
||||
.unwrap();
|
||||
rbw_logins.remove(rbw_index);
|
||||
|
||||
let pass_index = pass_logins
|
||||
.iter()
|
||||
.position(|x| x.id == pass_login.id)
|
||||
.unwrap();
|
||||
pass_logins.remove(pass_index);
|
||||
}
|
||||
|
||||
// TODO: need to create these
|
||||
println!("remaining {} rbw items", rbw_logins.len());
|
||||
println!("{:?}", rbw_logins);
|
||||
|
||||
// TODO: need to delete these
|
||||
println!("remaining {} pass items", pass_logins.len());
|
||||
println!("{:?}", pass_logins);
|
||||
|
||||
|
||||
+11
-8
@@ -18,11 +18,9 @@ pub struct Item {
|
||||
pub struct LoginItem {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub user: Option<String>,
|
||||
pub user: String,
|
||||
pub password: String,
|
||||
pub uris: Option<Vec<String>>,
|
||||
#[serde(rename = "type")]
|
||||
pub type_: String,
|
||||
pub uris: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn check_rbw() -> Result<(), Error> {
|
||||
@@ -59,7 +57,7 @@ pub fn get_items() -> Result<Vec<Item>, Error> {
|
||||
pub fn get_logins(items: Vec<Item>) -> Result<Vec<LoginItem>, Error> {
|
||||
let items = items
|
||||
.iter()
|
||||
.filter(|item| item.type_ == "Login")
|
||||
.filter(|item| item.type_.to_lowercase() == "login")
|
||||
.collect::<Vec<&Item>>();
|
||||
let mut login_items = Vec::<LoginItem>::new();
|
||||
|
||||
@@ -72,13 +70,18 @@ pub fn get_logins(items: Vec<Item>) -> Result<Vec<LoginItem>, Error> {
|
||||
login_items.push(LoginItem {
|
||||
id: item.id.clone(),
|
||||
name: item.name.clone(),
|
||||
user: item.user.clone(),
|
||||
user: match item.user.clone() {
|
||||
Some(val) => val,
|
||||
None => "".to_string(),
|
||||
},
|
||||
password: match password.strip_suffix("\n") {
|
||||
Some(s) => s.to_string(),
|
||||
None => password,
|
||||
},
|
||||
uris: item.uris.clone(),
|
||||
type_: item.type_.clone(),
|
||||
uris: match item.uris.clone() {
|
||||
Some(val) => val,
|
||||
None => Vec::new(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user