#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct TenantId(pub [u8; 16]);
impl TenantId {
pub const ZERO: Self = Self([0; 16]);
pub const LEN: usize = 16;
#[must_use]
pub fn is_zero(&self) -> bool {
self.0 == [0; 16]
}
#[must_use]
pub fn as_bytes(&self) -> &[u8; 16] {
&self.0
}
#[must_use]
pub fn from_bytes(b: [u8; 16]) -> Self {
Self(b)
}
}
impl std::fmt::Display for TenantId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for b in self.0 {
write!(f, "{b:02x}")?;
}
Ok(())
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
pub enum AnonymousPolicy {
#[default]
Lenient,
Strict,
}
pub trait TenantBackend: Send + Sync {
fn verify_login(&self, user: &str, password: &[u8]) -> Option<TenantId>;
fn has_tenant(&self, id: TenantId) -> bool;
fn anonymous_policy(&self) -> AnonymousPolicy {
AnonymousPolicy::Lenient
}
fn limits(&self, id: TenantId) -> crate::quota::TenantLimits {
let _ = id;
crate::quota::TenantLimits::default()
}
fn is_admin(&self, id: TenantId) -> bool {
let _ = id;
false
}
fn resolve_tenant(&self, name: &str) -> Option<TenantId> {
let _ = name;
None
}
fn set_limits(
&self,
id: TenantId,
limits: crate::quota::TenantLimits,
) -> Result<(), QuotaAdminError> {
let _ = (id, limits);
Err(QuotaAdminError::Unsupported)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum QuotaAdminError {
Unsupported,
}