Struct StaticTenantResolver

Source
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

Source

pub fn new() -> Self

Create a new empty static tenant resolver.

Source

pub async fn add_tenant(&self, credential: &str, tenant_context: TenantContext)

Add a tenant mapping to the resolver.

§Arguments
  • credential - Authentication credential for the tenant
  • tenant_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())
);
Source

pub async fn remove_tenant(&self, credential: &str) -> Option<TenantContext>

Remove a tenant mapping from the resolver.

§Arguments
  • credential - Authentication credential to remove
§Returns

The removed tenant context, if it existed

Source

pub async fn tenant_count(&self) -> usize

Get the number of configured tenants.

Source

pub async fn clear(&self)

Clear all tenant mappings.

Source

pub async fn get_all_credentials(&self) -> Vec<String>

Get all credentials (useful for testing).

Trait Implementations§

Source§

impl Clone for StaticTenantResolver

Source§

fn clone(&self) -> StaticTenantResolver

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StaticTenantResolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StaticTenantResolver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl TenantResolver for StaticTenantResolver

Source§

type Error = StaticResolverError

Error type for resolver operations
Source§

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>

Validate that a tenant exists and is active. Read more
Source§

async fn list_tenants(&self) -> Result<Vec<String>, Self::Error>

Get all active tenant IDs (useful for admin operations). Read more
Source§

fn is_valid_credential( &self, credential: &str, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Check if a credential is valid without returning the full context. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> TenantValidator for T

Source§

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>

Validate that the context is for single-tenant operation.
Source§

fn require_tenant_context(&self, context: &RequestContext) -> Result<(), String>

Extract tenant context or return error for multi-tenant operations.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.