yera.creds.loaders
Credential key validation and transformation helpers.
Symbols
flatten_json
flatten_json(
obj: dict[str, Any],
prefix: str,
) → dict[str, str]Flatten a nested object into dotted credential keys.
Nested mappings become path components, while string leaves become credential values.
Parameters
Nested mapping to flatten.
Dotted path prepended to each generated credential key. Pass an empty string to generate keys from the object root.
Returns
String values indexed by their flattened dotted credential keys.
Raises
If a generated key is invalid, a leaf is not a string, two entries produce the same flattened key, or generated keys conflict as both a leaf and a namespace.
is_leaf
is_leaf(
key: str,
creds: dict[str, dict[str, Any]],
) → boolReport whether a path identifies a stored credential leaf.
Parameters
Dotted credential path to inspect.
Stored credentials indexed by their dotted paths.
Returns
Whether key exists as a stored credential leaf.
is_namespace
is_namespace(
key: str,
creds: dict[str, dict[str, Any]],
) → boolReport whether a path is a namespace containing credential leaves.
The path must be a proper prefix followed by a dot. A credential stored
directly at key does not by itself make the key a namespace.
Parameters
Dotted credential path to inspect.
Stored credentials indexed by their dotted paths.
Returns
Whether at least one stored credential exists beneath key.
leaves_under
leaves_under(
path: str,
creds: dict[str, dict[str, Any]],
) → dict[str, dict[str, Any]]Return credential leaves stored beneath a namespace path.
Parameters
Dotted namespace path to inspect.
Stored credentials indexed by their dotted paths.
Returns
Credential leaves whose keys start with path followed by a dot.
raise_if_credential_group_key_prefix_conflict
raise_if_credential_group_key_prefix_conflict(
credentials: dict[str, Any],
group_name: str,
credentials_file: Path,
) → NoneRaise if credentials keys contain a leaf-namespace prefix pair.
Parameters
Stored credentials indexed by their dotted paths.
Name of the credential group being inspected.
Path to the file containing the credential group.
Raises
If two keys stand in a prefix relationship. The error identifies the credential group and its file.
raise_if_flat_credential_keys_prefix_conflict
raise_if_flat_credential_keys_prefix_conflict(
keys: Iterable[str],
prefix_message: str,
) → NoneRaise if any key is a proper dotted prefix of another (leaf-namespace conflict).
keys are dotted credential paths. After sorting, only adjacent pairs need
checking: if K immediately precedes K.<segment> lexicographically among
sorted keys, every prefix relationship appears as some adjacent pair.
Parameters
Dotted credential paths to inspect.
Text prepended to the conflict description.
Raises
If two keys stand in a prefix relationship.
validate_credential_group_name
validate_credential_group_name(
name: str,
) → NoneValidate a credential group name.
A valid name contains visible non-whitespace text, contains no dots, and contains no control characters.
Parameters
Credential-group name to validate.
Raises
If the name is empty, consists only of whitespace, contains a dot, or contains a control character.
validate_credential_key
validate_credential_key(
key: str,
) → NoneValidate a credential key as a dotted path.
A valid key is non-empty, contains no empty path segments, and contains no control characters.
Parameters
Credential key to validate.
Raises
If the key is empty, contains an empty segment, or contains a control character.