Skip to main content

v_common/storage/
authorization_provider.rs

1use v_authorization_lmdb_impl::LmdbAzContext;
2use crate::v_authorization::common::{AuthorizationContext, Trace};
3use futures::lock::Mutex;
4use std::io;
5
6/// Unified authorization provider
7pub enum AuthorizationProvider {
8    /// LMDB-backed authorization (sync calls via async mutex)
9    Lmdb(Mutex<LmdbAzContext>),
10}
11
12impl AuthorizationProvider {
13    /// Create LMDB-backed authorization provider
14    pub fn from_lmdb(ctx: LmdbAzContext) -> Self {
15        Self::Lmdb(Mutex::new(ctx))
16    }
17
18    /// Authorize access (async interface)
19    pub async fn authorize(
20        &self,
21        uri: &str,
22        user_uri: &str,
23        request_access: u8,
24        is_check_for_reload: bool,
25    ) -> io::Result<u8> {
26        match self {
27            Self::Lmdb(ctx) => {
28                ctx.lock().await.authorize(uri, user_uri, request_access, is_check_for_reload)
29            }
30        }
31    }
32
33    /// Authorize access with trace information
34    pub async fn authorize_and_trace(
35        &self,
36        uri: &str,
37        user_uri: &str,
38        request_access: u8,
39        is_check_for_reload: bool,
40        trace: &mut Trace<'_>,
41    ) -> io::Result<u8> {
42        match self {
43            Self::Lmdb(ctx) => {
44                ctx.lock().await.authorize_and_trace(uri, user_uri, request_access, is_check_for_reload, trace)
45            }
46        }
47    }
48}