cdk_mintd/env_vars/
grpc_processor.rs1use std::env;
4
5use cdk::nuts::CurrencyUnit;
6
7use crate::config::GrpcProcessor;
8
9pub const ENV_GRPC_PROCESSOR_SUPPORTED_UNITS: &str =
11 "CDK_MINTD_GRPC_PAYMENT_PROCESSOR_SUPPORTED_UNITS";
12pub const ENV_GRPC_PROCESSOR_ADDRESS: &str = "CDK_MINTD_GRPC_PAYMENT_PROCESSOR_ADDRESS";
13pub const ENV_GRPC_PROCESSOR_PORT: &str = "CDK_MINTD_GRPC_PAYMENT_PROCESSOR_PORT";
14pub const ENV_GRPC_PROCESSOR_TLS_DIR: &str = "CDK_MINTD_GRPC_PAYMENT_PROCESSOR_TLS_DIR";
15pub const ENV_GRPC_PROCESSOR_ALLOW_INSECURE: &str =
16 "CDK_MINTD_GRPC_PAYMENT_PROCESSOR_ALLOW_INSECURE";
17
18impl GrpcProcessor {
19 pub fn from_env(mut self) -> Self {
20 if let Ok(units_str) = env::var(ENV_GRPC_PROCESSOR_SUPPORTED_UNITS) {
21 if let Ok(units) = units_str
22 .split(',')
23 .map(|s| s.trim().parse())
24 .collect::<Result<Vec<CurrencyUnit>, _>>()
25 {
26 self.supported_units = units;
27 }
28 }
29
30 if let Ok(addr) = env::var(ENV_GRPC_PROCESSOR_ADDRESS) {
31 self.address = addr;
32 }
33
34 if let Ok(port) = env::var(ENV_GRPC_PROCESSOR_PORT) {
35 if let Ok(port) = port.parse() {
36 self.port = port;
37 }
38 }
39
40 if let Ok(tls_dir) = env::var(ENV_GRPC_PROCESSOR_TLS_DIR) {
41 self.tls_dir = Some(tls_dir.into());
42 }
43
44 if let Ok(allow_insecure) = env::var(ENV_GRPC_PROCESSOR_ALLOW_INSECURE) {
45 if let Ok(allow_insecure) = allow_insecure.parse() {
46 self.allow_insecure = allow_insecure;
47 }
48 }
49
50 self
51 }
52}