Expose user manager in request

This commit is contained in:
Emii Tatsuo 2020-11-26 21:04:02 -05:00
parent e83f2ca109
commit 47c6fae79f
Signed by: Emi
GPG Key ID: 68FAB2E2E6DFC98B
2 changed files with 11 additions and 3 deletions

View File

@ -126,6 +126,14 @@ impl Request {
{
Ok(self.manager.get_user(self.certificate())?)
}
#[cfg(feature="user_management")]
/// Expose the server's UserManager
///
/// Can be used to query users, or directly access the database
pub fn user_manager(&self) -> &UserManager {
&self.manager
}
}
impl ops::Deref for Request {

View File

@ -26,7 +26,7 @@ struct CertificateDef(Vec<u8>);
///
/// Wraps a [`sled::Db`]
pub struct UserManager {
db: sled::Db,
pub db: sled::Db,
pub (crate) users: sled::Tree, // user_id:String maps to data:UserData
pub (crate) certificates: sled::Tree, // certificate:u64 maps to data:CertificateData
}
@ -40,8 +40,8 @@ impl UserManager {
pub fn new(dir: impl AsRef<Path>) -> Result<Self> {
let db = sled::open(dir)?;
Ok(Self {
users: db.open_tree("users")?,
certificates: db.open_tree("certificates")?,
users: db.open_tree("gay.emii.kochab.users")?,
certificates: db.open_tree("gay.emii.kochab.certificates")?,
db,
})
}