Skip to content

Commit

Permalink
Values without a backing env var should not be expanded
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Feb 19, 2024
1 parent dd8ff5e commit c2a9ed8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion cmd/backup/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ func loadConfigsFromEnvFiles(directory string) ([]*Config, error) {
if err != nil {
return nil, errwrap.Wrap(err, fmt.Sprintf("error reading %s", item.Name()))
}
envFile, err := godotenv.Unmarshal(os.ExpandEnv(string(f)))
envFile, err := godotenv.Unmarshal(os.Expand(string(f), func(s string) string {
if val, ok := os.LookupEnv(s); ok {
return val
}
return fmt.Sprintf("$%s", s)
}))
if err != nil {
return nil, errwrap.Wrap(err, fmt.Sprintf("error reading config file %s", p))
}
Expand Down
1 change: 1 addition & 0 deletions test/confd/02backup.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NAME="other"
BACKUP_CRON_EXPRESSION="*/1 * * * *"
BACKUP_FILENAME="override-$NAME.tar.gz"
2 changes: 1 addition & 1 deletion test/confd/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ ! -f "$LOCAL_DIR/conf.tar.gz" ]; then
fi
pass "Config from file was used."

if [ ! -f "$LOCAL_DIR/other.tar.gz" ]; then
if [ ! -f "$LOCAL_DIR/override-other.tar.gz" ]; then
fail "Run on same schedule did not succeed."
fi
pass "Run on same schedule succeeded."
Expand Down

0 comments on commit c2a9ed8

Please sign in to comment.