mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-11 01:53:23 +01:00
Load passdb \o/
This commit is contained in:
parent
d568d46212
commit
d4da25b0d7
1
examples/pass.toml
Normal file
1
examples/pass.toml
Normal file
@ -0,0 +1 @@
|
|||||||
|
Testuser = "secret"
|
@ -1,4 +1,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::fs;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use argon2;
|
use argon2;
|
||||||
use lmdb::{Environment, Transaction, RwTransaction, Cursor};
|
use lmdb::{Environment, Transaction, RwTransaction, Cursor};
|
||||||
@ -53,4 +56,24 @@ impl PassDB {
|
|||||||
txn.put(self.db, &authcid.as_bytes(), &hash.as_bytes(), lmdb::WriteFlags::empty())
|
txn.put(self.db, &authcid.as_bytes(), &hash.as_bytes(), lmdb::WriteFlags::empty())
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn insert_multiple(&self, vec: Vec<(String, String)>) -> Result<()> {
|
||||||
|
let mut txn = self.env.begin_rw_txn()?;
|
||||||
|
for (authcid, password) in vec.iter() {
|
||||||
|
self.store_with_txn(&mut txn, authcid.as_ref(), password.as_bytes())?;
|
||||||
|
}
|
||||||
|
txn.commit()?;
|
||||||
|
|
||||||
|
let v: Vec<&String> = vec.iter().map(|(a,_)| a).collect();
|
||||||
|
debug!(self.log, "Loaded passwords for: {:?}", v);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_file<P: AsRef<Path>>(&self, path: P) -> Result<()> {
|
||||||
|
let f = fs::read(path)?;
|
||||||
|
let mut map: HashMap<String, String> = toml::from_slice(&f)?;
|
||||||
|
|
||||||
|
self.insert_multiple(map.drain().collect())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,10 @@ fn maybe(matches: clap::ArgMatches, log: Arc<Logger>) -> Result<(), Error> {
|
|||||||
db.access.internal.load_roles(&dir)?;
|
db.access.internal.load_roles(&dir)?;
|
||||||
dir.pop();
|
dir.pop();
|
||||||
|
|
||||||
|
dir.push("pass.toml");
|
||||||
|
db.passdb.load_file(&dir);
|
||||||
|
dir.pop();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
let ex = Executor::new();
|
let ex = Executor::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user