Package org.springframework.vault.core
Interface VaultOperations
- All Known Implementing Classes:
VaultTemplate
public interface VaultOperations
Central entrypoint for performing Vault operations on a reactive runtime.
Implemented by VaultTemplate, this
interface exposes reactive APIs for interacting with Vault backends such as
Key/Value, Transit and sys. It supports callback-style execution for
both authenticated
doWithSession and unauthenticated doWithVault access.
Paths used with this and other Template
API interfaces are typically relative to the VaultEndpoint of the
underlying VaultClient. If the client is configured without an
endpoint, fully-qualified URIs can be used.
Note that operations apply authentication and other headers regardless of using relative or absolute URIs. To prevent unwanted access to external endpoints using authentication headers, applications should sanitize paths to avoid unwanted access to external endpoints.
- Author:
- Mark Paluch, Lauren Voswinkel
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidDelete a path.<T extends @Nullable Object>
TdoWithSession(RestOperationsCallback<T> sessionCallback) Executes a VaultRestOperationsCallback.<T extends @Nullable Object>
TdoWithVault(RestOperationsCallback<T> clientCallback) Executes a VaultRestOperationsCallback.default VaultResponseInvoke an operation on a Vault path, typically aPOSTrequest along with an optional request body expecting a response.Enumerate keys from a Vault path.opsForKeyValue(String path) ReturnVaultKeyValueOperationsand determine theversionby querying Vault.opsForKeyValue(String path, VaultKeyValueOperationsSupport.KeyValueBackend apiVersion) ReturnVaultKeyValueOperations.ReturnVaultPkiOperationsif the PKI secrets engine is mounted on a different path thanpki.opsForTransform(String path) ReturnVaultTransformOperationsif the transit secrets engine is mounted on a different path thantransform.opsForTransit(String path) ReturnVaultTransitOperationsif the transit secrets engine is mounted on a different path thantransit.ReturnVaultVersionedKeyValueOperations.@Nullable VaultResponseRead (GET)from a Vault path.<T extends @Nullable Object>
@Nullable VaultResponseSupport<T>Read (GET)from a secrets engine.default VaultResponsereadRequired(String path) Read (GET)from a Vault path.default <T> VaultResponseSupport<T>readRequired(String path, Class<T> responseType) Read (GET)from a secrets engine.default @Nullable VaultResponseWrite (POST)to a Vault path.@Nullable VaultResponseWrite (POST)to a Vault path.
-
Method Details
-
opsForKeyValue
ReturnVaultKeyValueOperationsand determine theversionby querying Vault. Paths used with this method must be relative to the given mountpath.- Parameters:
path- the mount path, must not be empty or null.- Returns:
- the operations interface to interact with the Vault Key/Value secrets engine.
- Since:
- 4.1
-
opsForKeyValue
VaultKeyValueOperations opsForKeyValue(String path, VaultKeyValueOperationsSupport.KeyValueBackend apiVersion) ReturnVaultKeyValueOperations. Paths used with this method must be relative to the given mountpath.- Parameters:
path- the mount path, must not be empty or null.apiVersion- API version to use, must not be null.- Returns:
- the operations interface to interact with the Vault Key/Value secrets engine.
- Since:
- 2.1
-
opsForVersionedKeyValue
ReturnVaultVersionedKeyValueOperations.- Parameters:
path- the mount path- Returns:
- the operations interface to interact with the versioned Vault Key/Value (version 2) secrets engine.
- Since:
- 2.1
-
opsForPki
VaultPkiOperations opsForPki()- Returns:
- the operations interface to interact with the Vault PKI secrets engine.
-
opsForPki
ReturnVaultPkiOperationsif the PKI secrets engine is mounted on a different path thanpki.- Parameters:
path- the mount path- Returns:
- the operations interface to interact with the Vault PKI secrets engine.
-
opsForSys
VaultSysOperations opsForSys()- Returns:
- the operations interface administrative Vault access.
-
opsForToken
VaultTokenOperations opsForToken()- Returns:
- the operations interface to interact with Vault token.
-
opsForTransform
VaultTransformOperations opsForTransform()- Returns:
- the operations interface to interact with the Vault transform secrets engine.
- Since:
- 2.3
-
opsForTransform
ReturnVaultTransformOperationsif the transit secrets engine is mounted on a different path thantransform.- Parameters:
path- the mount path- Returns:
- the operations interface to interact with the Vault transform secrets engine.
- Since:
- 2.3
-
opsForTransit
VaultTransitOperations opsForTransit()- Returns:
- the operations interface to interact with the Vault transit secrets engine.
-
opsForTransit
ReturnVaultTransitOperationsif the transit secrets engine is mounted on a different path thantransit.- Parameters:
path- the mount path- Returns:
- the operations interface to interact with the Vault transit secrets engine.
-
opsForWrapping
VaultWrappingOperations opsForWrapping()- Returns:
- the operations interface to interact with the Vault system/wrapping endpoints.
- Since:
- 2.1
-
read
Read (GET)from a Vault path. Reading data using this method is suitable for API calls/secrets engines that do not require a request body.- Parameters:
path- must not be null.- Returns:
- the data. May be null if the path does not exist.
-
readRequired
Read (GET)from a Vault path. Reading data using this method is suitable for API calls/secrets engines that do not require a request body.- Parameters:
path- must not be null.- Returns:
- the data.
- Throws:
SecretNotFoundException- if the path does not exist.- Since:
- 4.0
-
read
<T extends @Nullable Object> @Nullable VaultResponseSupport<T> read(String path, Class<T> responseType) Read (GET)from a secrets engine. Reading data using this method is suitable for secrets engines that do not require a request body.- Parameters:
path- must not be null.responseType- must not be null.- Returns:
- the data. May be null if the path does not exist.
-
readRequired
Read (GET)from a secrets engine. Reading data using this method is suitable for secrets engines that do not require a request body.- Parameters:
path- must not be null.responseType- must not be null.- Returns:
- the data.
- Throws:
SecretNotFoundException- if the path does not exist.- Since:
- 4.0
-
list
Enumerate keys from a Vault path.- Parameters:
path- must not be null.- Returns:
- the data. May be null if the path does not exist.
-
write
Write (POST)to a Vault path.- Parameters:
path- must not be null.- Returns:
- the response, may be null.
- Since:
- 2.0
-
write
Write (POST)to a Vault path.- Parameters:
path- must not be null.body- the body, may be null if absent.- Returns:
- the response, may be null.
-
invoke
Invoke an operation on a Vault path, typically aPOSTrequest along with an optional request body expecting a response.- Parameters:
path- must not be null.body- the body, may be null if absent.- Returns:
- the response.
- Throws:
IllegalStateException- if the operation returns without returning a response.- Since:
- 4.0
-
delete
Delete a path.- Parameters:
path- must not be null.
-
doWithVault
<T extends @Nullable Object> T doWithVault(RestOperationsCallback<T> clientCallback) throws VaultException, RestClientException Executes a VaultRestOperationsCallback. Allows to interact with Vault usingRestOperationswithout requiring a session.- Parameters:
clientCallback- the request.- Returns:
- the
RestOperationsCallbackreturn value. - Throws:
VaultException- when aHttpStatusCodeExceptionoccurs.RestClientException- exceptions fromRestOperations.
-
doWithSession
<T extends @Nullable Object> T doWithSession(RestOperationsCallback<T> sessionCallback) throws VaultException, RestClientException Executes a VaultRestOperationsCallback. Allows to interact with Vault in an authenticated session. Operations without a session manager orClientAuthenticationdo not attach a session token and behave likedoWithVault(RestOperationsCallback).- Parameters:
sessionCallback- the request.- Returns:
- the
RestOperationsCallbackreturn value. - Throws:
VaultException- when aHttpStatusCodeExceptionoccurs.RestClientException- exceptions fromRestOperations.
-