#[cfg(any(test, feature = "test-support"))]
use std::collections::BTreeMap;
pub trait AuthContext: Send + Sync {
fn env(&self, name: &str) -> Option<String>;
}
#[derive(Debug, Clone, Copy, Default)]
pub struct ProcessAuthContext;
impl AuthContext for ProcessAuthContext {
fn env(&self, name: &str) -> Option<String> {
std::env::var(name)
.ok()
.filter(|value| !value.trim().is_empty())
}
}
#[cfg(any(test, feature = "test-support"))]
#[derive(Debug, Clone, Default)]
pub struct MapAuthContext {
env: BTreeMap<String, String>,
}
#[cfg(any(test, feature = "test-support"))]
impl MapAuthContext {
pub fn new() -> Self {
Self::default()
}
pub fn with_env(mut self, name: &str, value: &str) -> Self {
self.env.insert(name.to_string(), value.to_string());
self
}
}
#[cfg(any(test, feature = "test-support"))]
impl AuthContext for MapAuthContext {
fn env(&self, name: &str) -> Option<String> {
self.env
.get(name)
.filter(|value| !value.trim().is_empty())
.cloned()
}
}