Files
confgen/app
7000pctAUTO 84172b2d7b
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
Add test suite for confgen
2026-02-01 20:51:51 +00:00
..
2026-02-01 20:51:51 +00:00

Confgen

A CLI tool that generates, validates, and manages environment-specific configuration files from templates with schema validation, secrets interpolation, diff preview, and interactive editing.

Features

  • Template-based config generation: Define templates with Jinja2-style variable placeholders
  • Multi-environment support: Generate configs for dev, staging, and prod environments
  • Schema validation: Validate generated configs against JSON Schema definitions
  • Secrets interpolation: Replace secret placeholders with values from env vars or vault backends
  • Diff preview: Show colored diff between current and generated config before applying
  • Interactive TUI editor: Edit config values interactively in the terminal
  • Output with secret masking: Mask secret values in output with *** pattern

Installation

From Source

pip install -e .

Using pip

pip install confgen

Quick Start

  1. Create a template file (e.g., config.yaml.j2):
app_name: {{APP_NAME}}
database:
  host: {{DB_HOST}}
  port: {{DB_PORT}}
  password: {{env.SECRET_DB_PASSWORD}}
  1. Create a confgen.yaml configuration:
templates:
  config:
    path: config.yaml.j2
    format: yaml

environments:
  dev:
    variables:
      APP_NAME: myapp-dev
      DB_HOST: localhost
      DB_PORT: 5432
  prod:
    variables:
      APP_NAME: myapp
      DB_HOST: db.example.com
      DB_PORT: 5432
  1. Generate a config:
confgen generate --template config --environment dev --output config.dev.yaml

Configuration

Environment Variables

Variable Description Default
CONFGEN_TEMPLATES_DIR Directory containing template files ~/.confgen/templates
CONFGEN_CONFIG_DIR Directory for generated configs ~/.confgen/output
CONFGEN_ENV Default environment (dev/staging/prod) dev
CONFGEN_VAULT_URL Vault backend URL (optional) ``
CONFGEN_VAULT_TOKEN Vault authentication token (optional) ``

confgen.yaml

The main configuration file defining templates, environments, and schema:

templates:
  my_config:
    path: templates/config.yaml.j2
    format: yaml
    schema: schemas/config.json

environments:
  dev:
    variables:
      VAR1: value1
  staging:
    variables:
      VAR1: value2
  prod:
    variables:
      VAR1: value3

Commands

generate

Generate a configuration file from a template.

confgen generate [OPTIONS]
Option Description
--template, -t Template name (required)
--environment, -e Environment name (default: dev)
--output, -o Output file path
--format, -f Output format (json/yaml/toml)
--validate Validate generated config against schema
--diff Show diff before applying
--edit Open interactive editor

list

List available templates and environments.

confgen list [OPTIONS]
Option Description
--templates List available templates
--environments List available environments
--env Show variables for specific environment

validate

Validate a configuration file against a schema.

confgen validate [OPTIONS]
Option Description
--config, -c Config file to validate
--schema, -s Schema file path
--template, -t Template name to use its schema

edit

Open interactive editor for editing config values.

confgen edit [OPTIONS]
Option Description
--template, -t Template name (required)
--environment, -e Environment name
--output, -o Output file path

Template Syntax

Variables

Use Jinja2-style syntax for variable substitution:

app_name: {{APP_NAME}}
port: {{PORT}}
debug: {{DEBUG_MODE}}

Environment Variables

Access environment variables with env. prefix:

password: {{env.SECRET_PASSWORD}}
database_url: {{env.DATABASE_URL}}

Secrets (with masking)

Secrets are automatically masked in output:

api_key: {{vault.SECRET_API_KEY}}
db_password: {{env.SECRET_DB_PASSWORD}}

Conditionals

Use Jinja2 conditionals:

{% if USE_CACHE %}
cache:
  enabled: true
  ttl: {{CACHE_TTL}}
{% endif %}

Loops

Use Jinja2 loops:

services:
{% for service in SERVICES %}
  - name: {{service.name}}
    port: {{service.port}}
{% endfor %}

Secrets Management

Environment Variables

Secrets from environment variables:

password: {{env.SECRET_PASSWORD}}

Vault Backend

Secrets from a vault backend:

api_key: {{vault.SECRET_API_KEY}}

Configure vault with environment variables:

  • CONFGEN_VAULT_URL: Vault server URL
  • CONFGEN_VAULT_TOKEN: Authentication token

Schema Validation

Validate your configurations against JSON Schema:

{
  "type": "object",
  "properties": {
    "app_name": {"type": "string"},
    "port": {"type": "integer", "minimum": 1, "maximum": 65535},
    "debug": {"type": "boolean"}
  },
  "required": ["app_name", "port"]
}

Interactive Editor

Launch an interactive terminal UI to edit config values:

confgen edit --template my_config --environment dev

The editor provides:

  • Type-aware input validation
  • Default values from template
  • Secret field masking
  • Environment-specific editing

Development

# Install development dependencies
pip install -e .[dev]

# Run tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=src/confgen --cov-report=term-missing

# Format code
black src/confgen tests/

# Lint code
ruff check src/confgen tests/

Examples

See the examples/ directory for complete examples:

  • simple.yaml: Basic template example
  • complex.yaml: Template with secrets and conditionals
  • schema.json: JSON Schema for validation
  • confgen.yaml: Complete configuration example

License

MIT