config
¶
Functions:
-
load_config–Load a YAML configuration file.
-
mask_sensitive_info–Mask sensitive information in the given config dict.
-
setup_logging–Set up logging configuration from a dict.
load_config
¶
load_config(config_path: str) -> dict[str, Any]
Load a YAML configuration file.
Supported syntax
${VAR} → If VAR not set, becomes null ${VAR, default} → If VAR not set, "default" is inserted literally and then YAML type-casts it. ${VAR, "default"} → Quotes are preserved; YAML treats the value as a ${VAR, 'default'} string, suppressing automatic type casting. } inside the quoted value is allowed.
Behavior
- Read the entire YAML file as a raw string.
- Perform string-level substitution for ${...} patterns.
- Pass the substituted string to PyYAML, allowing YAML to determine types.
- Expand leading
~in string values into absolute home paths.
- Expand leading
This design ensures
- No custom smart-casting logic is needed.
- Default values are type-cast by YAML (10→int, false→bool, etc.).
- Environment variable values are applied before YAML parsing.
Parameters:
-
(config_path¶str) –Path to the YAML configuration file.
Returns:
-
dict[str, Any]–Parsed configuration as a Python dict with correct types.
mask_sensitive_info
¶
mask_sensitive_info(
config: dict[str, Any],
) -> dict[str, Any]
Mask sensitive information in the given config dict.
A key is considered sensitive if its name (case-insensitive) contains any of
the substrings in SENSITIVE_PATTERNS: key, password, secret,
or token. For example, api_key, db_password, access_token,
and client_secret are all masked.
This function is designed for small configuration dicts loaded at startup and is not intended for large data sets.
It processes nested dicts recursively.
Parameters:
-
(config¶dict[str, Any]) –Configuration dict to mask.
Returns:
-
dict[str, Any]–A new dictionary with sensitive values replaced by
"***MASKED***".
setup_logging
¶
setup_logging(logging_cfg: dict) -> None
Set up logging configuration from a dict.
Parameters:
-
(logging_cfg¶dict) –The logging configuration to apply.
Raises:
-
TypeError–If the configuration cannot be converted to a dictionary.