pulseengine_mcp_auth/
config.rs

1//! Authentication configuration
2
3use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6/// Authentication configuration
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct AuthConfig {
9    /// Storage backend configuration
10    pub storage: StorageConfig,
11    /// Enable authentication (if false, all requests are allowed)
12    pub enabled: bool,
13    /// Cache size for API keys
14    pub cache_size: usize,
15    /// Session timeout in seconds
16    pub session_timeout_secs: u64,
17    /// Maximum failed attempts before rate limiting
18    pub max_failed_attempts: u32,
19    /// Rate limiting window in seconds
20    pub rate_limit_window_secs: u64,
21}
22
23/// Storage configuration for authentication data
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub enum StorageConfig {
26    /// File-based storage
27    File {
28        /// Path to storage directory
29        path: PathBuf,
30    },
31    /// Environment variable storage
32    Environment {
33        /// Prefix for environment variables
34        prefix: String,
35    },
36    /// Memory-only storage (for testing)
37    Memory,
38}
39
40impl Default for AuthConfig {
41    fn default() -> Self {
42        Self {
43            storage: StorageConfig::File {
44                path: dirs::home_dir()
45                    .unwrap_or_else(|| PathBuf::from("."))
46                    .join(".loxone")
47                    .join("auth"),
48            },
49            enabled: true,
50            cache_size: 1000,
51            session_timeout_secs: 3600, // 1 hour
52            max_failed_attempts: 5,
53            rate_limit_window_secs: 900, // 15 minutes
54        }
55    }
56}
57
58impl AuthConfig {
59    /// Create a disabled authentication configuration
60    pub fn disabled() -> Self {
61        Self {
62            enabled: false,
63            ..Default::default()
64        }
65    }
66
67    /// Create a memory-only configuration (for testing)
68    pub fn memory() -> Self {
69        Self {
70            storage: StorageConfig::Memory,
71            ..Default::default()
72        }
73    }
74}