Skip to main content

praxis_policy_session_valkey/
factory.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 Praxis Contributors
3
4// `ValkeySessionStoreFactory` — the `SessionStoreFactory` that lets the
5// praxis-policy-apl-runtime visitor build a `ValkeySessionStore` from a
6// `global.apl.session_store: { kind: valkey, ... }` block. Mirrors the
7// PDP factories (CelPdpFactory, CedarDirectPdpFactory).
8
9use std::sync::Arc;
10
11use praxis_policy_apl_runtime::{SessionStore, SessionStoreFactory};
12
13use crate::config::ValkeyConfig;
14use crate::store::ValkeySessionStore;
15
16/// The `kind:` discriminator this factory builds. Part of the public
17/// surface — it is the string operators write in their config.
18pub const KIND: &str = "valkey";
19
20/// Factory the host registers via `AplOptions.session_store_factories`.
21#[derive(Default)]
22pub struct ValkeySessionStoreFactory;
23
24impl ValkeySessionStoreFactory {
25    /// A new instance with nothing registered or stored yet.
26    pub fn new() -> Self {
27        Self
28    }
29}
30
31impl SessionStoreFactory for ValkeySessionStoreFactory {
32    fn kind(&self) -> &str {
33        KIND
34    }
35
36    fn build(
37        &self,
38        config: &serde_yaml::Value,
39    ) -> Result<Arc<dyn SessionStore>, Box<dyn std::error::Error + Send + Sync>> {
40        let cfg = ValkeyConfig::from_value(config)?;
41        let store = ValkeySessionStore::from_config(&cfg)?;
42        Ok(Arc::new(store))
43    }
44}