cdk_mintd/env_vars/
info.rs1use 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 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 if let Ok(use_keyset_v2_str) = env::var(ENV_USE_KEYSET_V2) {
69 if let Ok(use_keyset_v2) = use_keyset_v2_str.parse() {
70 self.use_keyset_v2 = Some(use_keyset_v2);
71 }
72 }
73
74 if let Ok(output_str) = env::var(ENV_LOGGING_OUTPUT) {
76 if let Ok(output) = LoggingOutput::from_str(&output_str) {
77 self.logging.output = output;
78 } else {
79 tracing::warn!(
80 "Invalid logging output '{}' in environment variable. Valid options: stdout, file, both",
81 output_str
82 );
83 }
84 }
85
86 if let Ok(console_level) = env::var(ENV_LOGGING_CONSOLE_LEVEL) {
87 self.logging.console_level = Some(console_level);
88 }
89
90 if let Ok(file_level) = env::var(ENV_LOGGING_FILE_LEVEL) {
91 self.logging.file_level = Some(file_level);
92 }
93
94 self.http_cache = self.http_cache.from_env();
95
96 let mut mint_ttl_env: Option<u64> = None;
98 let mut melt_ttl_env: Option<u64> = None;
99 if let Ok(mint_ttl_str) = env::var(ENV_QUOTE_TTL_MINT) {
100 if let Ok(v) = mint_ttl_str.parse::<u64>() {
101 mint_ttl_env = Some(v);
102 }
103 }
104 if let Ok(melt_ttl_str) = env::var(ENV_QUOTE_TTL_MELT) {
105 if let Ok(v) = melt_ttl_str.parse::<u64>() {
106 melt_ttl_env = Some(v);
107 }
108 }
109 if mint_ttl_env.is_some() || melt_ttl_env.is_some() {
110 let current = self.quote_ttl.unwrap_or_default();
111 self.quote_ttl = Some(QuoteTTL {
112 mint_ttl: mint_ttl_env.unwrap_or(current.mint_ttl),
113 melt_ttl: melt_ttl_env.unwrap_or(current.melt_ttl),
114 });
115 }
116
117 self
118 }
119}