Skip to content

fix: warn when environment variables referenced in config are not set#1628

Open
yosofbadr wants to merge 2 commits into
TwiN:masterfrom
yosofbadr:fix/env-var-endpoints
Open

fix: warn when environment variables referenced in config are not set#1628
yosofbadr wants to merge 2 commits into
TwiN:masterfrom
yosofbadr:fix/env-var-endpoints

Conversation

@yosofbadr
Copy link
Copy Markdown

Summary

  • Replace os.ExpandEnv with os.Expand + os.LookupEnv in parseAndValidateConfigBytes so that a warning is logged whenever an environment variable referenced in the configuration (including endpoint url, headers, and body) is not defined in the environment.
  • Add tests verifying env var expansion works correctly in endpoint URL, headers, and body fields.
  • Add test confirming undefined env vars produce an empty-string substitution (the existing behavior) while now also emitting a warning log.

This helps users diagnose issues like the one reported in #1532, where Docker Compose quoting (- KTOKEN="value") caused the literal quotes to become part of the value, leading to YAML parse errors or unexpected substitution results. The warning makes it immediately clear which variable was not found.

Closes #1532

Test plan

  • TestParseAndValidateConfigBytesWithEnvVarInEndpointURLAndHeaders -- verifies ${VAR} in endpoint URL, Authorization header, and body are expanded
  • TestParseAndValidateConfigBytesWithUndefinedEnvVarWarning -- verifies undefined vars expand to empty string (and a warning is logged)
  • TestParseAndValidateConfigBytesWithLiteralDollarSign -- existing test still passes (literal $$ handling unchanged)
  • Full go test ./config/ suite passes

Replace os.ExpandEnv with os.Expand + os.LookupEnv so that a warning is
logged whenever an environment variable referenced in the configuration
file (including endpoint URLs, headers, and body) is not defined. This
helps users diagnose issues where env vars appear to not be interpolated
(e.g. due to Docker Compose quoting).

Add tests verifying that env var expansion works correctly in endpoint
URL, headers, and body fields, and that undefined variables produce the
expected empty-string substitution.

Closes TwiN#1532
@github-actions github-actions Bot added the bug Something isn't working label Apr 15, 2026
@yosofbadr yosofbadr marked this pull request as ready for review April 15, 2026 20:20
Comment thread config/config_test.go
if config == nil {
t.Fatal("config should not be nil")
}
// Undefined env vars should be replaced with empty string
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this not already the case? Or was it just leaving the unset environment variable as a literal value?

@yosofbadr
Copy link
Copy Markdown
Author

Good question @TwiN — yes, empty-string substitution was already the behavior of os.ExpandEnv (it wraps os.Getenv which returns "" for unset variables). This test just locks in that behavior so the switch to os.Expand + os.LookupEnv doesn't accidentally regress it. The new behavior introduced by the PR is the logr.Warnf line — the substitution itself is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Environment variables inconsistency

2 participants