Skip to main content

auth_framework/tenant/
mod.rs

1//! Multi-tenant support for AuthFramework
2//!
3//! This module provides native multi-tenant capabilities, allowing multiple
4//! isolated authentication and authorization contexts to coexist within
5//! the same process with complete data isolation.
6
7pub mod context;
8pub mod registry;
9
10pub use context::{TenantContext, TenantId, TenantMetadata};
11pub use registry::{TenantRegistry, TenantRegistryError};
12
13use crate::config::AuthConfig;
14
15/// Builder for creating TenantRegistry instances
16pub struct TenantRegistryBuilder {
17    default_config: AuthConfig,
18}
19
20impl TenantRegistryBuilder {
21    /// Create a new TenantRegistryBuilder with default config
22    pub fn new() -> Self {
23        Self {
24            default_config: AuthConfig::default(),
25        }
26    }
27
28    /// Set the default configuration for new tenants
29    pub fn with_config(mut self, config: AuthConfig) -> Self {
30        self.default_config = config;
31        self
32    }
33
34    /// Build the TenantRegistry
35    pub fn build(self) -> TenantRegistry {
36        TenantRegistry::new(self.default_config)
37    }
38}
39
40impl Default for TenantRegistryBuilder {
41    fn default() -> Self {
42        Self::new()
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[tokio::test]
51    async fn test_tenant_registry_builder() {
52        let registry = TenantRegistryBuilder::new().build();
53        assert_eq!(registry.tenant_count().await, 0);
54    }
55}