Class EnvVarSecretStore
- All Implemented Interfaces:
SecretStore
SecretStore backed by System.getenv(String).
Gives 12-factor deployments a zero-dependency way to feed secrets in as environment variables: find(java.lang.String) and
exists(java.lang.String) resolve straight from the process environment. Because the environment is immutable from within the
process, the mutating operations are unsupported:
store(String, char[])throwsUnsupportedOperationException.delete(String)throwsUnsupportedOperationException.
Note that environment variables are inherently more exposed than a dedicated secret backend (they are visible to
child processes and to anything that can read the process environment), so this store trades secrecy strength for
deployment simplicity. The retrieved value is never toString()'d, logged, or dumped by this class.
- Since:
- 10.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanDeletes the secret stored under the specified key.booleanReturns whether a secret is stored under the specified key without materializing its value.Optional<char[]>Returns the secret stored under the specified key.voidStores a secret under the specified key, replacing any existing value.
-
Constructor Details
-
EnvVarSecretStore
public EnvVarSecretStore()
-
-
Method Details
-
store
Description copied from interface:SecretStoreStores a secret under the specified key, replacing any existing value.The caller retains ownership of
secret and may zero it after this call returns; an implementation that needs to retain the value must copy it.- Specified by:
storein interfaceSecretStore- Parameters:
key- The key under which to store the secret. Must not benull .secret- The secret value. Must not benull .
-
find
Description copied from interface:SecretStoreReturns the secret stored under the specified key.The returned array is the caller's to own and zero; it is not a live view of the store's internal state.
- Specified by:
findin interfaceSecretStore- Parameters:
key- The key to look up. Must not benull .- Returns:
- The secret value, or
Optional.empty()if no secret is stored under the key.
-
exists
Description copied from interface:SecretStoreReturns whether a secret is stored under the specified key without materializing its value.- Specified by:
existsin interfaceSecretStore- Parameters:
key- The key to check. Must not benull .- Returns:
true if a secret is stored under the key.
-
delete
Description copied from interface:SecretStoreDeletes the secret stored under the specified key.- Specified by:
deletein interfaceSecretStore- Parameters:
key- The key to delete. Must not benull .- Returns:
true if a secret was present and removed;false if the key was already absent.
-