Interface SecretsProvider
- All Known Implementing Classes:
BaseSecretsProvider,InMemorySecretsProvider,SecretCache,VaultSecretsProvider
public interface SecretsProvider
Uniform secrets API shared by every secrets service (SPEC section 3). Missing secrets are
Optional.empty(); require(java.lang.String, codes.grow.packages.vault.secrets.GetOptions) and delete(java.lang.String, codes.grow.packages.vault.secrets.DeleteOptions) raise NotFoundException.
Every I/O method has an …Async variant returning CompletableFuture; the
defaults run the blocking method on a shared daemon executor (asyncExecutor()).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternJSON number grammar accepted bygetNumber(java.lang.String, codes.grow.packages.vault.secrets.GetOptions). -
Method Summary
Modifier and TypeMethodDescriptiondefault ExecutorReturns the executor of the default…Asyncmethods.default voidDeletes a secret with default options.voiddelete(String name, DeleteOptions opts) Deletes a secret.default CompletableFuture<Void> deleteAsync(String name, DeleteOptions opts) Asynchronousdelete(String, DeleteOptions).default booleanReturns whether a secret exists.default booleanexists(String name, GetOptions opts) Returns whether a secret exists.default CompletableFuture<Boolean> existsAsync(String name, GetOptions opts) Asynchronousexists(String, GetOptions).default Optional<SecretValue> Reads the latest version of a secret.get(String name, GetOptions opts) Reads a secret.Returns every secret directly underpath(not recursive), sorted by name.default CompletableFuture<Map<String, SecretValue>> getAllAsync(String path) AsynchronousgetAll(String).default CompletableFuture<Optional<SecretValue>> getAsync(String name, GetOptions opts) Asynchronousget(String, GetOptions).Reads a secret as a boolean.getBool(String name, GetOptions opts) Reads a secret as a boolean (true/false/1/0/yes/no/on/off, case-insensitive).default CompletableFuture<Optional<Boolean>> getBoolAsync(String name, GetOptions opts) AsynchronousgetBool(String, GetOptions).default <T> Optional<T> getJson(String name, com.fasterxml.jackson.core.type.TypeReference<T> type, GetOptions opts) Reads a secret as JSON into a generic type.default <T> Optional<T> Reads a secret as JSON.default <T> Optional<T> getJson(String name, Class<T> type, GetOptions opts) Reads a secret as JSON.default <T> CompletableFuture<Optional<T>> getJsonAsync(String name, Class<T> type, GetOptions opts) AsynchronousgetJson(String, Class, GetOptions).default Map<String, SecretValue> Reads several secrets.default Map<String, SecretValue> getMany(List<String> names, GetOptions opts) Reads several secrets; missing names are omitted, order follows the request.default CompletableFuture<Map<String, SecretValue>> getManyAsync(List<String> names, GetOptions opts) AsynchronousgetMany(List, GetOptions).Reads a secret as a number.getNumber(String name, GetOptions opts) Reads a secret as a number (JSON number syntax, surrounding whitespace ignored).default CompletableFuture<Optional<Double>> getNumberAsync(String name, GetOptions opts) AsynchronousgetNumber(String, GetOptions).Reads a secret as UTF-8 text.getString(String name, GetOptions opts) Reads a secret as UTF-8 text.default CompletableFuture<Optional<String>> getStringAsync(String name, GetOptions opts) AsynchronousgetString(String, GetOptions).default List<SecretMetadata> list()Lists every secret at the root.Lists secrets (names and metadata, never values) sorted by name.default CompletableFuture<List<SecretMetadata>> Asynchronouslist(String).loadEnv(String path, LoadEnvOptions opts) Sets one variable per secret directly underpath.loadEnv(Map<String, String> mapping, LoadEnvOptions opts) Sets each variable from its secret (envName → secretName).default Optional<SecretMetadata> Reads the latest metadata of a secret.metadata(String name, GetOptions opts) Reads a secret's metadata.default CompletableFuture<Optional<SecretMetadata>> metadataAsync(String name, GetOptions opts) Asynchronousmetadata(String, GetOptions).default SecretValueReads a secret that must exist.default SecretValuerequire(String name, GetOptions opts) Reads a secret that must exist.default CompletableFuture<SecretValue> requireAsync(String name, GetOptions opts) Asynchronousrequire(String, GetOptions).default StringWrites a secret with default options.set(String name, Object value, SetOptions opts) Writes a secret.default CompletableFuture<String> setAsync(String name, Object value, SetOptions opts) Asynchronousset(String, Object, SetOptions).default WatchHandlewatch(String name, Duration interval, WatchListener listener) Polls a secret without an error callback.watch(String name, Duration interval, WatchListener listener, WatchOptions opts) Polls a secret and reports changes (version, or SHA-256 of the value when unversioned), including deletion.
-
Field Details
-
NUMBER
JSON number grammar accepted bygetNumber(java.lang.String, codes.grow.packages.vault.secrets.GetOptions).
-
-
Method Details
-
get
Reads a secret.- Parameters:
name- full secret nameopts- version / path- Returns:
- the value, or empty when missing
-
getAll
Returns every secret directly underpath(not recursive), sorted by name.- Parameters:
path- folder / prefix; empty for the root- Returns:
- full name to value
-
list
Lists secrets (names and metadata, never values) sorted by name.- Parameters:
prefixOrPath- prefix or folder; empty for the root- Returns:
- the metadata
-
set
Writes a secret. AStringis stored as UTF-8,byte[]as is,SecretValue/Secretby their content, anything else JSON-encoded.- Parameters:
name- full secret namevalue- the valueopts- path / cas / tags / description- Returns:
- the new version, or
""when the service has no versions
-
delete
Deletes a secret.- Parameters:
name- full secret nameopts- path / versions / permanent- Throws:
NotFoundException- when the secret does not exist
-
metadata
Reads a secret's metadata.- Parameters:
name- full secret nameopts- version / path- Returns:
- the metadata, or empty when missing
-
watch
Polls a secret and reports changes (version, or SHA-256 of the value when unversioned), including deletion. Errors go toWatchOptions.onError()and polling continues.- Parameters:
name- full secret nameinterval- polling intervallistener- change callbackopts- error callback- Returns:
- the handle;
close()of the provider stops every watch
-
asyncExecutor
Returns the executor of the default…Asyncmethods.- Returns:
- a shared daemon executor
-
get
Reads the latest version of a secret.- Parameters:
name- full secret name- Returns:
- the value, or empty
-
getString
Reads a secret as UTF-8 text.- Parameters:
name- full secret nameopts- version / path- Returns:
- the text, or empty
- Throws:
ValidationException- when the value is binary
-
getString
Reads a secret as UTF-8 text.- Parameters:
name- full secret name- Returns:
- the text, or empty
-
getJson
Reads a secret as JSON.- Type Parameters:
T- target type- Parameters:
name- full secret nametype- target class (JsonNode.classorObject.classfor any JSON)opts- version / path- Returns:
- the decoded value, or empty
- Throws:
ValidationException- when the value is not JSON
-
getJson
Reads a secret as JSON.- Type Parameters:
T- target type- Parameters:
name- full secret nametype- target class- Returns:
- the decoded value, or empty
-
getJson
default <T> Optional<T> getJson(String name, com.fasterxml.jackson.core.type.TypeReference<T> type, GetOptions opts) Reads a secret as JSON into a generic type.- Type Parameters:
T- target type- Parameters:
name- full secret nametype- target type referenceopts- version / path- Returns:
- the decoded value, or empty
-
getNumber
Reads a secret as a number (JSON number syntax, surrounding whitespace ignored).- Parameters:
name- full secret nameopts- version / path- Returns:
- the number, or empty
- Throws:
ValidationException- when the value is not a number
-
getNumber
Reads a secret as a number.- Parameters:
name- full secret name- Returns:
- the number, or empty
-
getBool
Reads a secret as a boolean (true/false/1/0/yes/no/on/off, case-insensitive).- Parameters:
name- full secret nameopts- version / path- Returns:
- the boolean, or empty
- Throws:
ValidationException- when the value is not a boolean
-
getBool
Reads a secret as a boolean.- Parameters:
name- full secret name- Returns:
- the boolean, or empty
-
require
Reads a secret that must exist.- Parameters:
name- full secret nameopts- version / path- Returns:
- the value
- Throws:
NotFoundException- when missing
-
require
Reads a secret that must exist.- Parameters:
name- full secret name- Returns:
- the value
-
exists
Returns whether a secret exists.- Parameters:
name- full secret nameopts- version / path- Returns:
- true when present
-
exists
Returns whether a secret exists.- Parameters:
name- full secret name- Returns:
- true when present
-
getMany
Reads several secrets; missing names are omitted, order follows the request.- Parameters:
names- full secret namesopts- version / path applied to each- Returns:
- name to value
-
getMany
Reads several secrets.- Parameters:
names- full secret names- Returns:
- name to value
-
list
Lists every secret at the root.- Returns:
- the metadata sorted by name
-
set
Writes a secret with default options.- Parameters:
name- full secret namevalue- the value (seeset(String, Object, SetOptions))- Returns:
- the new version or
""
-
delete
Deletes a secret with default options.- Parameters:
name- full secret name
-
metadata
Reads the latest metadata of a secret.- Parameters:
name- full secret name- Returns:
- the metadata, or empty
-
loadEnv
Sets one variable per secret directly underpath. Java cannot change the process environment: variables become system properties (orLoadEnvOptions.target()). The name is the secret name relative topath, upper-cased, every character outside[A-Z0-9_]replaced by_, prefixed withLoadEnvOptions.prefix().- Parameters:
path- folder / prefixopts- override / prefix / target- Returns:
- variable name to secret name for every variable set (never values)
-
loadEnv
Sets each variable from its secret (envName → secretName).- Parameters:
mapping- variable name to secret nameopts- override / target- Returns:
- variable name to secret name for every variable set
- Throws:
NotFoundException- when a secret is missing (nothing is set then)
-
watch
Polls a secret without an error callback.- Parameters:
name- full secret nameinterval- polling intervallistener- change callback- Returns:
- the handle
-
getAsync
Asynchronousget(String, GetOptions).- Parameters:
name- full secret nameopts- version / path- Returns:
- a future with the value or empty
-
getStringAsync
AsynchronousgetString(String, GetOptions).- Parameters:
name- full secret nameopts- version / path- Returns:
- a future with the text or empty
-
getJsonAsync
default <T> CompletableFuture<Optional<T>> getJsonAsync(String name, Class<T> type, GetOptions opts) AsynchronousgetJson(String, Class, GetOptions).- Type Parameters:
T- target type- Parameters:
name- full secret nametype- target classopts- version / path- Returns:
- a future with the decoded value or empty
-
getNumberAsync
AsynchronousgetNumber(String, GetOptions).- Parameters:
name- full secret nameopts- version / path- Returns:
- a future with the number or empty
-
getBoolAsync
AsynchronousgetBool(String, GetOptions).- Parameters:
name- full secret nameopts- version / path- Returns:
- a future with the boolean or empty
-
requireAsync
Asynchronousrequire(String, GetOptions).- Parameters:
name- full secret nameopts- version / path- Returns:
- a future with the value, failed with
NotFoundExceptionwhen missing
-
existsAsync
Asynchronousexists(String, GetOptions).- Parameters:
name- full secret nameopts- version / path- Returns:
- a future with the flag
-
getManyAsync
default CompletableFuture<Map<String,SecretValue>> getManyAsync(List<String> names, GetOptions opts) AsynchronousgetMany(List, GetOptions).- Parameters:
names- full secret namesopts- version / path- Returns:
- a future with the map
-
getAllAsync
AsynchronousgetAll(String).- Parameters:
path- folder / prefix- Returns:
- a future with the map
-
listAsync
Asynchronouslist(String).- Parameters:
prefixOrPath- prefix or folder- Returns:
- a future with the metadata
-
setAsync
Asynchronousset(String, Object, SetOptions).- Parameters:
name- full secret namevalue- the valueopts- options- Returns:
- a future with the new version
-
deleteAsync
Asynchronousdelete(String, DeleteOptions).- Parameters:
name- full secret nameopts- options- Returns:
- a future completed when deleted
-
metadataAsync
Asynchronousmetadata(String, GetOptions).- Parameters:
name- full secret nameopts- version / path- Returns:
- a future with the metadata or empty
-