821537186e
- Reorganized import statements in adapter tests for better readability - Replaced or_insert_with(Vec::new) with or_default() in test closures - Updated Cargo.lock with new dependency versions and checksums - Added TLS features to tonic dependency configuration - Included sqlx, chrono, and uuid dependencies with specific features - Added jsonwebtoken and arc-swap as project dependencies - Reformatted assertion statements to comply with line length limits - Adjusted base64 import order in engine codec module - Updated protobuf include statement formatting
66 lines
2.1 KiB
Rust
66 lines
2.1 KiB
Rust
//! 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<String>,
|
|
/// Optional client certificate PEM path for appks mTLS.
|
|
pub tls_client_cert_path: Option<String>,
|
|
/// Optional client private key PEM path for appks mTLS.
|
|
pub tls_client_key_path: Option<String>,
|
|
/// TLS domain name used for certificate verification.
|
|
pub tls_domain_name: Option<String>,
|
|
}
|
|
|
|
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"));
|
|
}
|
|
}
|