mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-10 17:43:23 +01:00
Allows Access to write to the underlying database
This commit is contained in:
parent
565a5ed278
commit
8e10381fbd
@ -87,6 +87,20 @@ impl PermissionsProvider {
|
|||||||
Err(e) => { Err(e.into()) }
|
Err(e) => { Err(e.into()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn put_role(&self, txn: &mut RwTransaction, roleID: RoleIdentifier, role: Role) -> Result<()> {
|
||||||
|
let bytes = flexbuffers::to_vec(role)?;
|
||||||
|
txn.put(self.roledb, &roleID.to_ne_bytes(), &bytes, lmdb::WriteFlags::empty())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn put_user(&self, txn: &mut RwTransaction, userID: UserIdentifier, user: User) -> Result<()> {
|
||||||
|
let bytes = flexbuffers::to_vec(user)?;
|
||||||
|
txn.put(self.userdb, &userID.to_ne_bytes(), &bytes, lmdb::WriteFlags::empty())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This line documents init
|
/// This line documents init
|
||||||
@ -94,8 +108,12 @@ pub fn init(log: Logger, config: &Config, env: &lmdb::Environment) -> std::resul
|
|||||||
let mut flags = lmdb::DatabaseFlags::empty();
|
let mut flags = lmdb::DatabaseFlags::empty();
|
||||||
flags.set(lmdb::DatabaseFlags::INTEGER_KEY, true);
|
flags.set(lmdb::DatabaseFlags::INTEGER_KEY, true);
|
||||||
let roledb = env.create_db(Some("role"), flags)?;
|
let roledb = env.create_db(Some("role"), flags)?;
|
||||||
|
debug!(&log, "Opened access database '{}' successfully.", "role");
|
||||||
let permdb = env.create_db(Some("perm"), flags)?;
|
let permdb = env.create_db(Some("perm"), flags)?;
|
||||||
|
debug!(&log, "Opened access database '{}' successfully.", "perm");
|
||||||
let userdb = env.create_db(Some("user"), flags)?;
|
let userdb = env.create_db(Some("user"), flags)?;
|
||||||
|
debug!(&log, "Opened access database '{}' successfully.", "user");
|
||||||
|
info!(&log, "Opened all access databases");
|
||||||
return Ok(PermissionsProvider::new(log, roledb, permdb, userdb));
|
return Ok(PermissionsProvider::new(log, roledb, permdb, userdb));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,9 +100,11 @@ fn main() -> Result<(), Error> {
|
|||||||
// Initialize the LMDB environment. Since this would usually block untill the mmap() finishes
|
// Initialize the LMDB environment. Since this would usually block untill the mmap() finishes
|
||||||
// we wrap it in smol::unblock which runs this as future in a different thread.
|
// we wrap it in smol::unblock which runs this as future in a different thread.
|
||||||
let e_config = config.clone();
|
let e_config = config.clone();
|
||||||
|
info!(log, "LMDB env");
|
||||||
let env = lmdb::Environment::new()
|
let env = lmdb::Environment::new()
|
||||||
|
.set_flags(lmdb::EnvironmentFlags::MAP_ASYNC | lmdb::EnvironmentFlags::NO_SUB_DIR)
|
||||||
.set_max_dbs(LMDB_MAX_DB as libc::c_uint)
|
.set_max_dbs(LMDB_MAX_DB as libc::c_uint)
|
||||||
.open(&e_config.db)?;
|
.open(&PathBuf::from_str("/tmp/a.db").unwrap())?;
|
||||||
|
|
||||||
// Start loading the machine database, authentication system and permission system
|
// Start loading the machine database, authentication system and permission system
|
||||||
// All of those get a custom logger so the source of a log message can be better traced and
|
// All of those get a custom logger so the source of a log message can be better traced and
|
||||||
|
Loading…
Reference in New Issue
Block a user