updated get to operate against the new schema

master
Tom Alexander 5 years ago
parent a9b3c14b47
commit b362561466

@ -19,7 +19,7 @@ foil
Usage:
foil set [--db=<db>]
foil get [--db=<db>]
foil get [--namespace=<ns>] [--db=<db>]
foil list [--db=<db>]
foil transfer [--db=<db>]
foil dump [--db=<db>]
@ -27,9 +27,10 @@ Usage:
foil (-h | --help)
Options:
--db=<db> The path to the sqlite database [default: db.sqlite3].
-h --help Show this screen.
--version Show version.
--db=<db> The path to the sqlite database [default: db.sqlite3].
-n DB, --namespace=<db> An identifier for a group of secrets [default: main]
-h, --help Show this screen.
--version Show version.
";
#[derive(Debug, Deserialize)]
@ -41,6 +42,7 @@ struct Args {
cmd_transfer: bool,
cmd_dump: bool,
flag_db: Option<String>,
flag_namespace: String,
arg_spec: Option<String>,
}
@ -65,10 +67,6 @@ fn get_master_key(db_conn: &mut db::DbHandle) -> [u8; 32] {
let master_key: [u8; 32] = {
let master_password = PasswordInput::with_theme(&ColorfulTheme::default())
.with_prompt("Master password")
.with_confirmation(
"Repeat master password",
"Error: the passwords don't match.",
)
.interact()
.unwrap();
crypt::get_master_key(&db_conn, &master_password).unwrap()
@ -104,17 +102,20 @@ fn list(mut db_conn: db::DbHandle, master_key: [u8; 32]) {
}
}
fn get(mut db_conn: db::DbHandle, master_key: [u8; 32]) {
fn get(mut db_conn: db::DbHandle, master_key: [u8; 32], namespace: &str) {
println!("Reading a site from the database");
let host: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("hostname")
.interact()
.unwrap();
for account in db_conn.list_accounts(master_key) {
if account.host == host {
println!("username: {}", account.user);
println!("password: {}", account.password);
for note in db_conn.read_notes(master_key).unwrap() {
if note.namespace == namespace && note.title == host && note.category == "account" {
println!("===== note =====");
println!("namespace: {}", note.namespace);
println!("category: {}", note.category);
println!("title: {}", note.title);
println!("{}", note.value);
}
}
}
@ -189,7 +190,7 @@ fn main() -> Result<(), Box<dyn Error>> {
if args.cmd_set {
set(db_conn, master_key);
} else if args.cmd_get {
get(db_conn, master_key);
get(db_conn, master_key, &args.flag_namespace);
} else if args.cmd_list {
list(db_conn, master_key);
} else if args.cmd_transfer {

Loading…
Cancel
Save