use std::borrow::Cow;
use std::collections::HashMap;
use std::sync::Arc;
use crate::AuthenticError;
use super::AuthenticationCredential;
pub struct FetchedHttpRealmCredentials<Credential> {
realm_credentials: HashMap<Cow<'static, str>, Arc<Credential>>,
}
pub struct HttpRealmCredentials<Credential> {
current: Arc<FetchedHttpRealmCredentials<Credential>>,
}
impl<Credential> HttpRealmCredentials<Credential> {
pub fn new(realm_credentials: HashMap<Cow<'static, str>, Arc<Credential>>) -> Self {
Self {
current: Arc::new(FetchedHttpRealmCredentials { realm_credentials }),
}
}
}
impl<Credential> AuthenticationCredential for HttpRealmCredentials<Credential> {
type Fetch = Arc<FetchedHttpRealmCredentials<Credential>>;
fn fetch(&self) -> Result<Self::Fetch, AuthenticError> {
Ok(self.current.clone())
}
}
impl<Credential> FetchedHttpRealmCredentials<Credential> {
pub fn credential(&self, realm: &str) -> Option<&Arc<Credential>> {
self.realm_credentials.get(realm)
}
}