updated get to operate against the new schema

master
Tom Alexander 5 years ago
parent a9b3c14b47
commit b362561466

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

Loading…
Cancel
Save