mirror of
https://github.com/System-End/plura.git
synced 2026-04-19 15:18:23 +00:00
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.
This commit is contained in:
parent
9e3f5a8db0
commit
23ade06ff9
3 changed files with 24 additions and 35 deletions
25
Cargo.lock
generated
25
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
33
src/main.rs
33
src/main.rs
|
|
@ -45,41 +45,10 @@ enum Error {
|
|||
Initialization,
|
||||
}
|
||||
|
||||
#[dotenvy::load(required = false)]
|
||||
#[tokio::main]
|
||||
#[tracing::instrument]
|
||||
async fn main() -> error_stack::Result<ExitCode, Error> {
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue