Skip to content

Commit 9b3d67e

Browse files
eastgatecursoragent
andcommitted
feat: complete env_resolution migration for remaining env var literals
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent a6074b0 commit 9b3d67e

13 files changed

Lines changed: 262 additions & 68 deletions

File tree

bin/loamspine-service/main.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,13 @@ async fn run_server(
204204

205205
let rpc_service = {
206206
let svc = LoamSpineRpcService::new(service);
207-
let tower_socket = std::env::var("TOWER_SIGNER_SOCKET")
208-
.or_else(|_| std::env::var("BEARDOG_SOCKET"));
209-
if let Ok(socket_val) = tower_socket {
207+
let tower_socket = loam_spine_core::constants::env_resolution::tower_signer_socket();
208+
if let Some(socket_val) = tower_socket {
210209
let socket_path = std::path::PathBuf::from(&socket_val);
211210
info!("Tower signing enabled via TOWER_SIGNER_SOCKET={socket_val}");
212-
let signer_did = std::env::var("TOWER_SIGNER_DID")
211+
let signer_did = loam_spine_core::constants::env_resolution::tower_signer_did()
213212
.map(loam_spine_core::types::Did::new)
214-
.unwrap_or_else(|_| loam_spine_core::types::Did::anonymous());
213+
.unwrap_or_else(loam_spine_core::types::Did::anonymous);
215214
let signer = std::sync::Arc::new(
216215
loam_spine_core::traits::crypto_provider::JsonRpcCryptoSigner::new(
217216
socket_path,
@@ -315,7 +314,7 @@ async fn run_server(
315314
};
316315

317316
#[cfg(unix)]
318-
let family_id = std::env::var("BIOMEOS_FAMILY_ID").ok();
317+
let family_id = loam_spine_core::constants::env_resolution::biomeos_family_id();
319318

320319
// Capability-domain symlink: ledger.sock → loamspine.sock
321320
// Enables orchestration-layer `by_capability = "ledger"` routing in deploy graphs.

crates/loam-spine-api/src/jsonrpc/method_gate.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ impl AuthMode {
5656
/// Unset or unrecognized defaults to `Permissive`.
5757
#[must_use]
5858
pub fn from_env() -> Self {
59-
std::env::var("LOAMSPINE_AUTH_MODE")
60-
.ok()
59+
loam_spine_core::constants::env_resolution::loamspine_auth_mode()
6160
.and_then(|v| match v.to_ascii_lowercase().as_str() {
6261
"enforced" => Some(Self::Enforced),
6362
"permissive" => Some(Self::Permissive),

crates/loam-spine-api/src/jsonrpc/uds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ fn is_btsp_ndjson(line: &str) -> bool {
462462

463463
/// Resolve the BTSP provider socket from environment for NDJSON auto-detect.
464464
fn resolve_btsp_provider() -> Option<std::path::PathBuf> {
465-
if let Ok(path) = std::env::var("BTSP_PROVIDER_SOCKET") {
465+
if let Some(path) = loam_spine_core::constants::env_resolution::btsp_provider_socket() {
466466
return Some(std::path::PathBuf::from(path));
467467
}
468468
let config = loam_spine_core::btsp::BtspHandshakeConfig::from_env()?;

crates/loam-spine-core/src/btsp/config.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const DEFAULT_BTSP_PROVIDER_PREFIX: &str = "btsp-provider";
2424
/// Checks `BTSP_PROVIDER` env var first, allowing runtime configuration
2525
/// of the handshake provider without compile-time primal coupling.
2626
fn btsp_provider_prefix() -> String {
27-
std::env::var("BTSP_PROVIDER").unwrap_or_else(|_| DEFAULT_BTSP_PROVIDER_PREFIX.into())
27+
crate::constants::env_resolution::btsp_provider()
28+
.unwrap_or_else(|| DEFAULT_BTSP_PROVIDER_PREFIX.into())
2829
}
2930

3031
/// Pure variant for testing and explicit configuration.
@@ -81,11 +82,11 @@ impl BtspHandshakeConfig {
8182
/// meaning BTSP is required. Returns `None` in development mode.
8283
#[must_use]
8384
pub fn from_env() -> Option<Self> {
84-
let provider_socket_override = std::env::var("BTSP_PROVIDER_SOCKET").ok();
85+
let provider_socket_override = crate::constants::env_resolution::btsp_provider_socket();
8586
Self::from_values(
86-
std::env::var("BIOMEOS_FAMILY_ID").ok().as_deref(),
87+
crate::constants::env_resolution::biomeos_family_id().as_deref(),
8788
provider_socket_override.as_deref(),
88-
std::env::var("BIOMEOS_SOCKET_DIR").ok().as_deref(),
89+
crate::constants::env_resolution::biomeos_socket_dir().as_deref(),
8990
)
9091
}
9192
}
@@ -148,7 +149,9 @@ pub(crate) fn provider_socket_name(
148149
/// Returns `true` when `BIOMEOS_FAMILY_ID` is set and not `"default"`.
149150
#[must_use]
150151
pub fn is_btsp_required() -> bool {
151-
is_btsp_required_with(std::env::var("BIOMEOS_FAMILY_ID").ok().as_deref())
152+
is_btsp_required_with(
153+
crate::constants::env_resolution::biomeos_family_id().as_deref(),
154+
)
152155
}
153156

154157
/// Pure inner function: check BTSP requirement from explicit values.

crates/loam-spine-core/src/btsp/handshake.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,7 @@ fn decode_session_key(session_key: Option<&String>) -> Option<[u8; 32]> {
509509
pub(crate) fn resolve_family_seed() -> Result<String, LoamSpineError> {
510510
use base64::Engine;
511511

512-
let raw = std::env::var("FAMILY_SEED")
513-
.or_else(|_| std::env::var("BTSP_FAMILY_SEED"))
514-
.or_else(|_| std::env::var("BEARDOG_FAMILY_SEED"))
515-
.map_err(|_| {
512+
let raw = crate::constants::env_resolution::family_seed().map_err(|_| {
516513
LoamSpineError::ipc(
517514
IpcErrorPhase::Connect,
518515
"FAMILY_SEED not set (checked FAMILY_SEED, BTSP_FAMILY_SEED, and BEARDOG_FAMILY_SEED)",

crates/loam-spine-core/src/config.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,16 @@ impl Default for DiscoveryConfig {
179179
let tarpc = crate::constants::env_resolution::tarpc_port();
180180
let jsonrpc = crate::constants::env_resolution::jsonrpc_port();
181181

182-
let discovery_enabled = std::env::var("LOAMSPINE_DISCOVERY_ENABLED")
183-
.map(|v| !matches!(v.as_str(), "0" | "false" | "no"))
184-
.unwrap_or(true);
182+
let discovery_enabled = crate::constants::env_resolution::discovery_enabled();
185183

186184
Self {
187185
discovery_enabled,
188-
discovery_endpoint: std::env::var("DISCOVERY_ENDPOINT").ok(),
186+
discovery_endpoint: crate::constants::env_resolution::discovery_endpoint(),
189187

190-
tarpc_endpoint: std::env::var("TARPC_ENDPOINT")
191-
.unwrap_or_else(|_| format!("http://{bind}:{tarpc}")),
192-
jsonrpc_endpoint: std::env::var("JSONRPC_ENDPOINT")
193-
.unwrap_or_else(|_| format!("http://{bind}:{jsonrpc}")),
188+
tarpc_endpoint: crate::constants::env_resolution::tarpc_endpoint()
189+
.unwrap_or_else(|| format!("http://{bind}:{tarpc}")),
190+
jsonrpc_endpoint: crate::constants::env_resolution::jsonrpc_endpoint()
191+
.unwrap_or_else(|| format!("http://{bind}:{jsonrpc}")),
194192

195193
auto_advertise: true,
196194
heartbeat_interval_seconds: 60,

0 commit comments

Comments
 (0)