diff --git a/crates/cdk-mintd/src/env_vars.rs b/crates/cdk-mintd/src/env_vars.rs index eae4de4d..88d9e90e 100644 --- a/crates/cdk-mintd/src/env_vars.rs +++ b/crates/cdk-mintd/src/env_vars.rs @@ -6,8 +6,7 @@ use anyhow::{anyhow, bail, Result}; use cdk::nuts::CurrencyUnit; use crate::config::{ - Cln, Database, DatabaseEngine, FakeWallet, Info, LNbits, Ln, LnBackend, Lnd, MintInfo, - Phoenixd, Settings, Strike, + Cln, Database, DatabaseEngine, ElasticSearchLogger, FakeWallet, Info, LNbits, Ln, LnBackend, Lnd, MintInfo, Phoenixd, Settings, Strike }; pub const DATABASE_ENV_VAR: &str = "CDK_MINTD_DATABASE"; @@ -68,6 +67,10 @@ pub const ENV_FAKE_WALLET_FEE_PERCENT: &str = "CDK_MINTD_FAKE_WALLET_FEE_PERCENT pub const ENV_FAKE_WALLET_RESERVE_FEE_MIN: &str = "CDK_MINTD_FAKE_WALLET_RESERVE_FEE_MIN"; pub const ENV_FAKE_WALLET_MIN_DELAY: &str = "CDK_MINTD_FAKE_WALLET_MIN_DELAY"; pub const ENV_FAKE_WALLET_MAX_DELAY: &str = "CDK_MINTD_FAKE_WALLET_MAX_DELAY"; +// Elastic Search +pub const ENV_ELASTIC_SEARCH_URL: &str = "CDK_MINTD_ELASTIC_SEARCH_URL"; +pub const ENV_ELASTIC_SEARCH_INDEX: &str = "CDK_MINTD_ELASTIC_SEARCH_INDEX"; +pub const ENV_ELASTIC_SEARCH_API_KEY_BASE64: &str = "CDK_MINTD_ELASTIC_SEARCH_API_KEY_BASE64"; impl Settings { pub fn from_env(&mut self) -> Result { @@ -79,6 +82,8 @@ impl Settings { self.info = self.info.clone().from_env(); self.mint_info = self.mint_info.clone().from_env(); self.ln = self.ln.clone().from_env(); + + self.external_loggers_from_env(); match self.ln.ln_backend { LnBackend::Cln => { @@ -104,6 +109,20 @@ impl Settings { Ok(self.clone()) } + + fn external_loggers_from_env(&mut self) { + // ElasticSearch + if env::var(ENV_ELASTIC_SEARCH_URL).is_ok() { + if self.elasticsearch.is_none() { + let extlogger = ElasticSearchLogger { + elasticsearch_url: "".to_string(), api_key: None, index: "".to_string() + }; + self.elasticsearch = Some(extlogger.from_env()); + } else { + self.elasticsearch = Some(self.elasticsearch.clone().expect("Expected ElasticSearchLogger").from_env()); + } + } + } } impl Info { @@ -433,3 +452,24 @@ impl FakeWallet { self } } + + +impl ElasticSearchLogger { + pub fn from_env(mut self) -> Self { + if let Ok(elasticsearch_url) = env::var(ENV_ELASTIC_SEARCH_URL) { + self.elasticsearch_url = elasticsearch_url; + } + + if let Ok(api_key) = env::var(ENV_ELASTIC_SEARCH_API_KEY_BASE64) { + self.api_key = Some(api_key); + } else { + self.api_key = None; + } + + if let Ok(index) = env::var(ENV_ELASTIC_SEARCH_INDEX) { + self.index = index; + } + + self + } +}