DVSecrets class
Reads secrets from the process environment, then .env.
Resolution runs configured values first, then the process environment,
then the .env file. Configured values lead so that DV.Test.withSecrets
works: a developer with the variable exported in their shell would
otherwise break a suite that supplied its own, which is the thing that
helper exists to prevent. The environment leads over .env because a file
checked into a repository outlives the branch it was written on, and
letting it shadow the running machine's own setting is how a production
deploy picks up a development credential.
Secrets are deliberately not part of the generated client. Only
PUBLIC_-prefixed variables are compiled into env.g.dart; everything else
stays in the environment of the process that runs the code. That is why a
browser build has no environment to read: a secret compiled into a web
bundle is a secret published to every visitor. On the web, reach secrets
through a backend function instead.
Constructors
- DVSecrets()
-
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
get(
String key) → String -
The value of
key. -
getOr(
String key, String fallback) → String -
The value of
key, falling back tofallbackwhen it is absent. Use for genuinely optional configuration, never to paper over a missing secret. -
has(
String key) → bool -
Whether
keyresolves to a non-empty value. -
maybeGet(
String key) → String? -
The value of
key, or null when nothing provides it. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onRotate(
String key, FutureOr< void> hook(String value)) → void Function() -
Runs
hookwith the new value wheneverkeyrotates. -
rotate(
String key, String value) → Future< void> -
Reports that
keynow resolves tovalue, and runs its hooks. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
captureState(
) → DVSecretsState - Everything a test could change, for putting back afterwards.
-
configure(
Map< String, String> secrets) → void - Registers secrets explicitly. Intended for tests and for hosts that load secrets from a manager rather than the environment.
-
redact(
String text) → String -
textwith every resolved secret value replaced by dvRedactedMarker. -
reset(
) → void - Drops everything configure registered, every rotation hook, and every value redact would strike out.
-
restoreState(
DVSecretsState state) → void - Puts back what captureState took.
-
useCredentialsDirectory(
String? path) → void -
Reads supervisor credentials from
pathinstead of$CREDENTIALS_DIRECTORY; null reads none. -
useEnvFile(
String path) → void -
Reads local-development values from
pathinstead of./.env.
Constants
- minimumRedactableLength → const int
- Below this length a value is not matched, and the reason is damage rather than laziness.