MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / apply_env_overrides

Function apply_env_overrides

nodedb/src/config/server/env.rs:166–396  ·  view source on GitHub ↗

Apply environment variable overrides to a loaded `ServerConfig`. Priority order: env var > TOML value > compiled default. Handled variables: - `NODEDB_HOST` — overrides `config.host` (bind address, e.g., `0.0.0.0`) - `NODEDB_PORT_NATIVE` — overrides `config.ports.native` (default 6433) - `NODEDB_PORT_PGWIRE` — overrides `config.ports.pgwire` (default 6432) - `NODEDB_PORT_HT

(config: &mut ServerConfig)

Source from the content-addressed store, hash-verified

164/// (called from `main.rs`) so that the value is never passed through logging
165/// code paths or stored in `ServerConfig` where it could appear in debug output.
166pub fn apply_env_overrides(config: &mut ServerConfig) {
167 // ── Host and ports ─────────────────────────────────────────────
168
169 if let Ok(val) = std::env::var("NODEDB_HOST") {
170 match val.trim().parse::<IpAddr>() {
171 Ok(ip) => {
172 tracing::info!(env_var = "NODEDB_HOST", value = %val, "environment variable override applied");
173 config.server.host = ip;
174 }
175 Err(_) => {
176 tracing::warn!(
177 env_var = "NODEDB_HOST",
178 value = %val,
179 "ignoring malformed environment variable (expected IP address), using config value"
180 );
181 }
182 }
183 }
184
185 apply_port_env("NODEDB_PORT_NATIVE", &mut config.server.ports.native);
186 apply_port_env("NODEDB_PORT_PGWIRE", &mut config.server.ports.pgwire);
187 apply_port_env("NODEDB_PORT_HTTP", &mut config.server.ports.http);
188 apply_optional_port_env("NODEDB_PORT_RESP", &mut config.server.ports.resp);
189 apply_optional_port_env("NODEDB_PORT_ILP", &mut config.server.ports.ilp);
190
191 if let Ok(val) = std::env::var("NODEDB_DATA_DIR") {
192 let path = std::path::PathBuf::from(&val);
193 tracing::info!(
194 env_var = "NODEDB_DATA_DIR",
195 value = %val,
196 "environment variable override applied"
197 );
198 config.server.data_dir = path;
199 }
200
201 if let Ok(val) = std::env::var("NODEDB_MEMORY_LIMIT") {
202 match parse_memory_size(&val) {
203 Ok(bytes) => {
204 tracing::info!(
205 env_var = "NODEDB_MEMORY_LIMIT",
206 value = %val,
207 bytes,
208 "environment variable override applied"
209 );
210 config.server.memory_limit = bytes;
211 }
212 Err(e) => {
213 tracing::warn!(
214 env_var = "NODEDB_MEMORY_LIMIT",
215 value = %val,
216 error = %e,
217 "ignoring malformed environment variable, using config value"
218 );
219 }
220 }
221 }
222
223 if let Ok(val) = std::env::var("NODEDB_NODE_ID") {

Callers 4

mainFunction · 0.85
env_data_dir_overrideFunction · 0.85
env_cluster_overridesFunction · 0.85

Calls 7

apply_port_envFunction · 0.85
apply_optional_port_envFunction · 0.85
parse_memory_sizeFunction · 0.85
parse_seed_nodesFunction · 0.85
apply_bool_envFunction · 0.85
apply_observability_envFunction · 0.85
as_strMethod · 0.45

Tested by 3

env_data_dir_overrideFunction · 0.68
env_cluster_overridesFunction · 0.68