From 54fd75cc14cd4a3a878e1b08efc8f176d2f6b3fe Mon Sep 17 00:00:00 2001 From: Andrew McGivery Date: Thu, 3 Oct 2024 17:26:35 -0400 Subject: [PATCH] Add dotenv to allow router to read environment variables from .env file --- Cargo.lock | 7 +++++++ apollo-router/Cargo.toml | 1 + apollo-router/src/executable.rs | 3 +++ 3 files changed, 11 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7128f24194..96e0aaf187 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -266,6 +266,7 @@ dependencies = [ "dhat", "diff", "displaydoc", + "dotenv", "ecdsa", "flate2", "fred", @@ -2249,6 +2250,12 @@ dependencies = [ "syn 2.0.76", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "downcast" version = "0.11.0" diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index ff09306e2a..b95036fece 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -272,6 +272,7 @@ bytesize = { version = "1.3.0", features = ["serde"] } ahash = "0.8.11" itoa = "1.0.9" ryu = "1.0.15" +dotenv = "0.15.0" [target.'cfg(macos)'.dependencies] uname = "0.1.1" diff --git a/apollo-router/src/executable.rs b/apollo-router/src/executable.rs index 86bdee162f..9216e5a424 100644 --- a/apollo-router/src/executable.rs +++ b/apollo-router/src/executable.rs @@ -19,6 +19,7 @@ use clap::Args; use clap::CommandFactory; use clap::Parser; use clap::Subcommand; +use dotenv::dotenv; #[cfg(any(feature = "dhat-heap", feature = "dhat-ad-hoc"))] use once_cell::sync::OnceCell; use regex::Captures; @@ -398,6 +399,8 @@ impl Executable { config: Option, cli_args: Option, ) -> Result<()> { + dotenv().ok(); + let opt = cli_args.unwrap_or_else(Opt::parse); if opt.version {