🚧 Adds rbw item struct
Signed-off-by: Ash Svitan <selfsigned-ash@proton.me>
This commit is contained in:
+7
-1
@@ -1,4 +1,5 @@
|
|||||||
mod pass;
|
mod pass;
|
||||||
|
mod rbw;
|
||||||
mod sh;
|
mod sh;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
@@ -8,11 +9,16 @@ const ENV_VAR_DEFAULT_VAULT: &str = "PASS_VAULT";
|
|||||||
|
|
||||||
fn main() -> Result<(), Error> {
|
fn main() -> Result<(), Error> {
|
||||||
pass::check_pass()?;
|
pass::check_pass()?;
|
||||||
|
rbw::check_rbw()?;
|
||||||
|
|
||||||
let vaults = pass::get_vaults().vaults;
|
let vaults = pass::get_vaults().vaults;
|
||||||
if vaults.len() <= 0 {
|
if vaults.len() <= 0 {
|
||||||
return Err(Error::new(ErrorKind::Other, "No vaults found"));
|
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;
|
let vault;
|
||||||
match env::var(ENV_VAR_DEFAULT_VAULT) {
|
match env::var(ENV_VAR_DEFAULT_VAULT) {
|
||||||
|
|||||||
+7
-7
@@ -1,24 +1,24 @@
|
|||||||
use crate::sh;
|
use crate::sh;
|
||||||
use std::io::{Error, ErrorKind};
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::io::{Error, ErrorKind};
|
||||||
|
|
||||||
const EXECUTABLE: &str = "pass-cli";
|
const EXECUTABLE: &str = "pass-cli";
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct Vaults {
|
pub struct Vaults {
|
||||||
pub vaults: Vec<Vault>
|
pub vaults: Vec<Vault>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct Vault {
|
pub struct Vault {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub vault_id: String,
|
pub vault_id: String,
|
||||||
pub share_id: String
|
pub share_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct Items {
|
pub struct Items {
|
||||||
pub items: Vec<Item>
|
pub items: Vec<Item>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
@@ -29,7 +29,7 @@ pub struct Item {
|
|||||||
pub content: ItemContent,
|
pub content: ItemContent,
|
||||||
pub state: String,
|
pub state: String,
|
||||||
pub create_time: String,
|
pub create_time: String,
|
||||||
pub modify_time: String
|
pub modify_time: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
@@ -42,7 +42,7 @@ pub struct ItemContent {
|
|||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct ItemContentContent {
|
pub struct ItemContentContent {
|
||||||
pub Login: Option<ItemLogin>
|
pub Login: Option<ItemLogin>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
@@ -51,7 +51,7 @@ pub struct ItemLogin {
|
|||||||
pub username: String,
|
pub username: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
pub urls: Vec<String>,
|
pub urls: Vec<String>,
|
||||||
pub totp_uri: String
|
pub totp_uri: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_pass() -> Result<(), Error> {
|
pub fn check_pass() -> Result<(), Error> {
|
||||||
|
|||||||
+35
@@ -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(());
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user