EnvSecrets¶
Sensitive values supplied by the process environment and, optionally, a
.env file.
Build one from Env.vars at startup, and hand each component the values it
needs. It is val, so it can be shared between actors, and every value it
returns is already wrapped in a Sensitive[String].
Every environment value is wrapped, whether or not it is a secret, because
which names are secret is not something this package can know. PATH and
LOG_LEVEL come back as Sensitive[String] too, and exposing them costs
the same deliberate act as exposing a password. Read ordinary configuration
from Env.vars directly, so that a call to expose stays a signal.
Use ReadEnvSecrets to take a .env file into
account as well.
use "sensitive"
actor Main
new create(env: Env) =>
let secrets = EnvSecrets(env.vars)
try
let password = secrets("DB_PASSWORD")?
env.out.print("The password is " + password.string())
else
env.out.print("DB_PASSWORD is not set")
end
Constructors¶
create¶
Read the NAME=VALUE entries of vars, which is Env.vars in the usual
case. The value is everything after the first =, taken verbatim. An
entry with no =, or with an empty name, is ignored. Where one name is
set twice, the first of them wins, which is what getenv returns.
Parameters¶
Returns¶
- EnvSecrets val^
Public Functions¶
apply¶
The value bound to name. Raises an error if name is not bound.
Parameters¶
- name: String val