use v_authorization_lmdb_impl::LmdbAzContext;
use crate::v_authorization::common::{AuthorizationContext, Trace};
use futures::lock::Mutex;
use std::io;
pub enum AuthorizationProvider {
Lmdb(Mutex<LmdbAzContext>),
}
impl AuthorizationProvider {
pub fn from_lmdb(ctx: LmdbAzContext) -> Self {
Self::Lmdb(Mutex::new(ctx))
}
pub async fn authorize(
&self,
uri: &str,
user_uri: &str,
request_access: u8,
is_check_for_reload: bool,
) -> io::Result<u8> {
match self {
Self::Lmdb(ctx) => {
ctx.lock().await.authorize(uri, user_uri, request_access, is_check_for_reload)
}
}
}
pub async fn authorize_and_trace(
&self,
uri: &str,
user_uri: &str,
request_access: u8,
is_check_for_reload: bool,
trace: &mut Trace<'_>,
) -> io::Result<u8> {
match self {
Self::Lmdb(ctx) => {
ctx.lock().await.authorize_and_trace(uri, user_uri, request_access, is_check_for_reload, trace)
}
}
}
}