Skip to content

failclose

azure_bootstrap.failclose

Fail-closed-for-auth / fail-open-for-features env helpers.

ConfigurationError is re-exported from :mod:azure_bootstrap.models.exceptions so callers see a single canonical class regardless of which import path they use. v1 callers of ConfigurationError keep working unchanged.

Use: - :func:require_env for tenant_id, connection strings, secrets — anything whose absence MUST stop the pipeline. - :func:optional_env for endpoint URLs that have sensible defaults or feature flags with documented fallback semantics. - :func:fail_open_env for "feature disabled when None" semantics — comment every call site with the threat consequence of the open default.

Classes:

Name Description
ConfigurationError

Exception raised when configuration loading or access fails.

Functions:

Name Description
require_env

Return os.environ[name] when truthy; raise ConfigurationError otherwise.

optional_env

Return os.environ.get(name, default).strip().

fail_open_env

Return the env value when truthy, else None — for "feature disabled" semantics.

ConfigurationError

Bases: RepositoryError

Exception raised when configuration loading or access fails.

This exception is raised when: - Azure App Configuration connection fails - Configuration values are missing or invalid - Configuration refresh operations fail - Configuration loading encounters critical errors

require_env

require_env(name: str, *, message: str | None = None) -> str

Return os.environ[name] when truthy; raise ConfigurationError otherwise.

Source code in azure_bootstrap/failclose/__init__.py
def require_env(name: str, *, message: str | None = None) -> str:
    """Return ``os.environ[name]`` when truthy; raise ``ConfigurationError`` otherwise."""
    raw = os.environ.get(name, "")
    if not raw or not raw.strip():
        raise ConfigurationError(
            message or f"Required environment variable {name!r} is missing or empty"
        )
    return raw.strip()

optional_env

optional_env(name: str, *, default: str = '') -> str

Return os.environ.get(name, default).strip().

Source code in azure_bootstrap/failclose/__init__.py
def optional_env(name: str, *, default: str = "") -> str:
    """Return ``os.environ.get(name, default).strip()``."""
    return os.environ.get(name, default).strip()

fail_open_env

fail_open_env(name: str) -> str | None

Return the env value when truthy, else None — for "feature disabled" semantics.

Source code in azure_bootstrap/failclose/__init__.py
def fail_open_env(name: str) -> str | None:
    """Return the env value when truthy, else None — for "feature disabled" semantics."""
    raw = os.environ.get(name)
    if raw is None:
        return None
    stripped = raw.strip()
    return stripped or None