mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 06:47:56 +01:00
Put the users in the db as well
This commit is contained in:
parent
78e7d45614
commit
8f5cea673b
@ -28,6 +28,7 @@ pub struct Databases {
|
||||
pub access: Arc<access::AccessControl>,
|
||||
pub machine: Arc<machine::internal::Internal>,
|
||||
pub passdb: Arc<pass::PassDB>,
|
||||
pub userdb: Arc<user::Internal>,
|
||||
}
|
||||
|
||||
const LMDB_MAX_DB: u32 = 16;
|
||||
@ -55,10 +56,13 @@ impl Databases {
|
||||
|
||||
let passdb = pass::PassDB::init(log.new(o!("system" => "passwords")), env.clone()).unwrap();
|
||||
|
||||
let userdb = user::init(log.new(o!("system" => "users")), &config, env.clone())?;
|
||||
|
||||
Ok(Self {
|
||||
access: Arc::new(ac),
|
||||
passdb: Arc::new(passdb),
|
||||
machine: Arc::new(mdb)
|
||||
machine: Arc::new(mdb),
|
||||
userdb: Arc::new(userdb),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -4,14 +4,19 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
use std::fmt;
|
||||
use std::fs;
|
||||
use std::sync::Arc;
|
||||
use std::iter::FromIterator;
|
||||
use std::path::Path;
|
||||
use crate::db::access::RoleIdentifier;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use slog::Logger;
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::config::Config;
|
||||
|
||||
mod internal;
|
||||
pub use internal::Internal;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
/// An user
|
||||
@ -117,6 +122,15 @@ pub fn load_file<P: AsRef<Path>>(path: P) -> Result<HashMap<String, User>> {
|
||||
)))
|
||||
}
|
||||
|
||||
pub fn init(log: Logger, config: &Config, env: Arc<lmdb::Environment>) -> Result<Internal> {
|
||||
let mut flags = lmdb::DatabaseFlags::empty();
|
||||
flags.set(lmdb::DatabaseFlags::INTEGER_KEY, true);
|
||||
let db = env.create_db(Some("users"), flags)?;
|
||||
debug!(&log, "Opened user db successfully.");
|
||||
|
||||
Ok(Internal::new(log, env, db))
|
||||
}
|
||||
|
||||
#[cfg(test_DISABLED)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
28
src/main.rs
28
src/main.rs
@ -122,23 +122,27 @@ fn main() {
|
||||
// Returning a `Result` from `main` allows us to use the `?` shorthand.
|
||||
// In the case of an Err it will be printed using `fmt::Debug`
|
||||
fn maybe(matches: clap::ArgMatches, log: Arc<Logger>) -> Result<(), Error> {
|
||||
|
||||
if matches.is_present("dump") {
|
||||
error!(log, "Dumping is currently not implemented");
|
||||
Ok(())
|
||||
} else if matches.is_present("load") {
|
||||
let mut dir = PathBuf::from(matches.value_of_os("load").unwrap());
|
||||
dir.push("users.toml");
|
||||
let map = db::user::load_file(&dir);
|
||||
debug!(log, "Loaded users: {:?}", map);
|
||||
dir.pop();
|
||||
Ok(())
|
||||
} else {
|
||||
// If no `config` option is given use a preset default.
|
||||
let configpath = matches.value_of("config").unwrap_or("/etc/bffh/config.toml");
|
||||
let config = config::read(&PathBuf::from_str(configpath).unwrap())?;
|
||||
debug!(log, "Loaded Config: {:?}", config);
|
||||
|
||||
if matches.is_present("dump") {
|
||||
error!(log, "Dumping is currently not implemented");
|
||||
Ok(())
|
||||
} else if matches.is_present("load") {
|
||||
let db = db::Databases::new(&log, &config)?;
|
||||
|
||||
let mut dir = PathBuf::from(matches.value_of_os("load").unwrap());
|
||||
dir.push("users.toml");
|
||||
let map = db::user::load_file(&dir)?;
|
||||
for (uid,user) in map.iter() {
|
||||
db.userdb.put_user(uid, user)?;
|
||||
}
|
||||
debug!(log, "Loaded users: {:?}", map);
|
||||
dir.pop();
|
||||
Ok(())
|
||||
} else {
|
||||
let ex = Executor::new();
|
||||
|
||||
let mqtt = AsyncClient::new(config.mqtt_url.clone())?;
|
||||
|
Loading…
Reference in New Issue
Block a user