Skip to content

Commit 653331a

Browse files
committed
refactor(config): compile-time env var mappings eliminate runtime ambiguity
Replace dynamic path inference with derive macro that generates explicit mappings at compile time. Field attribute #[config_env(leaf)] gives users control over nested vs value type handling without hardcoding type names in the macro.
1 parent 13a1bf3 commit 653331a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2233
-1058
lines changed

.github/config/components.yml

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,17 @@ components:
3737
paths:
3838
- "core/sdk/**"
3939

40+
rust-internals:
41+
depends_on:
42+
- "rust-workspace"
43+
paths:
44+
- "core/internals/**"
45+
- "core/internals_derive/**"
46+
4047
rust-common:
4148
depends_on:
42-
- "rust-workspace" # Common is affected by workspace changes
43-
- "ci-infrastructure" # CI changes trigger full regression
49+
- "rust-workspace"
50+
- "rust-internals"
4451
paths:
4552
- "core/common/**"
4653

@@ -51,28 +58,52 @@ components:
5158
paths:
5259
- "core/binary_protocol/**"
5360

61+
rust-clock:
62+
depends_on:
63+
- "rust-workspace"
64+
paths:
65+
- "core/clock/**"
66+
67+
rust-journal:
68+
depends_on:
69+
- "rust-workspace"
70+
paths:
71+
- "core/journal/**"
72+
73+
rust-partitions:
74+
depends_on:
75+
- "rust-workspace"
76+
paths:
77+
- "core/partitions/**"
78+
5479
rust-server:
5580
depends_on:
56-
- "rust-workspace" # Server is affected by workspace changes
57-
- "ci-infrastructure" # CI changes trigger full regression
81+
- "rust-workspace"
82+
- "rust-internals"
5883
- "rust-common"
5984
- "rust-binary-protocol"
85+
- "rust-journal"
86+
- "rust-partitions"
6087
paths:
6188
- "core/server/**"
6289

6390
rust-cluster:
6491
depends_on:
65-
- "rust-workspace" # Cluster is affected by workspace changes
66-
- "ci-infrastructure" # CI changes trigger full regression
92+
- "rust-workspace"
93+
- "rust-clock"
6794
paths:
68-
- "core/consensus/"
69-
- "core/metadata/"
70-
- "core/message_bus/"
95+
- "core/consensus/**"
96+
- "core/metadata/**"
97+
- "core/message_bus/**"
7198

7299
# Main Rust workspace testing
73100
rust:
74101
depends_on:
75102
- "rust-workspace"
103+
- "rust-internals"
104+
- "rust-clock"
105+
- "rust-journal"
106+
- "rust-partitions"
76107
- "rust-sdk"
77108
- "rust-common"
78109
- "rust-binary-protocol"
@@ -84,7 +115,7 @@ components:
84115
- "rust-connectors"
85116
- "rust-mcp"
86117
- "rust-integration"
87-
- "ci-infrastructure" # CI changes trigger full regression
118+
- "ci-infrastructure"
88119
paths:
89120
- "Dockerfile*"
90121
- "!foreign/**" # Exclude foreign SDKs
@@ -121,13 +152,15 @@ components:
121152
rust-connectors:
122153
depends_on:
123154
- "rust-sdk"
155+
- "rust-internals"
124156
paths:
125157
- "core/connectors/**"
126158

127159
# MCP AI component
128160
rust-mcp:
129161
depends_on:
130162
- "rust-sdk"
163+
- "rust-internals"
131164
paths:
132165
- "core/ai/mcp/**"
133166

@@ -138,6 +171,7 @@ components:
138171
- "rust-common"
139172
- "rust-binary-protocol"
140173
- "rust-server"
174+
- "rust-internals"
141175
paths:
142176
- "core/integration/**"
143177

Cargo.lock

