Skip to main content

backbone_core/config/
features_config.rs

1//! Feature flags configuration
2//!
3//! Defines application feature toggles and rate limiting.
4
5use serde::{Deserialize, Serialize};
6
7fn default_true() -> bool { true }
8fn default_false() -> bool { false }
9
10/// Feature flags configuration
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct FeaturesConfig {
13    /// Enable user registration
14    #[serde(default = "default_true")]
15    pub user_registration: bool,
16    /// Enable email verification
17    #[serde(default = "default_true")]
18    pub email_verification: bool,
19    /// Enable password reset
20    #[serde(default = "default_true")]
21    pub password_reset: bool,
22    /// Enable two-factor authentication
23    #[serde(default = "default_false")]
24    pub two_factor_auth: bool,
25    /// Enable social login
26    #[serde(default = "default_false")]
27    pub social_login: bool,
28    /// Enable audit logging
29    #[serde(default = "default_true")]
30    pub audit_logging: bool,
31    /// Enable rate limiting
32    #[serde(default = "default_true")]
33    pub rate_limiting: bool,
34    /// Rate limiting configuration
35    #[serde(default)]
36    pub rate_limiting_config: Option<RateLimitingConfig>,
37}
38
39impl Default for FeaturesConfig {
40    fn default() -> Self {
41        Self {
42            user_registration: true,
43            email_verification: true,
44            password_reset: true,
45            two_factor_auth: false,
46            social_login: false,
47            audit_logging: true,
48            rate_limiting: true,
49            rate_limiting_config: Some(RateLimitingConfig::default()),
50        }
51    }
52}
53
54/// Rate limiting configuration
55#[derive(Debug, Clone, Serialize, Deserialize)]
56pub struct RateLimitingConfig {
57    /// Default requests per hour limit
58    #[serde(default = "default_rate_limit")]
59    pub default_limit: u32,
60    /// Burst limit
61    #[serde(default = "default_burst_limit")]
62    pub burst_limit: u32,
63    /// Storage backend (redis, memory)
64    #[serde(default = "default_rate_storage")]
65    pub storage: String,
66}
67
68fn default_rate_limit() -> u32 { 1000 }
69fn default_burst_limit() -> u32 { 100 }
70fn default_rate_storage() -> String { "redis".to_string() }
71
72impl Default for RateLimitingConfig {
73    fn default() -> Self {
74        Self {
75            default_limit: default_rate_limit(),
76            burst_limit: default_burst_limit(),
77            storage: default_rate_storage(),
78        }
79    }
80}