Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:416rehman DeepZero Env Var Expansion

From Leeroopedia
Knowledge Sources
Domains Infrastructure, Configuration
Last Updated 2026-10-27 00:00 GMT

Overview

Expand `${VAR}` and `${VAR:-default}` syntax in pipeline YAML config before parsing, so secrets and install paths never need to be hardcoded in pipeline files.

Description

Pipeline YAML files can reference environment variables using shell-like syntax: `${VAR}` expands to the variable's value, and `${VAR:-default}` provides a fallback if the variable is unset. The `load_pipeline` function recursively walks the entire YAML structure (strings, dicts, lists) and expands all occurrences before any processor config is parsed. An unset variable with no default expands to an empty string rather than leaking the literal `${VAR}` text — which would read as a truthy value downstream and produce confusing errors like "ghidra not found at ${GHIDRA_INSTALL_DIR}".

Usage

Use this heuristic when writing pipeline YAML configs. Reference environment variables for paths and credentials instead of hardcoding them. Always provide a `${VAR:-default}` fallback for optional config, and use `validate()` in the processor to check if required fields are empty after expansion.

The Insight (Rule of Thumb)

  • Action: Use `${VAR}` for required env vars and `${VAR:-default}` for optional ones in pipeline YAML config values.
  • Value: Unset `VAR` with no default → empty string. Unset `VAR` with `:-default` → the default value.
  • Trade-off: Expansion happens before processor validation, so an empty expansion passes through as an empty config field — processors must check for empty in their `validate()` method.
  • Compatibility: Works in any string value anywhere in the YAML structure (nested dicts, lists, etc.).

Reasoning

Hardcoding `GHIDRA_INSTALL_DIR` or `JAVA_HOME` in a pipeline YAML file makes the pipeline non-portable — different machines have different install paths. Env var expansion lets the same pipeline YAML work everywhere by deferring path resolution to runtime. The critical design choice is that an unset var expands to empty rather than leaving the literal `${VAR}` in place: a literal would pass type checks (it is a non-empty string) and produce confusing errors deep in the pipeline, while an empty string is caught early by the processor's `validate()`.

Code Evidence

Recursive expansion from `pipeline.py:298-305`:

def _expand_env_vars(obj: Any) -> Any:
    if isinstance(obj, str):
        return _expand_string(obj)
    if isinstance(obj, dict):
        return {k: _expand_env_vars(v) for k, v in obj.items()}
    if isinstance(obj, list):
        return [_expand_env_vars(v) for v in obj]
    return obj

String expansion with default syntax from `pipeline.py:308-321`:

def _expand_string(s: str) -> str:
    import re

    def _replace(match: re.Match) -> str:
        var = match.group(1)
        if ":-" in var:
            name, default = var.split(":-", 1)
            return os.environ.get(name, default)
        # an unset var expands to empty rather than leaking the literal "${VAR}",
        # which would read as a truthy value downstream and produce confusing
        # errors like "ghidra not found at ${GHIDRA_INSTALL_DIR}"
        return os.environ.get(var, "")

    return re.sub(r"\$\{([^}]+)\}", _replace, s)

Documented in processor base class from `stage.py:236-243`:

# config fields can read from environment variables via YAML syntax:
#   config:
#     install_dir: ${GHIDRA_INSTALL_DIR}
#     java_home: ${JAVA_HOME:-/usr/lib/jvm/default}
#
# the engine expands ${VAR} and ${VAR:-default} before parsing.
# use validate() to check if required fields are empty after expansion.

Ghidra validate checking for empty after expansion from `ghidra_decompile.py:122-126`:

def validate(self, ctx: ProcessorContext) -> list[str]:
    if not self.config.ghidra_install_dir:
        return [
            "ghidra_install_dir is required - set it in config or via ${GHIDRA_INSTALL_DIR}"
        ]

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment