Skip to main content

rustack_logs_core/
config.rs

1//! CloudWatch Logs service configuration.
2
3use std::env;
4
5/// CloudWatch Logs service configuration.
6#[derive(Debug, Clone)]
7pub struct LogsConfig {
8    /// Skip signature validation (default: true for local dev).
9    pub skip_signature_validation: bool,
10    /// Default AWS region.
11    pub default_region: String,
12    /// Default AWS account ID.
13    pub account_id: String,
14    /// Host to bind to.
15    pub host: String,
16    /// Port to listen on.
17    pub port: u16,
18}
19
20impl LogsConfig {
21    /// Create configuration from environment variables.
22    #[must_use]
23    pub fn from_env() -> Self {
24        Self {
25            skip_signature_validation: env_bool("LOGS_SKIP_SIGNATURE_VALIDATION", true),
26            default_region: env::var("DEFAULT_REGION").unwrap_or_else(|_| "us-east-1".to_owned()),
27            account_id: env::var("DEFAULT_ACCOUNT_ID")
28                .unwrap_or_else(|_| "000000000000".to_owned()),
29            host: env::var("LOGS_HOST").unwrap_or_else(|_| "0.0.0.0".to_owned()),
30            port: env::var("LOGS_PORT")
31                .ok()
32                .and_then(|v| v.parse().ok())
33                .unwrap_or(4515),
34        }
35    }
36}
37
38impl Default for LogsConfig {
39    fn default() -> Self {
40        Self {
41            skip_signature_validation: true,
42            default_region: "us-east-1".to_owned(),
43            account_id: "000000000000".to_owned(),
44            host: "0.0.0.0".to_owned(),
45            port: 4515,
46        }
47    }
48}
49
50fn env_bool(key: &str, default: bool) -> bool {
51    env::var(key).map_or(default, |v| {
52        matches!(v.to_lowercase().as_str(), "1" | "true" | "yes")
53    })
54}