refactor(tests): reformat code and update dependency management
- 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
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
//! Server deployment configuration.
|
||||
//!
|
||||
//! Reads from environment variables to select adapter (local/redis/nats)
|
||||
//! and WebTransport settings.
|
||||
|
||||
use std::env;
|
||||
|
||||
/// Adapter + message bus configuration for multi-node scale-out.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DeployConfig {
|
||||
/// "local" | "redis" | "nats"
|
||||
pub adapter_mode: String,
|
||||
/// Redis connection URL (used when adapter_mode = "redis").
|
||||
pub redis_url: String,
|
||||
/// NATS connection URL (used when adapter_mode = "nats").
|
||||
pub nats_url: String,
|
||||
/// Unique server ID for this node.
|
||||
pub server_id: String,
|
||||
/// Enable WebTransport server.
|
||||
pub webtransport_enabled: bool,
|
||||
/// WebTransport listen port.
|
||||
pub webtransport_port: u16,
|
||||
/// TLS certificate path (required for WebTransport).
|
||||
pub cert_path: String,
|
||||
/// TLS key path (required for WebTransport).
|
||||
pub key_path: String,
|
||||
}
|
||||
|
||||
impl DeployConfig {
|
||||
pub fn from_env() -> Self {
|
||||
let server_id = env::var("IMKS_SERVER_ID").unwrap_or_else(|_| hostname());
|
||||
|
||||
Self {
|
||||
adapter_mode: env::var("IMKS_ADAPTER").unwrap_or_else(|_| "local".into()),
|
||||
redis_url: env::var("IMKS_REDIS_URL")
|
||||
.unwrap_or_else(|_| "redis://localhost:6379".into()),
|
||||
nats_url: env::var("IMKS_NATS_URL").unwrap_or_else(|_| "nats://localhost:4222".into()),
|
||||
server_id,
|
||||
webtransport_enabled: env::var("IMKS_WT_ENABLED")
|
||||
.map(|v| v == "true" || v == "1")
|
||||
.unwrap_or(false),
|
||||
webtransport_port: env::var("IMKS_WT_PORT")
|
||||
.ok()
|
||||
.and_then(|v| v.parse().ok())
|
||||
.unwrap_or(3001),
|
||||
cert_path: env::var("IMKS_WT_CERT_PATH").unwrap_or_default(),
|
||||
key_path: env::var("IMKS_WT_KEY_PATH").unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DeployConfig {
|
||||
fn default() -> Self {
|
||||
Self::from_env()
|
||||
}
|
||||
}
|
||||
|
||||
fn hostname() -> String {
|
||||
env::var("HOSTNAME")
|
||||
.or_else(|_| env::var("HOST"))
|
||||
.unwrap_or_else(|_| "imks-node-1".into())
|
||||
}
|
||||
Reference in New Issue
Block a user