1use crate::types::AwsRegion;
6
7#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct RustackConfig {
11 pub gateway_listen: String,
13 pub default_region: AwsRegion,
15 pub log_level: String,
17 pub persistence: bool,
19 pub data_dir: String,
21}
22
23impl Default for RustackConfig {
24 fn default() -> Self {
25 Self {
26 gateway_listen: "0.0.0.0:4566".to_owned(),
27 default_region: AwsRegion::default(),
28 log_level: "info".to_owned(),
29 persistence: false,
30 data_dir: "/var/lib/localstack".to_owned(),
31 }
32 }
33}
34
35impl RustackConfig {
36 #[must_use]
38 pub fn from_env() -> Self {
39 let mut config = Self::default();
40
41 if let Ok(v) = std::env::var("GATEWAY_LISTEN") {
42 config.gateway_listen = v;
43 }
44 if let Ok(v) = std::env::var("DEFAULT_REGION") {
45 config.default_region = AwsRegion::new(v);
46 }
47 if let Ok(v) = std::env::var("LOG_LEVEL") {
48 config.log_level = v;
49 }
50 if let Ok(v) = std::env::var("PERSISTENCE") {
51 config.persistence = v == "1" || v.eq_ignore_ascii_case("true");
52 }
53 if let Ok(v) = std::env::var("DATA_DIR") {
54 config.data_dir = v;
55 }
56
57 config
58 }
59}
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_should_create_default_config() {
67 let config = RustackConfig::default();
68 assert_eq!(config.gateway_listen, "0.0.0.0:4566");
69 assert_eq!(config.default_region.as_str(), "us-east-1");
70 assert!(!config.persistence);
71 }
72}