Skip to content

Secrets

rn_forge.commons.integration.secrets

Secret-access protocols: fail fast on a missing secret, never on a silent default.

Missing keys raise :class:SecretNotFound; they never return None and risk silently substituting an insecure default.

AsyncSecretStore

Bases: Protocol

The async counterpart of :class:SecretStore.

get_secret(key) async

Return the secret value for key.

Raises:

Type Description
SecretNotFound

No secret exists for key.

EnvSecretStore(*, prefix='')

Reads secrets from the process environment. The local/dev default.

get_secret("db-password") reads DB_PASSWORD — the key is upper-cased, - is replaced with _, and prefix (upper-cased, with a trailing _ if not already present) is prepended.

Initialize :class:EnvSecretStore.

Parameters:

Name Type Description Default
prefix str

Prepended to every environment variable name looked up, e.g. prefix="myapp" maps get_secret("db-password") to MYAPP_DB_PASSWORD.

''

get_secret(key)

Return the environment variable value mapped from key.

Raises:

Type Description
SecretNotFound

The mapped environment variable is unset or blank.

SecretNotFound(message, *message_args, error_code=-1, **error_data)

Bases: AppException

The named secret does not exist in the backing store.

check(value, message, *message_args, **kwargs) classmethod

Raise this exception if value is falsy.

Parameters:

Name Type Description Default
value Any

The value to test.

required
message str

Exception message (supports positional format args).

required
*message_args Any

Forwarded to message.format().

()
**kwargs Any

Forwarded as error_code / error_data to the constructor.

{}

Example::

AppException.check(path.exists(), "Missing file: {}", path, error_code=404)

SecretStore

Bases: Protocol

A synchronous secret-lookup protocol.

get_secret(key)

Return the secret value for key.

Raises:

Type Description
SecretNotFound

No secret exists for key.