✨ Adds updating fields
Signed-off-by: Ash Svitan <selfsigned-ash@proton.me>
This commit is contained in:
+17
-8
@@ -44,13 +44,15 @@ fn main() -> Result<(), Error> {
|
|||||||
|
|
||||||
let pass_items = pass::get_items(&vault)?;
|
let pass_items = pass::get_items(&vault)?;
|
||||||
let mut pass_logins = pass::get_logins(pass_items);
|
let mut pass_logins = pass::get_logins(pass_items);
|
||||||
println!("{:?}", pass_logins[0]);
|
|
||||||
println!("{}", pass_logins.len());
|
|
||||||
|
|
||||||
let rbw_items = rbw::get_items()?;
|
let rbw_items = rbw::get_items()?;
|
||||||
let mut rbw_logins = rbw::get_logins(rbw_items)?;
|
let mut rbw_logins = rbw::get_logins(rbw_items)?;
|
||||||
println!("{:?}", rbw_logins[0]);
|
|
||||||
println!("{}", rbw_logins.len());
|
println!(
|
||||||
|
"Got {} pass logins and {} rbw logins...",
|
||||||
|
pass_logins.len(),
|
||||||
|
rbw_logins.len()
|
||||||
|
);
|
||||||
|
|
||||||
for rbw_login in rbw_logins.clone().iter() {
|
for rbw_login in rbw_logins.clone().iter() {
|
||||||
let mut pass_login: Option<&pass::LoginItem> = None;
|
let mut pass_login: Option<&pass::LoginItem> = None;
|
||||||
@@ -79,16 +81,23 @@ fn main() -> Result<(), Error> {
|
|||||||
|
|
||||||
if rbw_user != pass_user || rbw_password != pass_password {
|
if rbw_user != pass_user || rbw_password != pass_password {
|
||||||
// TODO: need to update
|
// TODO: need to update
|
||||||
println!("Attempting to update:");
|
println!("Attempting to update {}:", rbw_login.name);
|
||||||
println!("\t{} -> {}", pass_user, rbw_user);
|
println!("\t{} -> {}", pass_user, rbw_user.clone());
|
||||||
println!("\t{} -> {}", pass_password, rbw_password);
|
println!("\t{} -> {}", pass_password, rbw_password.clone());
|
||||||
print!("Proceed? [y/N] ");
|
print!("Proceed? [y/N] ");
|
||||||
io::stdout().flush()?;
|
io::stdout().flush()?;
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
io::stdin().read_line(&mut input)?;
|
io::stdin().read_line(&mut input)?;
|
||||||
|
|
||||||
if input.to_lowercase() == "y\n" {
|
if input.to_lowercase() == "y\n" {
|
||||||
println!("UPDATING!!!");
|
let updated_pass_login = pass::LoginItem {
|
||||||
|
id: pass_login.id.clone(),
|
||||||
|
title: pass_login.title.clone(),
|
||||||
|
username: rbw_user.clone(),
|
||||||
|
email: rbw_user.clone(),
|
||||||
|
password: rbw_password,
|
||||||
|
};
|
||||||
|
pass::update(&vault, updated_pass_login, pass_user_is_actually_email)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-8
@@ -28,7 +28,6 @@ pub struct Item {
|
|||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct ItemContent {
|
pub struct ItemContent {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub note: String,
|
|
||||||
pub content: ItemContentContent,
|
pub content: ItemContentContent,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,8 +43,6 @@ pub struct ItemLogin {
|
|||||||
pub email: String,
|
pub email: String,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
pub urls: Vec<String>,
|
|
||||||
pub totp_uri: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// our own custom structure, a counterpart to rbw::LoginItem
|
// our own custom structure, a counterpart to rbw::LoginItem
|
||||||
@@ -56,8 +53,6 @@ pub struct LoginItem {
|
|||||||
pub username: String,
|
pub username: String,
|
||||||
pub email: String,
|
pub email: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
pub urls: Vec<String>,
|
|
||||||
pub totp_uri: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_pass() -> Result<(), Error> {
|
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> {
|
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()) {
|
return match serde_json::from_str(items_raw.as_str()) {
|
||||||
Ok(val) => Ok(val),
|
Ok(val) => Ok(val),
|
||||||
Err(e) => Err(Error::new(
|
Err(e) => Err(Error::new(
|
||||||
@@ -121,9 +119,22 @@ pub fn get_logins(items: Items) -> Vec<LoginItem> {
|
|||||||
username: login.username,
|
username: login.username,
|
||||||
email: login.email,
|
email: login.email,
|
||||||
password: login.password,
|
password: login.password,
|
||||||
urls: login.urls,
|
|
||||||
totp_uri: login.totp_uri,
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.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(());
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ pub struct Item {
|
|||||||
pub id: String,
|
pub id: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub user: Option<String>,
|
pub user: Option<String>,
|
||||||
pub uris: Option<Vec<String>>,
|
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub type_: String,
|
pub type_: String,
|
||||||
}
|
}
|
||||||
@@ -20,7 +19,6 @@ pub struct LoginItem {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
pub user: String,
|
pub user: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
pub uris: Vec<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_rbw() -> Result<(), Error> {
|
pub fn check_rbw() -> Result<(), Error> {
|
||||||
@@ -78,10 +76,6 @@ pub fn get_logins(items: Vec<Item>) -> Result<Vec<LoginItem>, Error> {
|
|||||||
Some(s) => s.to_string(),
|
Some(s) => s.to_string(),
|
||||||
None => password,
|
None => password,
|
||||||
},
|
},
|
||||||
uris: match item.uris.clone() {
|
|
||||||
Some(val) => val,
|
|
||||||
None => Vec::new(),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user