Environment
rn_forge.commons.runtime.environment
Typed environment-variable access with fail-fast startup guards.
Environment
Typed helpers for reading and writing environment variables.
forbid(name, *forbidden, message=None)
staticmethod
Raise if the value of name equals any of forbidden.
Intended for "the insecure default is still in place" guards, e.g.
Environment.forbid("SECRET_KEY", "change-me").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Environment variable to check. |
required |
*forbidden
|
str
|
Values that must not be the current value of name. |
()
|
message
|
str | None
|
Custom exception message. Defaults to a generic one naming name and the matched value. |
None
|
Raises:
| Type | Description |
|---|---|
AppException
|
The current value of name matches one of forbidden. |
get(name, default=None)
staticmethod
Return the value of name, or default if not set.
get_all()
staticmethod
Return a snapshot of all current environment variables.
is_enabled(name, default=False)
staticmethod
Return True when env var name is a truthy string.
Uses :func:parse_bool with strict=False; unrecognised values
fall back to default.
require(*names)
staticmethod
Return the values of names, raising if any is unset or blank.
A set-but-empty/whitespace-only variable counts as missing, same as
:meth:AppUtils.is_empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*names
|
str
|
Environment variable names that must all be present. |
()
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A mapping of |
Raises:
| Type | Description |
|---|---|
AppException
|
One or more variables are unset or empty. The message lists every missing name at once (not just the first), so a misconfigured deployment surfaces all problems in one run. |
Example::
cfg = Environment.require("DB_URL", "SECRET_KEY")
set(name, value)
staticmethod
Set environment variable name to value and return value.