yera.creds.loaders

Credential key validation and transformation helpers.

Symbols

def flatten_json — Flatten a nested object into dotted credential keys.
def is_leaf — Report whether a path identifies a stored credential leaf.
def is_namespace — Report whether a path is a namespace containing credential leaves.
def leaves_under — Return credential leaves stored beneath a namespace path.
def raise_if_credential_group_key_prefix_conflict — Raise if *credentials* keys contain a leaf-namespace prefix pair.
def raise_if_flat_credential_keys_prefix_conflict — Raise if any key is a proper dotted prefix of another (leaf-namespace conflict).
def validate_credential_group_name — Validate a credential group name.
def validate_credential_key — Validate a credential key as a dotted path.

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

obj
type: dict[str, Any]

Nested mapping to flatten.

prefix
type: str

Dotted path prepended to each generated credential key. Pass an empty string to generate keys from the object root.

Returns

type: dict[str, str]

String values indexed by their flattened dotted credential keys.

Raises

CredentialKeyError

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]],
) → bool

Report whether a path identifies a stored credential leaf.

Parameters

key
type: str

Dotted credential path to inspect.

creds
type: dict[str, dict[str, Any]]

Stored credentials indexed by their dotted paths.

Returns

type: bool

Whether key exists as a stored credential leaf.

is_namespace

is_namespace(
    key: str,
    creds: dict[str, dict[str, Any]],
) → bool

Report 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

key
type: str

Dotted credential path to inspect.

creds
type: dict[str, dict[str, Any]]

Stored credentials indexed by their dotted paths.

Returns

type: bool

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

path
type: str

Dotted namespace path to inspect.

creds
type: dict[str, dict[str, Any]]

Stored credentials indexed by their dotted paths.

Returns

type: dict[str, dict[str, Any]]

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,
) → None

Raise if credentials keys contain a leaf-namespace prefix pair.

Parameters

credentials
type: dict[str, Any]

Stored credentials indexed by their dotted paths.

group_name
type: str

Name of the credential group being inspected.

credentials_file
type: Path

Path to the file containing the credential group.

Raises

CredentialKeyError

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,
) → None

Raise 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

keys
type: Iterable[str]

Dotted credential paths to inspect.

prefix_message
type: str

Text prepended to the conflict description.

Raises

CredentialKeyError

If two keys stand in a prefix relationship.

validate_credential_group_name

validate_credential_group_name(
    name: str,
) → None

Validate a credential group name.

A valid name contains visible non-whitespace text, contains no dots, and contains no control characters.

Parameters

name
type: str

Credential-group name to validate.

Raises

CredentialGroupNameError

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,
) → None

Validate a credential key as a dotted path.

A valid key is non-empty, contains no empty path segments, and contains no control characters.

Parameters

key
type: str

Credential key to validate.

Raises

CredentialKeyError

If the key is empty, contains an empty segment, or contains a control character.