Skip to content

feat: support environment variables in YAML configuration#790

Merged
kvch merged 3 commits into
xataio:mainfrom
mvanhorn:feat/env-var-expansion-yaml
Jun 4, 2026
Merged

feat: support environment variables in YAML configuration#790
kvch merged 3 commits into
xataio:mainfrom
mvanhorn:feat/env-var-expansion-yaml

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

@mvanhorn mvanhorn commented Apr 8, 2026

Summary

Adds os.ExpandEnv support to YAML config parsing so users can reference environment variables like ${DB_PASSWORD} in config files instead of hardcoding secrets.

Applied to all three YAML-backed parsing paths:

  • LoadFile (viper): reads file manually, expands env vars, feeds to viper.ReadConfig
  • ParseStreamConfig (yaml.Unmarshal): expands before the case-sensitive YAML parse
  • ParseTransformerConfig: expands before transformation rule parsing

Also handles the transformer rules merge path (PGSTREAM_TRANSFORMER_RULES_FILE).

Example config:

listener:
  postgres:
    conn: "postgres://${PG_USER}:${PG_PASSWORD}@${PG_HOST}:5432/mydb"

Fixes #383

This contribution was developed with AI assistance (Codex).

Expand ${VAR} references in YAML config files using os.ExpandEnv
before parsing. This avoids exposing secrets in config files.

Applied to all three YAML parsing paths: LoadFile (viper),
ParseStreamConfig (yaml.Unmarshal), and ParseTransformerConfig.

Fixes xataio#383
Copy link
Copy Markdown
Collaborator

@kvch kvch left a comment

Choose a reason for hiding this comment

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

This is a great feature! However, the implementation breaks the transformer configurations. Could you please fix the code so it only expands ${...} variables?

os.ExpandEnv also expanded bare $VAR forms, which broke transformer
configurations containing template/regex dollar syntax ($1, $name, $$).
Replace it with a braced-form-only expander and cover the passthrough
cases with table tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mvanhorn
Copy link
Copy Markdown
Contributor Author

mvanhorn commented Jun 4, 2026

Fixed - expansion now only touches ${...} forms (valid env identifier inside braces). Bare $VAR and transformer template/regex dollar syntax ($1, ${1}, $$) pass through untouched; added table tests covering those cases plus a ParseTransformerConfig test asserting transformer configs survive expansion.

@kvch
Copy link
Copy Markdown
Collaborator

kvch commented Jun 4, 2026

Thank you for the fixes!

@kvch kvch merged commit 5420967 into xataio:main Jun 4, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Config] Support for env variables in yaml configuration

2 participants