1use serde::{Deserialize, Serialize};
6use std::path::PathBuf;
7
8#[derive(Debug, Clone, Deserialize, Serialize)]
10#[serde(default)]
11pub struct AuthConfig {
12 pub enable: bool,
15
16 pub database_path: PathBuf,
18
19 pub durability: bool,
21
22 pub superadmin: String,
25
26 pub api_key: ApiKeyConfig,
28
29 pub lockout: LockoutConfig,
31
32 pub rate_limit: RateLimitConfig,
34
35 pub session: SessionConfig,
37}
38
39impl Default for AuthConfig {
40 fn default() -> Self {
41 Self {
42 enable: false,
43 database_path: PathBuf::from("auth"),
44 durability: false,
45 superadmin: String::default(),
46 api_key: ApiKeyConfig::default(),
47 lockout: LockoutConfig::default(),
48 rate_limit: RateLimitConfig::default(),
49 session: SessionConfig::default(),
50 }
51 }
52}
53
54#[derive(Debug, Clone, Deserialize, Serialize)]
56#[serde(default)]
57pub struct ApiKeyConfig {
58 pub default_ttl_seconds: i64,
61
62 pub max_keys_per_user: u32,
65
66 pub prefix: String,
68}
69
70impl Default for ApiKeyConfig {
71 fn default() -> Self {
72 Self {
73 default_ttl_seconds: 2592000,
74 max_keys_per_user: 10,
75 prefix: "ave_node_".to_string(),
76 }
77 }
78}
79
80#[derive(Debug, Clone, Deserialize, Serialize)]
82#[serde(default)]
83pub struct LockoutConfig {
84 pub max_attempts: u32,
87
88 pub duration_seconds: i64,
90}
91
92impl Default for LockoutConfig {
93 fn default() -> Self {
94 Self {
95 max_attempts: 10,
96 duration_seconds: 300,
97 }
98 }
99}
100
101#[derive(Debug, Clone, Deserialize, Serialize)]
103#[serde(default)]
104pub struct RateLimitConfig {
105 pub enable: bool,
107
108 pub window_seconds: i64,
110
111 pub max_requests: u32,
113
114 pub limit_by_key: bool,
116
117 pub limit_by_ip: bool,
119
120 pub cleanup_interval_seconds: i64,
122
123 #[serde(default)]
126 pub sensitive_endpoints: Vec<EndpointRateLimit>,
127}
128
129#[derive(Debug, Clone, Deserialize, Serialize)]
131pub struct EndpointRateLimit {
132 pub endpoint: String,
134
135 pub max_requests: u32,
137
138 pub window_seconds: Option<i64>,
140}
141
142impl Default for RateLimitConfig {
143 fn default() -> Self {
144 Self {
145 enable: true,
146 window_seconds: 60,
147 max_requests: 100,
148 limit_by_key: true,
149 limit_by_ip: true,
150 cleanup_interval_seconds: 3600,
151 sensitive_endpoints: vec![
153 EndpointRateLimit {
154 endpoint: "/login".to_string(),
155 max_requests: 10,
156 window_seconds: None, },
158 EndpointRateLimit {
159 endpoint: "/change-password".to_string(),
160 max_requests: 5,
161 window_seconds: None,
162 },
163 EndpointRateLimit {
164 endpoint: "/admin/users".to_string(),
165 max_requests: 20,
166 window_seconds: None,
167 },
168 ],
169 }
170 }
171}
172
173#[derive(Debug, Clone, Deserialize, Serialize)]
175#[serde(default)]
176pub struct SessionConfig {
177 pub audit_enable: bool,
179
180 pub audit_retention_days: u32,
182
183 pub audit_max_entries: u32,
186}
187
188impl Default for SessionConfig {
189 fn default() -> Self {
190 Self {
191 audit_enable: true,
192 audit_retention_days: 90,
193 audit_max_entries: 1_000_000,
196 }
197 }
198}