//! gRPC client configuration for connecting to appks core services. //! //! Reads the appks address and timeout from environment variables. use std::env; /// Configuration for appks gRPC connections. #[derive(Debug, Clone)] pub struct RpcConfig { /// appks gRPC endpoint, e.g. `http://localhost:50051`. pub appks_addr: String, /// Connection establishment timeout (seconds). pub connect_timeout_secs: u64, /// Optional CA certificate PEM path for appks mTLS. pub tls_ca_cert_path: Option, /// Optional client certificate PEM path for appks mTLS. pub tls_client_cert_path: Option, /// Optional client private key PEM path for appks mTLS. pub tls_client_key_path: Option, /// TLS domain name used for certificate verification. pub tls_domain_name: Option, } impl RpcConfig { /// Build config from environment variables with defaults. pub fn from_env() -> Self { Self { appks_addr: env::var("APPKS_GRPC_ADDR") .unwrap_or_else(|_| "http://localhost:50051".to_string()), connect_timeout_secs: env::var("APPKS_GRPC_TIMEOUT") .ok() .and_then(|v| v.parse().ok()) .unwrap_or(10), tls_ca_cert_path: env::var("APPKS_GRPC_TLS_CA_CERT").ok(), tls_client_cert_path: env::var("APPKS_GRPC_TLS_CLIENT_CERT").ok(), tls_client_key_path: env::var("APPKS_GRPC_TLS_CLIENT_KEY").ok(), tls_domain_name: env::var("APPKS_GRPC_TLS_DOMAIN").ok(), } } } impl Default for RpcConfig { fn default() -> Self { Self::from_env() } } #[cfg(test)] mod tests { use super::*; #[test] fn test_default_config() { let cfg = RpcConfig { appks_addr: "http://localhost:50051".to_string(), connect_timeout_secs: 10, tls_ca_cert_path: None, tls_client_cert_path: None, tls_client_key_path: None, tls_domain_name: None, }; assert_eq!(cfg.connect_timeout_secs, 10); assert!(cfg.appks_addr.starts_with("http")); } }