🚧 Adds rbw item struct

Signed-off-by: Ash Svitan <selfsigned-ash@proton.me>
This commit is contained in:
2026-04-30 15:31:03 +02:00
parent e61ff4b825
commit 0430ff2bd2
3 changed files with 49 additions and 8 deletions
+7 -1
View File
@@ -1,4 +1,5 @@
mod pass;
mod rbw;
mod sh;
use std::env;
@@ -8,11 +9,16 @@ const ENV_VAR_DEFAULT_VAULT: &str = "PASS_VAULT";
fn main() -> Result<(), Error> {
pass::check_pass()?;
rbw::check_rbw()?;
let vaults = pass::get_vaults().vaults;
if vaults.len() <= 0 {
return Err(Error::new(ErrorKind::Other, "No vaults found"));
}
let vault_names = vaults.iter().map(|vault| vault.name.clone()).collect::<Vec<String>>();
let vault_names = vaults
.iter()
.map(|vault| vault.name.clone())
.collect::<Vec<String>>();
let vault;
match env::var(ENV_VAR_DEFAULT_VAULT) {
+7 -7
View File
@@ -1,24 +1,24 @@
use crate::sh;
use std::io::{Error, ErrorKind};
use serde::Deserialize;
use std::io::{Error, ErrorKind};
const EXECUTABLE: &str = "pass-cli";
#[derive(Deserialize, Debug)]
pub struct Vaults {
pub vaults: Vec<Vault>
pub vaults: Vec<Vault>,
}
#[derive(Deserialize, Debug)]
pub struct Vault {
pub name: String,
pub vault_id: String,
pub share_id: String
pub share_id: String,
}
#[derive(Deserialize, Debug)]
pub struct Items {
pub items: Vec<Item>
pub items: Vec<Item>,
}
#[derive(Deserialize, Debug)]
@@ -29,7 +29,7 @@ pub struct Item {
pub content: ItemContent,
pub state: String,
pub create_time: String,
pub modify_time: String
pub modify_time: String,
}
#[derive(Deserialize, Debug)]
@@ -42,7 +42,7 @@ pub struct ItemContent {
#[derive(Deserialize, Debug)]
pub struct ItemContentContent {
pub Login: Option<ItemLogin>
pub Login: Option<ItemLogin>,
}
#[derive(Deserialize, Debug)]
@@ -51,7 +51,7 @@ pub struct ItemLogin {
pub username: String,
pub password: String,
pub urls: Vec<String>,
pub totp_uri: String
pub totp_uri: String,
}
pub fn check_pass() -> Result<(), Error> {
+35
View File
@@ -0,0 +1,35 @@
use crate::sh;
use serde::Deserialize;
use std::io::{Error, ErrorKind};
const EXECUTABLE: &str = "rbw";
#[derive(Deserialize, Debug)]
pub struct Item {
pub id: String,
pub name: String,
pub user: String,
pub uris: Vec<String>,
#[serde(rename = "type")]
pub type_: String,
}
pub fn check_rbw() -> Result<(), Error> {
let which = sh::sh(format!("which {}", EXECUTABLE));
if which.is_empty() {
return Err(Error::new(
ErrorKind::Other,
format!("{} is not installed", EXECUTABLE),
));
}
let unlocked = sh::sh(format!("{} unlocked", EXECUTABLE));
if !unlocked.is_empty() {
return Err(Error::new(
ErrorKind::Other,
format!("{} database not unlocked", EXECUTABLE),
));
}
return Ok(());
}