✨ Adds getting items from rbw
Signed-off-by: Ash Svitan <selfsigned-ash@proton.me>
This commit is contained in:
+8
-3
@@ -41,9 +41,14 @@ fn main() -> Result<(), Error> {
|
||||
}
|
||||
};
|
||||
|
||||
let items = pass::get_items(&vault)?.items;
|
||||
println!("{:?}", items[0]);
|
||||
println!("{}", items.len());
|
||||
let pass_items = pass::get_items(&vault)?.items;
|
||||
println!("{:?}", pass_items[0]);
|
||||
println!("{}", pass_items.len());
|
||||
|
||||
let rbw_items_partial = rbw::get_items()?;
|
||||
let rbw_items = rbw::get_login_items(rbw_items_partial)?;
|
||||
println!("{:?}", rbw_items[0]);
|
||||
println!("{}", rbw_items.len());
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
+47
-2
@@ -8,8 +8,19 @@ const EXECUTABLE: &str = "rbw";
|
||||
pub struct Item {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub user: String,
|
||||
pub uris: Vec<String>,
|
||||
pub user: Option<String>,
|
||||
pub uris: Option<Vec<String>>,
|
||||
#[serde(rename = "type")]
|
||||
pub type_: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct LoginItem {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub user: Option<String>,
|
||||
pub password: String,
|
||||
pub uris: Option<Vec<String>>,
|
||||
#[serde(rename = "type")]
|
||||
pub type_: String,
|
||||
}
|
||||
@@ -33,3 +44,37 @@ pub fn check_rbw() -> Result<(), Error> {
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn get_items() -> Result<Vec<Item>, Error> {
|
||||
let items_raw = sh::sh(format!("{} list --raw", EXECUTABLE));
|
||||
return match serde_json::from_str(items_raw.as_str()) {
|
||||
Ok(val) => Ok(val),
|
||||
Err(e) => Err(Error::new(
|
||||
ErrorKind::Other,
|
||||
format!("Couldn't get items: {e}"),
|
||||
)),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn get_login_items(items: Vec<Item>) -> Result<Vec<LoginItem>, Error> {
|
||||
let items = items.iter().filter(|item| item.type_ == "Login").collect::<Vec<&Item>>();
|
||||
let mut login_items = Vec::<LoginItem>::new();
|
||||
|
||||
for item in items {
|
||||
let password = sh::sh(format!("{} get '{}'", EXECUTABLE, item.name));
|
||||
if let None = item.user {
|
||||
println!("WARNING: user not found for {}", item.name);
|
||||
}
|
||||
|
||||
login_items.push(LoginItem {
|
||||
id: item.id.clone(),
|
||||
name: item.name.clone(),
|
||||
user: item.user.clone(),
|
||||
password: password,
|
||||
uris: item.uris.clone(),
|
||||
type_: item.type_.clone()
|
||||
});
|
||||
}
|
||||
|
||||
return Ok(login_items);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user