aa_storage/config.rs
1//! [`StorageConfig`] — the `[storage]` section of `agent-assembly.toml`.
2
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7use crate::DriverName;
8
9/// The `[storage]` section: which driver backs each storage kind, plus the
10/// per-driver connection subsections.
11///
12/// ```toml
13/// [storage]
14/// policy_store = "redis"
15/// audit_sink = "postgres"
16/// session_store = "redis"
17/// credential_store = "postgres"
18/// rate_limit_counter = "redis"
19/// lifecycle_store = "postgres"
20///
21/// [storage.redis]
22/// url = "redis://localhost:6379"
23///
24/// [storage.postgres]
25/// url = "postgresql://localhost:5432/assembly"
26/// ```
27///
28/// The six driver-kind keys select a backend by [`DriverName`]; every other key
29/// under `[storage]` is a `[storage.<name>]` table captured into [`drivers`]
30/// and handed verbatim to that driver's factory.
31///
32/// [`drivers`]: StorageConfig::drivers
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct StorageConfig {
35 /// Driver backing the [`PolicyStore`](crate::PolicyStore).
36 pub policy_store: DriverName,
37 /// Driver backing the [`AuditSink`](crate::AuditSink).
38 pub audit_sink: DriverName,
39 /// Driver backing the [`SessionStore`](crate::SessionStore).
40 pub session_store: DriverName,
41 /// Driver backing the [`CredentialStore`](crate::CredentialStore).
42 pub credential_store: DriverName,
43 /// Driver backing the [`RateLimitCounter`](crate::RateLimitCounter).
44 pub rate_limit_counter: DriverName,
45 /// Driver backing the [`LifecycleStore`](crate::LifecycleStore).
46 pub lifecycle_store: DriverName,
47 /// Per-driver `[storage.<name>]` subsections, keyed by driver name.
48 ///
49 /// Each value is the raw TOML table for that driver; the driver's own
50 /// factory parses the keys it needs.
51 #[serde(flatten)]
52 pub drivers: HashMap<DriverName, toml::Value>,
53}
54
55impl StorageConfig {
56 /// Return the `[storage.<name>]` subsection for `name`, if present.
57 pub fn driver_section(&self, name: &DriverName) -> Option<&toml::Value> {
58 self.drivers.get(name)
59 }
60}