🔨 Refactors pass to generate LoginItem's

Signed-off-by: Ash Svitan <selfsigned-ash@proton.me>
This commit is contained in:
2026-04-30 20:16:43 +02:00
parent 631c807571
commit 15dd1722d4
3 changed files with 83 additions and 34 deletions
+41 -2
View File
@@ -25,19 +25,20 @@ pub struct Item {
pub content: ItemContent,
}
#[derive(Deserialize, Debug)]
#[derive(Deserialize, Debug, Clone)]
pub struct ItemContent {
pub title: String,
pub note: String,
pub content: ItemContentContent,
}
#[derive(Deserialize, Debug)]
#[derive(Deserialize, Debug, Clone)]
pub struct ItemContentContent {
#[serde(rename = "Login")]
pub login: Option<ItemLogin>,
}
// pass-cli provided structure, this is what it's called inside the JSON data
#[derive(Deserialize, Debug, Clone)]
pub struct ItemLogin {
pub email: String,
@@ -47,6 +48,18 @@ pub struct ItemLogin {
pub totp_uri: String,
}
// our own custom structure, a counterpart to rbw::LoginItem
#[derive(Debug, Clone)]
pub struct LoginItem {
pub id: String,
pub title: String,
pub username: String,
pub email: String,
pub password: String,
pub urls: Vec<String>,
pub totp_uri: String,
}
pub fn check_pass() -> Result<(), Error> {
let which = sh::sh(format!("which {}", EXECUTABLE));
if which.is_empty() {
@@ -88,3 +101,29 @@ pub fn get_items(vault: &String) -> Result<Items, Error> {
)),
};
}
pub fn get_logins(items: Items) -> Vec<LoginItem> {
items
.items
.iter()
.filter(|item| {
if let None = item.content.content.login {
false
} else {
true
}
})
.map(|item| {
let login = item.content.content.login.clone().unwrap();
LoginItem {
id: item.id.clone(),
title: item.content.title.clone(),
username: login.username,
email: login.email,
password: login.password,
urls: login.urls,
totp_uri: login.totp_uri,
}
})
.collect()
}