use std::env;
#[derive(Debug, Clone)]
pub struct LogsConfig {
pub skip_signature_validation: bool,
pub default_region: String,
pub account_id: String,
pub host: String,
pub port: u16,
}
impl LogsConfig {
#[must_use]
pub fn from_env() -> Self {
Self {
skip_signature_validation: env_bool("LOGS_SKIP_SIGNATURE_VALIDATION", true),
default_region: env::var("DEFAULT_REGION").unwrap_or_else(|_| "us-east-1".to_owned()),
account_id: env::var("DEFAULT_ACCOUNT_ID")
.unwrap_or_else(|_| "000000000000".to_owned()),
host: env::var("LOGS_HOST").unwrap_or_else(|_| "0.0.0.0".to_owned()),
port: env::var("LOGS_PORT")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(4515),
}
}
}
impl Default for LogsConfig {
fn default() -> Self {
Self {
skip_signature_validation: true,
default_region: "us-east-1".to_owned(),
account_id: "000000000000".to_owned(),
host: "0.0.0.0".to_owned(),
port: 4515,
}
}
}
fn env_bool(key: &str, default: bool) -> bool {
env::var(key).map_or(default, |v| {
matches!(v.to_lowercase().as_str(), "1" | "true" | "yes")
})
}