bucketwarden-auth 0.1.0

BucketWarden local identity, access key, and session credential store.
Documentation
use super::*;

impl AuthStore {
    pub fn identity_provider_support_report(&self) -> IdentityProviderSupportReport {
        IdentityProviderSupportReport::current()
    }

    pub fn credential_support_report(&self) -> CredentialSupportReport {
        CredentialSupportReport::current()
    }

    pub fn temporary_credential_support_report(&self) -> TemporaryCredentialSupportReport {
        TemporaryCredentialSupportReport::current()
    }

    pub(crate) fn require_enabled_principal(
        &self,
        principal_id: &str,
    ) -> Result<&Principal, AuthError> {
        let principal = self
            .principals
            .get(principal_id)
            .ok_or_else(|| AuthError::UnknownPrincipal(principal_id.to_string()))?;
        if principal.enabled {
            Ok(principal)
        } else {
            Err(AuthError::DisabledPrincipal(principal_id.to_string()))
        }
    }

    pub(crate) fn require_enabled_tenant(&mut self, tenant_id: &str) -> Result<(), AuthError> {
        if tenant_id == DEFAULT_TENANT_ID && !self.tenants.contains_key(tenant_id) {
            self.create_tenant(DEFAULT_TENANT_ID);
        }
        let tenant = self
            .tenants
            .get(tenant_id)
            .ok_or_else(|| AuthError::UnknownTenant(tenant_id.to_string()))?;
        if tenant.enabled {
            Ok(())
        } else {
            Err(AuthError::DisabledTenant(tenant_id.to_string()))
        }
    }

    pub(crate) fn credential_mut(
        &mut self,
        access_key_id: &str,
    ) -> Result<&mut CredentialRecord, AuthError> {
        self.credentials
            .get_mut(access_key_id)
            .ok_or_else(|| AuthError::UnknownAccessKey(access_key_id.to_string()))
    }
}