pulseengine_mcp_auth/
storage.rs

1//! Storage backend for authentication data
2
3use crate::models::ApiKey;
4use async_trait::async_trait;
5use std::collections::HashMap;
6use thiserror::Error;
7
8#[derive(Debug, Error)]
9pub enum StorageError {
10    #[error("Storage error: {0}")]
11    General(String),
12}
13
14/// Storage backend trait
15#[async_trait]
16pub trait StorageBackend: Send + Sync {
17    async fn load_keys(&self) -> Result<HashMap<String, ApiKey>, StorageError>;
18    async fn save_key(&self, key: &ApiKey) -> Result<(), StorageError>;
19    async fn delete_key(&self, key_id: &str) -> Result<(), StorageError>;
20}
21
22/// File-based storage backend
23pub struct FileStorage {
24    #[allow(dead_code)]
25    path: std::path::PathBuf,
26}
27
28impl FileStorage {
29    pub fn new(path: std::path::PathBuf) -> Self {
30        Self { path }
31    }
32}
33
34#[async_trait]
35impl StorageBackend for FileStorage {
36    async fn load_keys(&self) -> Result<HashMap<String, ApiKey>, StorageError> {
37        Ok(HashMap::new())
38    }
39
40    async fn save_key(&self, _key: &ApiKey) -> Result<(), StorageError> {
41        Ok(())
42    }
43
44    async fn delete_key(&self, _key_id: &str) -> Result<(), StorageError> {
45        Ok(())
46    }
47}
48
49/// Environment variable storage backend
50pub struct EnvironmentStorage {
51    #[allow(dead_code)]
52    prefix: String,
53}
54
55impl EnvironmentStorage {
56    pub fn new(prefix: String) -> Self {
57        Self { prefix }
58    }
59}
60
61#[async_trait]
62impl StorageBackend for EnvironmentStorage {
63    async fn load_keys(&self) -> Result<HashMap<String, ApiKey>, StorageError> {
64        Ok(HashMap::new())
65    }
66
67    async fn save_key(&self, _key: &ApiKey) -> Result<(), StorageError> {
68        Ok(())
69    }
70
71    async fn delete_key(&self, _key_id: &str) -> Result<(), StorageError> {
72        Ok(())
73    }
74}