Skip to main content

mecha10_core/context/
infra_config.rs

1//! Infrastructure configuration types
2//!
3//! Configuration structures for Redis, PostgreSQL, MLflow, MinIO, and other
4//! infrastructure services used by the Mecha10 framework.
5
6use serde::Deserialize;
7
8#[derive(Debug, Deserialize, Clone)]
9pub struct InfrastructureConfig {
10    pub redis: RedisConfig,
11    #[serde(default)]
12    pub control_plane_redis: Option<RedisConfig>,
13    #[serde(default)]
14    pub bridge: Option<BridgeConfig>,
15    #[serde(default)]
16    pub postgres: Option<PostgresConfig>,
17    #[serde(default)]
18    pub mlflow: Option<MlflowConfig>,
19    #[serde(default)]
20    pub minio: Option<MinioConfig>,
21}
22
23#[derive(Debug, Deserialize, Clone)]
24pub struct RedisConfig {
25    pub url: String,
26    #[serde(default = "default_max_connections")]
27    pub max_connections: usize,
28    #[serde(default = "default_connection_timeout")]
29    pub connection_timeout_ms: u64,
30}
31
32impl Default for RedisConfig {
33    fn default() -> Self {
34        Self {
35            url: "redis://localhost:6379".to_string(),
36            max_connections: default_max_connections(),
37            connection_timeout_ms: default_connection_timeout(),
38        }
39    }
40}
41
42#[derive(Debug, Deserialize, Clone)]
43pub struct PostgresConfig {
44    pub host: String,
45    pub port: u16,
46    pub database: String,
47    pub username: String,
48    pub password: String,
49    #[serde(default = "default_max_connections")]
50    pub max_connections: usize,
51}
52
53#[derive(Debug, Deserialize, Clone)]
54pub struct MlflowConfig {
55    pub tracking_uri: String,
56    pub artifact_location: String,
57}
58
59#[derive(Debug, Deserialize, Clone)]
60pub struct MinioConfig {
61    pub endpoint: String,
62    pub access_key: String,
63    pub secret_key: String,
64    #[serde(default)]
65    pub secure: bool,
66}
67
68#[derive(Debug, Deserialize, Clone)]
69pub struct BridgeConfig {
70    #[serde(default = "default_bridge_enabled")]
71    pub enabled: bool,
72
73    #[serde(default = "default_local_topics")]
74    pub local_topics: Vec<String>,
75
76    #[serde(default = "default_bridged_topics")]
77    pub bridged_topics: Vec<String>,
78
79    #[serde(default)]
80    pub robot_id: Option<String>,
81}
82
83impl Default for BridgeConfig {
84    fn default() -> Self {
85        Self {
86            enabled: default_bridge_enabled(),
87            local_topics: default_local_topics(),
88            bridged_topics: default_bridged_topics(),
89            robot_id: None,
90        }
91    }
92}
93
94fn default_bridge_enabled() -> bool {
95    true
96}
97
98fn default_local_topics() -> Vec<String> {
99    vec![
100        "/sensor/camera/*".to_string(),
101        "/sensor/lidar/*".to_string(),
102        "/sensor/imu/*".to_string(),
103    ]
104}
105
106fn default_bridged_topics() -> Vec<String> {
107    vec![
108        "/system/*".to_string(),
109        "/telemetry/*".to_string(),
110        "/logs/*".to_string(),
111        "/fleet/*".to_string(),
112    ]
113}
114
115fn default_max_connections() -> usize {
116    10
117}
118
119fn default_connection_timeout() -> u64 {
120    5000
121}