pub struct StaticTenantResolver { /* private fields */ }Expand description
Static in-memory tenant resolver for testing and simple deployments.
This implementation stores tenant mappings in memory and is suitable for:
- Development and testing environments
- Simple deployments with a small number of tenants
- Proof-of-concept implementations
For production use with many tenants, consider implementing a database-backed resolver.
§Example Usage
use scim_server::multi_tenant::{StaticTenantResolver, TenantResolver};
use scim_server::{TenantContext, IsolationLevel};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut resolver = StaticTenantResolver::new();
// Add tenant mappings
resolver.add_tenant(
"api-key-tenant-a",
TenantContext::new("tenant-a".to_string(), "client-a".to_string())
.with_isolation_level(IsolationLevel::Strict)
).await;
resolver.add_tenant(
"api-key-tenant-b",
TenantContext::new("tenant-b".to_string(), "client-b".to_string())
).await;
// Resolve tenant from credentials
let tenant_context = resolver.resolve_tenant("api-key-tenant-a").await?;
assert_eq!(tenant_context.tenant_id, "tenant-a");
Ok(())
}Implementations§
Source§impl StaticTenantResolver
impl StaticTenantResolver
Sourcepub async fn add_tenant(&self, credential: &str, tenant_context: TenantContext)
pub async fn add_tenant(&self, credential: &str, tenant_context: TenantContext)
Add a tenant mapping to the resolver.
§Arguments
credential- Authentication credential for the tenanttenant_context- The tenant context to associate with the credential
§Example
use scim_server::multi_tenant::StaticTenantResolver;
use scim_server::TenantContext;
let mut resolver = StaticTenantResolver::new();
resolver.add_tenant(
"api-key-123",
TenantContext::new("tenant-a".to_string(), "client-a".to_string())
);Sourcepub async fn remove_tenant(&self, credential: &str) -> Option<TenantContext>
pub async fn remove_tenant(&self, credential: &str) -> Option<TenantContext>
Sourcepub async fn tenant_count(&self) -> usize
pub async fn tenant_count(&self) -> usize
Get the number of configured tenants.
Sourcepub async fn get_all_credentials(&self) -> Vec<String>
pub async fn get_all_credentials(&self) -> Vec<String>
Get all credentials (useful for testing).
Trait Implementations§
Source§impl Clone for StaticTenantResolver
impl Clone for StaticTenantResolver
Source§fn clone(&self) -> StaticTenantResolver
fn clone(&self) -> StaticTenantResolver
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StaticTenantResolver
impl Debug for StaticTenantResolver
Source§impl Default for StaticTenantResolver
impl Default for StaticTenantResolver
Source§impl TenantResolver for StaticTenantResolver
impl TenantResolver for StaticTenantResolver
Source§type Error = StaticResolverError
type Error = StaticResolverError
Error type for resolver operations
Source§async fn resolve_tenant(
&self,
credential: &str,
) -> Result<TenantContext, Self::Error>
async fn resolve_tenant( &self, credential: &str, ) -> Result<TenantContext, Self::Error>
Resolve a tenant context from authentication credentials. Read more
Source§async fn validate_tenant(&self, tenant_id: &str) -> Result<bool, Self::Error>
async fn validate_tenant(&self, tenant_id: &str) -> Result<bool, Self::Error>
Validate that a tenant exists and is active. Read more
Auto Trait Implementations§
impl Freeze for StaticTenantResolver
impl !RefUnwindSafe for StaticTenantResolver
impl Send for StaticTenantResolver
impl Sync for StaticTenantResolver
impl Unpin for StaticTenantResolver
impl !UnwindSafe for StaticTenantResolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> TenantValidator for T
impl<T> TenantValidator for T
Source§fn validate_tenant_context(
&self,
expected_tenant_id: &str,
context: &RequestContext,
) -> Result<(), String>
fn validate_tenant_context( &self, expected_tenant_id: &str, context: &RequestContext, ) -> Result<(), String>
Validate that the context has the expected tenant.
Source§fn validate_single_tenant_context(
&self,
context: &RequestContext,
) -> Result<(), String>
fn validate_single_tenant_context( &self, context: &RequestContext, ) -> Result<(), String>
Validate that the context is for single-tenant operation.
Source§fn require_tenant_context(&self, context: &RequestContext) -> Result<(), String>
fn require_tenant_context(&self, context: &RequestContext) -> Result<(), String>
Extract tenant context or return error for multi-tenant operations.