summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-06-11 12:51:49 -0600
committermo khan <mo@mokhan.ca>2025-06-11 12:51:49 -0600
commit77c185a8db0d54cb66b28b694b1671428b831595 (patch)
tree9e671ff4a22608955370656e85eb5991b4d85d22 /src/config.rs
parent7c41dfe19aa0ced3b895979ca4e369067fd58da1 (diff)
Add full implementation
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/config.rs b/src/config.rs
index a13658b..266f669 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -2,16 +2,50 @@
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 = format!("http://{}", bind_addr);
+ 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,
}
}
}