cdk_mintd/env_vars/
info.rs

1//! Info environment variables
2
3use std::env;
4use std::str::FromStr;
5
6use cdk_common::common::QuoteTTL;
7
8use super::common::*;
9use crate::config::{Info, LoggingOutput};
10
11impl Info {
12    pub fn from_env(mut self) -> Self {
13        // Required fields
14        if let Ok(url) = env::var(ENV_URL) {
15            self.url = url;
16        }
17
18        if let Ok(host) = env::var(ENV_LISTEN_HOST) {
19            self.listen_host = host;
20        }
21
22        if let Ok(port_str) = env::var(ENV_LISTEN_PORT) {
23            if let Ok(port) = port_str.parse() {
24                self.listen_port = port;
25            }
26        }
27
28        if let Ok(signatory_url) = env::var(ENV_SIGNATORY_URL) {
29            self.signatory_url = Some(signatory_url);
30        }
31
32        if let Ok(signatory_certs) = env::var(ENV_SIGNATORY_CERTS) {
33            self.signatory_certs = Some(signatory_certs);
34        }
35
36        if let Ok(seed) = env::var(ENV_SEED) {
37            self.seed = Some(seed);
38        }
39
40        if let Ok(mnemonic) = env::var(ENV_MNEMONIC) {
41            self.mnemonic = Some(mnemonic);
42        }
43
44        if let Ok(cache_seconds_str) = env::var(ENV_CACHE_SECONDS) {
45            if let Ok(seconds) = cache_seconds_str.parse() {
46                self.http_cache.ttl = Some(seconds);
47            }
48        }
49
50        if let Ok(extend_cache_str) = env::var(ENV_EXTEND_CACHE_SECONDS) {
51            if let Ok(seconds) = extend_cache_str.parse() {
52                self.http_cache.tti = Some(seconds);
53            }
54        }
55
56        if let Ok(fee_str) = env::var(ENV_INPUT_FEE_PPK) {
57            if let Ok(fee) = fee_str.parse() {
58                self.input_fee_ppk = Some(fee);
59            }
60        }
61
62        if let Ok(swagger_str) = env::var(ENV_ENABLE_SWAGGER) {
63            if let Ok(enable) = swagger_str.parse() {
64                self.enable_swagger_ui = Some(enable);
65            }
66        }
67
68        // Logging configuration
69        if let Ok(output_str) = env::var(ENV_LOGGING_OUTPUT) {
70            if let Ok(output) = LoggingOutput::from_str(&output_str) {
71                self.logging.output = output;
72            } else {
73                tracing::warn!(
74                    "Invalid logging output '{}' in environment variable. Valid options: stdout, file, both",
75                    output_str
76                );
77            }
78        }
79
80        if let Ok(console_level) = env::var(ENV_LOGGING_CONSOLE_LEVEL) {
81            self.logging.console_level = Some(console_level);
82        }
83
84        if let Ok(file_level) = env::var(ENV_LOGGING_FILE_LEVEL) {
85            self.logging.file_level = Some(file_level);
86        }
87
88        self.http_cache = self.http_cache.from_env();
89
90        // Quote TTL from env
91        let mut mint_ttl_env: Option<u64> = None;
92        let mut melt_ttl_env: Option<u64> = None;
93        if let Ok(mint_ttl_str) = env::var(ENV_QUOTE_TTL_MINT) {
94            if let Ok(v) = mint_ttl_str.parse::<u64>() {
95                mint_ttl_env = Some(v);
96            }
97        }
98        if let Ok(melt_ttl_str) = env::var(ENV_QUOTE_TTL_MELT) {
99            if let Ok(v) = melt_ttl_str.parse::<u64>() {
100                melt_ttl_env = Some(v);
101            }
102        }
103        if mint_ttl_env.is_some() || melt_ttl_env.is_some() {
104            let current = self.quote_ttl.unwrap_or_default();
105            self.quote_ttl = Some(QuoteTTL {
106                mint_ttl: mint_ttl_env.unwrap_or(current.mint_ttl),
107                melt_ttl: melt_ttl_env.unwrap_or(current.melt_ttl),
108            });
109        }
110
111        self
112    }
113}