Skip to content

ontocast.config.snapshot

The settings a run is configured with, as a JSON-safe, secret-free mapping.

Keyed by environment-variable name, so a run's record reads in the same vocabulary as the .env that configured it, and two records diff key by key.

Attributes

REDACTED = '<redacted>' module-attribute

SECRET_FIELD_NAMES = frozenset({'api_key', 'auth'}) module-attribute

Functions:

config_snapshot(settings)

Every leaf setting under settings with the value in force.

Credentials are replaced by a marker (None stays None, so the record still says whether one was set), and credentials embedded in URLs are stripped.

Parameters:

Name Type Description Default
settings BaseSettings

Usually the run's :class:~ontocast.config.settings.Config.

required

Returns:

Type Description
dict[str, Any]

{ENV_NAME: value} with JSON-safe values, in declaration order. A

dict[str, Any]

setting read from several names (an alias) appears under each, so a

dict[str, Any]

record can be looked up by whichever name configured it.

Source code in ontocast/config/snapshot.py
def config_snapshot(settings: BaseSettings) -> dict[str, Any]:
    """Every leaf setting under ``settings`` with the value in force.

    Credentials are replaced by a marker (``None`` stays ``None``, so the record
    still says whether one was set), and credentials embedded in URLs are
    stripped.

    Args:
        settings: Usually the run's :class:`~ontocast.config.settings.Config`.

    Returns:
        ``{ENV_NAME: value}`` with JSON-safe values, in declaration order. A
        setting read from several names (an alias) appears under each, so a
        record can be looked up by whichever name configured it.
    """
    snapshot: dict[str, Any] = {}
    for field, value in iter_settings_values(settings):
        if field.name in SECRET_FIELD_NAMES:
            value = None if value is None else REDACTED
        elif isinstance(value, str):
            value = _strip_url_credentials(value)
        for name in field.env_names:
            snapshot[name] = to_jsonable_python(value)
    return snapshot