2022-03-15 17:52:47 +01:00
|
|
|
use std::path::PathBuf;
|
2022-03-12 17:31:53 +01:00
|
|
|
use std::sync::Arc;
|
2022-03-15 17:52:47 +01:00
|
|
|
use anyhow::Context;
|
|
|
|
use lmdb::Environment;
|
|
|
|
use once_cell::sync::OnceCell;
|
2022-03-13 17:29:21 +01:00
|
|
|
use crate::authorization::roles::Role;
|
|
|
|
use crate::resources::Resource;
|
2022-03-15 17:52:47 +01:00
|
|
|
use crate::session::db::SessionCache;
|
|
|
|
use crate::Users;
|
|
|
|
use crate::users::UserRef;
|
2022-03-12 17:31:53 +01:00
|
|
|
|
2022-03-15 17:52:47 +01:00
|
|
|
mod db;
|
2022-03-12 17:31:53 +01:00
|
|
|
|
2022-03-15 17:52:47 +01:00
|
|
|
static SESSION_CACHE: OnceCell<SessionCache> = OnceCell::new();
|
2022-03-12 17:31:53 +01:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct SessionManager {
|
2022-03-15 17:52:47 +01:00
|
|
|
users: Users,
|
2022-03-12 17:31:53 +01:00
|
|
|
}
|
|
|
|
impl SessionManager {
|
2022-03-15 17:52:47 +01:00
|
|
|
pub fn new(users: Users) -> Self {
|
|
|
|
Self { users }
|
2022-03-12 17:31:53 +01:00
|
|
|
}
|
2022-03-15 17:52:47 +01:00
|
|
|
|
|
|
|
// TODO: make infallible
|
2022-03-12 17:31:53 +01:00
|
|
|
pub fn open(&self, uid: impl AsRef<str>) -> Option<SessionHandle> {
|
2022-03-15 17:52:47 +01:00
|
|
|
let uid = uid.as_ref();
|
|
|
|
if let Some(user) = self.users.get_user(uid) {
|
|
|
|
tracing::trace!(uid, "opening new session for user");
|
|
|
|
Some(SessionHandle { user: UserRef::new(user.id) })
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2022-03-12 17:31:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct SessionHandle {
|
2022-03-15 17:52:47 +01:00
|
|
|
user: UserRef,
|
2022-03-12 17:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SessionHandle {
|
2022-03-15 17:52:47 +01:00
|
|
|
pub fn get_user(&self) -> UserRef {
|
2022-03-13 17:29:21 +01:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has_disclose(&self, resource: &Resource) -> bool {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
pub fn has_read(&self, resource: &Resource) -> bool {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
pub fn has_write(&self, resource: &Resource) -> bool {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
pub fn has_manage(&self, resource: &Resource) -> bool {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2022-03-12 17:31:53 +01:00
|
|
|
}
|