Skip to main content

aa_storage/
factory.rs

1//! Factory traits that build a storage backend from its TOML subsection.
2//!
3//! A driver crate implements the factory for each storage kind it provides and
4//! registers it on the [`Registry`](crate::Registry). The loader then calls the
5//! factory with the driver's `[storage.<name>]` subsection (as a
6//! [`toml::Value`]) to construct the trait object.
7
8use std::sync::Arc;
9
10use crate::{AuditSink, CredentialStore, LifecycleStore, PolicyStore, RateLimitCounter, Result, SessionStore};
11
12/// Builds a [`PolicyStore`] from its `[storage.<name>]` TOML subsection.
13pub trait PolicyStoreFactory: Send + Sync {
14    /// Construct the policy-store backend from its config subsection.
15    fn build(&self, config: &toml::Value) -> Result<Arc<dyn PolicyStore>>;
16}
17
18/// Builds an [`AuditSink`] from its `[storage.<name>]` TOML subsection.
19pub trait AuditSinkFactory: Send + Sync {
20    /// Construct the audit-sink backend from its config subsection.
21    fn build(&self, config: &toml::Value) -> Result<Arc<dyn AuditSink>>;
22}
23
24/// Builds a [`SessionStore`] from its `[storage.<name>]` TOML subsection.
25pub trait SessionStoreFactory: Send + Sync {
26    /// Construct the session-store backend from its config subsection.
27    fn build(&self, config: &toml::Value) -> Result<Arc<dyn SessionStore>>;
28}
29
30/// Builds a [`CredentialStore`] from its `[storage.<name>]` TOML subsection.
31pub trait CredentialStoreFactory: Send + Sync {
32    /// Construct the credential-store backend from its config subsection.
33    fn build(&self, config: &toml::Value) -> Result<Arc<dyn CredentialStore>>;
34}
35
36/// Builds a [`RateLimitCounter`] from its `[storage.<name>]` TOML subsection.
37pub trait RateLimitCounterFactory: Send + Sync {
38    /// Construct the rate-limit-counter backend from its config subsection.
39    fn build(&self, config: &toml::Value) -> Result<Arc<dyn RateLimitCounter>>;
40}
41
42/// Builds a [`LifecycleStore`] from its `[storage.<name>]` TOML subsection.
43pub trait LifecycleStoreFactory: Send + Sync {
44    /// Construct the lifecycle-store backend from its config subsection.
45    fn build(&self, config: &toml::Value) -> Result<Arc<dyn LifecycleStore>>;
46}