Lines changed: 28 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ members = [
4141
"core/connectors/sources/random_source",
4242
"core/consensus",
4343
"core/integration",
44+
"core/internals",
45+
"core/internals_derive",
4446
"core/journal",
4547
"core/message_bus",
4648
"core/metadata",
@@ -114,6 +116,7 @@ console-subscriber = "0.5.0"
114116
crossbeam = "0.8.4"
115117
cyper = { version = "0.7.1", features = ["rustls"], default-features = false }
116118
cyper-axum = { version = "0.7.1" }
119+
darling = "0.20"
117120
dashmap = "6.1.0"
118121
derive-new = "0.7.0"
119122
derive_builder = "0.20.2"
@@ -140,6 +143,8 @@ iggy_binary_protocol = { path = "core/binary_protocol", version = "0.8.1-edge.1"
140143
iggy_common = { path = "core/common", version = "0.8.1-edge.1" }
141144
iggy_connector_sdk = { path = "core/connectors/sdk", version = "0.1.1-edge.1" }
142145
integration = { path = "core/integration" }
146+
internals = { path = "core/internals", version = "0.1.0" }
147+
internals_derive = { path = "core/internals_derive", version = "0.1.0" }
143148
keyring = { version = "3.6.3", features = ["sync-secret-service", "vendored"] }
144149
lazy_static = "1.5.0"
145150
left-right = "0.11"
@@ -172,7 +177,9 @@ parquet = "=55.2.0"
172177
passterm = "=2.0.1"
173178
postcard = { version = "1.1.3", features = ["alloc"] }
174179
predicates = "3.1.3"
180+
proc-macro2 = "1"
175181
quinn = "0.11.9"
182+
quote = "1"
176183
rand = "0.9.2"
177184
rand_xoshiro = "0.7.0"
178185
regex = "1.12.2"
@@ -199,6 +206,7 @@ simd-json = { version = "0.17.0", features = ["serde_impl"] }
199206
slab = "0.4.1"
200207
strum = { version = "0.27.2", features = ["derive"] }
201208
strum_macros = "0.27.2"
209+
syn = { version = "2", features = ["full", "extra-traits"] }
202210
sysinfo = "0.37.2"
203211
tempfile = "3.24.0"
204212
test-case = "3.3.1"

DEPENDENCIES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ inotify-sys: 0.1.5, "ISC",
417417
inout: 0.1.4, "Apache-2.0 OR MIT",
418418
integer-encoding: 3.0.4, "MIT",
419419
integration: 0.0.1, "Apache-2.0",
420+
internals: 0.1.0, "Apache-2.0",
421+
internals_derive: 0.1.0, "Apache-2.0",
420422
inventory: 0.3.21, "Apache-2.0 OR MIT",
421423
io-uring: 0.7.11, "Apache-2.0 OR MIT",
422424
io_uring_buf_ring: 0.2.3, "MIT",

core/ai/mcp/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ dotenvy = { workspace = true }
3434
figlet-rs = { workspace = true }
3535
figment = { workspace = true }
3636
iggy = { workspace = true }
37-
iggy_common = { workspace = true }
37+
internals = { workspace = true }
38+
internals_derive = { workspace = true }
3839
opentelemetry = { workspace = true }
3940
opentelemetry-appender-tracing = { workspace = true }
4041
opentelemetry-otlp = { workspace = true }

core/ai/mcp/src/configs.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,64 +24,69 @@ use figment::{
2424
value::Dict,
2525
};
2626
use iggy::prelude::{DEFAULT_ROOT_PASSWORD, DEFAULT_ROOT_USERNAME};
27-
use iggy_common::{CustomEnvProvider, FileConfigProvider};
27+
use internals::{FileConfigProvider, TypedEnvProvider};
28+
use internals_derive::ConfigEnv;
2829
use serde::{Deserialize, Serialize};
2930
use std::fmt::{Display as FmtDisplay, Formatter};
3031
use std::str::FromStr;
3132
use strum::Display;
3233
use tower_http::cors::{AllowOrigin, CorsLayer};
3334

34-
#[derive(Debug, Clone, Deserialize, Serialize)]
35+
#[derive(Debug, Clone, Deserialize, Serialize, ConfigEnv)]
36+
#[config_env(prefix = "IGGY_MCP_")]
3537
#[serde(default)]
3638
pub struct McpServerConfig {
3739
pub http: HttpConfig,
3840
pub iggy: IggyConfig,
3941
pub permissions: PermissionsConfig,
42+
#[config_env(leaf)]
4043
pub transport: McpTransport,
4144
pub telemetry: TelemetryConfig,
4245
}
4346

44-
#[derive(Debug, Clone, Serialize, Deserialize)]
47+
#[derive(Debug, Clone, Serialize, Deserialize, ConfigEnv)]
4548
pub struct IggyConfig {
4649
pub address: String,
4750
pub username: String,
51+
#[config_env(secret)]
4852
pub password: String,
53+
#[config_env(secret)]
4954
pub token: String,
5055
pub consumer: String,
5156
pub tls: IggyTlsConfig,
5257
}
5358

54-
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
59+
#[derive(Debug, Default, Clone, Serialize, Deserialize, ConfigEnv)]
5560
pub struct IggyTlsConfig {
5661
pub enabled: bool,
5762
pub ca_file: String,
5863
pub domain: Option<String>,
5964
}
6065

61-
#[derive(Debug, Clone, Deserialize, Serialize)]
66+
#[derive(Debug, Clone, Deserialize, Serialize, ConfigEnv)]
6267
pub struct PermissionsConfig {
6368
pub create: bool,
6469
pub read: bool,
6570
pub update: bool,
6671
pub delete: bool,
6772
}
6873

69-
#[derive(Debug, Clone, Deserialize, Serialize)]
74+
#[derive(Debug, Clone, Deserialize, Serialize, ConfigEnv)]
7075
pub struct HttpConfig {
7176
pub address: String,
7277
pub path: String,
7378
pub cors: HttpCorsConfig,
7479
pub tls: HttpTlsConfig,
7580
}
7681

77-
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
82+
#[derive(Debug, Default, Deserialize, Serialize, Clone, ConfigEnv)]
7883
pub struct HttpTlsConfig {
7984
pub enabled: bool,
8085
pub cert_file: String,
8186
pub key_file: String,
8287
}
8388

84-
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
89+
#[derive(Debug, Default, Deserialize, Serialize, Clone, ConfigEnv)]
8590
pub struct HttpCorsConfig {
8691
pub enabled: bool,
8792
pub allowed_methods: Vec<String>,
@@ -103,7 +108,7 @@ pub enum McpTransport {
103108
Stdio,
104109
}
105110

106-
#[derive(Debug, Deserialize, Serialize, Clone)]
111+
#[derive(Debug, Deserialize, Serialize, Clone, ConfigEnv)]
107112
pub struct TelemetryConfig {
108113
pub enabled: bool,
109114
pub service_name: String,
@@ -132,8 +137,9 @@ impl FmtDisplay for TelemetryConfig {
132137
}
133138
}
134139

135-
#[derive(Debug, Deserialize, Serialize, Clone)]
140+
#[derive(Debug, Deserialize, Serialize, Clone, ConfigEnv)]
136141
pub struct TelemetryLogsConfig {
142+
#[config_env(leaf)]
137143
pub transport: TelemetryTransport,
138144
pub endpoint: String,
139145
}
@@ -157,8 +163,9 @@ impl FmtDisplay for TelemetryLogsConfig {
157163
}
158164
}
159165

160-
#[derive(Debug, Deserialize, Serialize, Clone)]
166+
#[derive(Debug, Deserialize, Serialize, Clone, ConfigEnv)]
161167
pub struct TelemetryTracesConfig {
168+
#[config_env(leaf)]
162169
pub transport: TelemetryTransport,
163170
pub endpoint: String,
164171
}
@@ -394,15 +401,17 @@ impl McpServerConfig {
394401
}
395402
}
396403

404+
const SECRET_KEYS: [&str; 2] = ["IGGY_MCP_IGGY_PASSWORD", "IGGY_MCP_IGGY_TOKEN"];
405+
397406
#[derive(Debug, Clone)]
398407
pub struct McpServerEnvProvider {
399-
provider: CustomEnvProvider<McpServerConfig>,
408+
provider: TypedEnvProvider<McpServerConfig>,
400409
}
401410

402411
impl Default for McpServerEnvProvider {
403412
fn default() -> Self {
404413
Self {
405-
provider: CustomEnvProvider::new("IGGY_MCP_", &[]),
414+
provider: TypedEnvProvider::new("IGGY_MCP_", &SECRET_KEYS),
406415
}
407416
}
408417
}
@@ -413,8 +422,6 @@ impl Provider for McpServerEnvProvider {
413422
}
414423

415424
fn data(&self) -> Result<figment::value::Map<Profile, Dict>, figment::Error> {
416-
self.provider.deserialize().map_err(|_| {
417-
figment::Error::from("Cannot deserialize environment variables for MCP config")
418-
})
425+
self.provider.data()
419426
}
420427
}

0 commit comments

Comments
 (0)