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 to fallback when it is absent. Use for genuinely optional configuration, never to paper over a missing secret.
has(String key) → bool
Whether key resolves 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 hook with the new value whenever key rotates.
rotate(String key, String value) → Future<void>
Reports that key now resolves to value, 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
text with 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 path instead of $CREDENTIALS_DIRECTORY; null reads none.
useEnvFile(String path) → void
Reads local-development values from path instead of ./.env.

Constants

minimumRedactableLength → const int
Below this length a value is not matched, and the reason is damage rather than laziness.