From 23ade06ff9d02b4020170d6afdb53f04b43bf419 Mon Sep 17 00:00:00 2001 From: End Date: Fri, 3 Apr 2026 09:34:30 -0700 Subject: [PATCH] chore(deps): restore dotenvy and replace custom .env loader Replace the hand-rolled unsafe .env parser with dotenvy's #[dotenvy::load(required = false)] attribute macro. --- Cargo.lock | 25 ++++++++++++++++++++++--- Cargo.toml | 1 + src/main.rs | 33 +-------------------------------- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bebebb9..20632eb 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -623,6 +623,24 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "git+https://github.com/allan2/dotenvy#fa25166994d6978bd2e002f0ed190c0c39674ebe" +dependencies = [ + "dotenvy-macros", +] + +[[package]] +name = "dotenvy-macros" +version = "0.15.7" +source = "git+https://github.com/allan2/dotenvy#fa25166994d6978bd2e002f0ed190c0c39674ebe" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.103", +] + [[package]] name = "dunce" version = "1.0.5" @@ -1726,6 +1744,7 @@ dependencies = [ "clap", "derive_more", "displaydoc", + "dotenvy 0.15.7 (git+https://github.com/allan2/dotenvy)", "error-stack", "futures", "http-body-util", @@ -2582,7 +2601,7 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" dependencies = [ - "dotenvy", + "dotenvy 0.15.7 (registry+https://github.com/rust-lang/crates.io-index)", "either", "heck", "hex", @@ -2614,7 +2633,7 @@ dependencies = [ "bytes", "crc", "digest", - "dotenvy", + "dotenvy 0.15.7 (registry+https://github.com/rust-lang/crates.io-index)", "either", "futures-channel", "futures-core", @@ -2655,7 +2674,7 @@ dependencies = [ "bitflags", "byteorder", "crc", - "dotenvy", + "dotenvy 0.15.7 (registry+https://github.com/rust-lang/crates.io-index)", "etcetera", "futures-channel", "futures-core", diff --git a/Cargo.toml b/Cargo.toml index 2319cce..09167ce 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ tokio = { version = "1.45.1", features = ["rt", "macros", "rt-multi-thread"] } tracing = "0.1.41" tracing-error = "0.2.1" tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } +dotenvy = { git = "https://github.com/allan2/dotenvy", features = ["macros"] } url = "2.5.4" serde_json = "1.0.140" diff --git a/src/main.rs b/src/main.rs index 2462c0a..0e547b2 100755 --- a/src/main.rs +++ b/src/main.rs @@ -45,41 +45,10 @@ enum Error { Initialization, } +#[dotenvy::load(required = false)] #[tokio::main] #[tracing::instrument] async fn main() -> error_stack::Result { - if std::env::var("USE_DOTENV").is_ok() { - // Custom, minimal .env loader to avoid depending on crate helpers in the build image. - // This reads .env, parses simple KEY=VALUE lines, strips optional surrounding quotes, - // and sets the variables into the environment for the process. - if let Ok(content) = std::fs::read_to_string(".env") { - for raw_line in content.lines() { - let line = raw_line.trim(); - if line.is_empty() || line.starts_with('#') { - continue; - } - // Split on the first '=' - if let Some(eq) = line.find('=') { - let key = line[..eq].trim(); - let mut val = line[eq + 1..].trim().to_string(); - // Strip surrounding quotes if present - if (val.starts_with('"') && val.ends_with('"')) - || (val.starts_with('\'') && val.ends_with('\'')) - { - if val.len() >= 2 { - val = val[1..val.len() - 1].to_string(); - } - } - // Only set if key non-empty - if !key.is_empty() { - unsafe { std::env::set_var(key, val) }; - } - } - } - } else { - tracing::debug!(".env requested via USE_DOTENV but .env file not found"); - } - } let console_subscriber = tracing_subscriber::fmt::layer().pretty(); let error_subscriber = tracing_error::ErrorLayer::default(); let env_subscriber = EnvFilter::builder()