1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#[derive(Debug, Clone)]
pub struct Config {
pub bind_addr: String,
pub issuer_url: String,
pub database_path: String,
pub rate_limit_requests_per_minute: u32,
pub jwt_key_rotation_hours: u32,
pub enable_audit_logging: bool,
pub cors_allowed_origins: Vec<String>,
pub cleanup_interval_hours: u32,
}
impl Config {
pub fn from_env() -> Self {
let bind_addr = std::env::var("BIND_ADDR").unwrap_or_else(|_| "127.0.0.1:7878".to_string());
let issuer_url = std::env::var("ISSUER_URL").unwrap_or_else(|_| format!("http://{}", bind_addr));
let database_path = std::env::var("DATABASE_PATH").unwrap_or_else(|_| "oauth.db".to_string());
let rate_limit_requests_per_minute = std::env::var("RATE_LIMIT_RPM")
.unwrap_or_else(|_| "60".to_string())
.parse()
.unwrap_or(60);
let jwt_key_rotation_hours = std::env::var("JWT_KEY_ROTATION_HOURS")
.unwrap_or_else(|_| "24".to_string())
.parse()
.unwrap_or(24);
let enable_audit_logging = std::env::var("ENABLE_AUDIT_LOGGING")
.unwrap_or_else(|_| "true".to_string())
.parse()
.unwrap_or(true);
let cors_allowed_origins = std::env::var("CORS_ALLOWED_ORIGINS")
.unwrap_or_else(|_| "*".to_string())
.split(',')
.map(|s| s.trim().to_string())
.collect();
let cleanup_interval_hours = std::env::var("CLEANUP_INTERVAL_HOURS")
.unwrap_or_else(|_| "1".to_string())
.parse()
.unwrap_or(1);
Self {
bind_addr,
issuer_url,
database_path,
rate_limit_requests_per_minute,
jwt_key_rotation_hours,
enable_audit_logging,
cors_allowed_origins,
cleanup_interval_hours,
}
}
}
|