Package org.springframework.vault.core
Class ReactiveVaultTemplate
java.lang.Object
org.springframework.vault.core.ReactiveVaultTemplate
- All Implemented Interfaces:
ReactiveVaultOperations
This class encapsulates main Vault interaction.
ReactiveVaultTemplate
will log
into Vault on initialization and use the token throughout the whole lifetime.- Since:
- 2.0
- Author:
- Mark Paluch, Raoof Mohammed, James Luke, Timothy R. Weiand
- See Also:
-
Constructor Summary
ConstructorDescriptionReactiveVaultTemplate
(VaultEndpointProvider endpointProvider, ClientHttpConnector connector) ReactiveVaultTemplate
(VaultEndpointProvider endpointProvider, ClientHttpConnector connector, VaultTokenSupplier vaultTokenSupplier) Create a newReactiveVaultTemplate
with aVaultEndpointProvider
,ClientHttpConnector
andVaultTokenSupplier
.ReactiveVaultTemplate
(VaultEndpoint vaultEndpoint, ClientHttpConnector connector) ReactiveVaultTemplate
(VaultEndpoint vaultEndpoint, ClientHttpConnector connector, VaultTokenSupplier vaultTokenSupplier) Create a newReactiveVaultTemplate
with aVaultEndpoint
,ClientHttpConnector
andVaultTokenSupplier
.ReactiveVaultTemplate
(WebClientBuilder webClientBuilder) Create a newReactiveVaultTemplate
through aWebClientBuilder
.ReactiveVaultTemplate
(WebClientBuilder webClientBuilder, VaultTokenSupplier vaultTokenSupplier) -
Method Summary
Modifier and TypeMethodDescriptionDelete a path.protected WebClient
doCreateSessionWebClient
(VaultEndpointProvider endpointProvider, ClientHttpConnector connector) Create a session-boundWebClient
to be used byVaultTemplate
for Vault communication givenVaultEndpointProvider
andClientHttpConnector
for calls that require an authenticated context.protected WebClient
doCreateWebClient
(VaultEndpointProvider endpointProvider, ClientHttpConnector connector) Create aWebClient
to be used byReactiveVaultTemplate
for Vault communication givenVaultEndpointProvider
andClientHttpConnector
.<V,
T extends org.reactivestreams.Publisher<V>>
TdoWithSession
(Function<WebClient, ? extends T> sessionCallback) Executes a VaultRestOperationsCallback
.<V,
T extends org.reactivestreams.Publisher<V>>
TdoWithVault
(Function<WebClient, ? extends T> clientCallback) Executes a VaultRestOperationsCallback
.Enumerate keys from a Vault path.opsForKeyValue
(String path, VaultKeyValueOperationsSupport.KeyValueBackend apiVersion) opsForTransit
(String path) ReturnReactiveVaultTransitOperations
if the transit backend is mounted on a different path thantransit
.Read from a Vault path.<T> Mono<VaultResponseSupport<T>>
Read from a Vault path.Write to a Vault path.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.vault.core.ReactiveVaultOperations
write
-
Constructor Details
-
ReactiveVaultTemplate
Create a newReactiveVaultTemplate
with aVaultEndpoint
,ClientHttpConnector
. This constructor does not use aVaultTokenSupplier
. It is intended for usage with Vault Agent to inherit Vault Agent's authentication without using theauthentication token header
.- Parameters:
vaultEndpoint
- must not be null.connector
- must not be null.- Since:
- 2.2.1
-
ReactiveVaultTemplate
public ReactiveVaultTemplate(VaultEndpoint vaultEndpoint, ClientHttpConnector connector, VaultTokenSupplier vaultTokenSupplier) Create a newReactiveVaultTemplate
with aVaultEndpoint
,ClientHttpConnector
andVaultTokenSupplier
.- Parameters:
vaultEndpoint
- must not be null.connector
- must not be null.vaultTokenSupplier
- must not be null.
-
ReactiveVaultTemplate
Create a newReactiveVaultTemplate
with aVaultEndpointProvider
andClientHttpConnector
. This constructor does not use aVaultTokenSupplier
. It is intended for usage with Vault Agent to inherit Vault Agent's authentication without using theauthentication token header
.- Parameters:
endpointProvider
- must not be null.connector
- must not be null.- Since:
- 2.2.1
-
ReactiveVaultTemplate
public ReactiveVaultTemplate(VaultEndpointProvider endpointProvider, ClientHttpConnector connector, VaultTokenSupplier vaultTokenSupplier) Create a newReactiveVaultTemplate
with aVaultEndpointProvider
,ClientHttpConnector
andVaultTokenSupplier
.- Parameters:
endpointProvider
- must not be null.connector
- must not be null.vaultTokenSupplier
- must not be null.
-
ReactiveVaultTemplate
Create a newReactiveVaultTemplate
through aWebClientBuilder
. This constructor does not use aVaultTokenSupplier
. It is intended for usage with Vault Agent to inherit Vault Agent's authentication without using theauthentication token header
.- Parameters:
webClientBuilder
- must not be null.- Since:
- 2.2.1
-
ReactiveVaultTemplate
public ReactiveVaultTemplate(WebClientBuilder webClientBuilder, VaultTokenSupplier vaultTokenSupplier) - Parameters:
webClientBuilder
- must not be null.vaultTokenSupplier
- must not be null- Since:
- 2.2
-
-
Method Details
-
doCreateWebClient
protected WebClient doCreateWebClient(VaultEndpointProvider endpointProvider, ClientHttpConnector connector) Create aWebClient
to be used byReactiveVaultTemplate
for Vault communication givenVaultEndpointProvider
andClientHttpConnector
.VaultEndpointProvider
is used to contribute host and port details for relative URLs typically used by the Template API. Subclasses may override this method to customize theWebClient
.- Parameters:
endpointProvider
- must not be null.connector
- must not be null.- Returns:
- the
WebClient
used for Vault communication. - Since:
- 2.1
-
doCreateSessionWebClient
protected WebClient doCreateSessionWebClient(VaultEndpointProvider endpointProvider, ClientHttpConnector connector) Create a session-boundWebClient
to be used byVaultTemplate
for Vault communication givenVaultEndpointProvider
andClientHttpConnector
for calls that require an authenticated context.VaultEndpointProvider
is used to contribute host and port details for relative URLs typically used by the Template API. Subclasses may override this method to customize theWebClient
.- Parameters:
endpointProvider
- must not be null.connector
- must not be null.- Returns:
- the
WebClient
used for Vault communication. - Since:
- 2.1
-
opsForSys
- Specified by:
opsForSys
in interfaceReactiveVaultOperations
- Returns:
- the operations interface administrative Vault access.
-
opsForTransit
- Specified by:
opsForTransit
in interfaceReactiveVaultOperations
- Returns:
- the operations interface to interact with the Vault transit backend.
-
opsForTransit
Description copied from interface:ReactiveVaultOperations
ReturnReactiveVaultTransitOperations
if the transit backend is mounted on a different path thantransit
.- Specified by:
opsForTransit
in interfaceReactiveVaultOperations
- Parameters:
path
- the mount path- Returns:
- the operations interface to interact with the Vault transit backend.
-
opsForKeyValue
public ReactiveVaultKeyValueOperations opsForKeyValue(String path, VaultKeyValueOperationsSupport.KeyValueBackend apiVersion) - Specified by:
opsForKeyValue
in interfaceReactiveVaultOperations
-
opsForVersionedKeyValue
Description copied from interface:ReactiveVaultOperations
- Specified by:
opsForVersionedKeyValue
in interfaceReactiveVaultOperations
- Parameters:
path
- the mount path- Returns:
- the operations interface to interact with the versioned Vault Key/Value (version 2) backend.
-
read
Description copied from interface:ReactiveVaultOperations
Read from a Vault path. Reading data using this method is suitable for API calls/secret backends that do not require a request body.- Specified by:
read
in interfaceReactiveVaultOperations
- Parameters:
path
- must not be null.- Returns:
- the data. May be empty if the path does not exist.
-
read
Description copied from interface:ReactiveVaultOperations
Read from a Vault path. Reading data using this method is suitable for API calls/secret backends that do not require a request body.- Specified by:
read
in interfaceReactiveVaultOperations
- Parameters:
path
- must not be null.responseType
- must not be null.- Returns:
- the data. May be empty if the path does not exist.
-
list
Description copied from interface:ReactiveVaultOperations
Enumerate keys from a Vault path.- Specified by:
list
in interfaceReactiveVaultOperations
- Parameters:
path
- must not be null.- Returns:
- the data. May be empty if the path does not exist.
-
write
Description copied from interface:ReactiveVaultOperations
Write to a Vault path.- Specified by:
write
in interfaceReactiveVaultOperations
- Parameters:
path
- must not be null.body
- the body, may be null if absent.- Returns:
- the response. May be empty if the response has no body.
-
delete
Description copied from interface:ReactiveVaultOperations
Delete a path.- Specified by:
delete
in interfaceReactiveVaultOperations
- Parameters:
path
- must not be null.
-
doWithVault
public <V,T extends org.reactivestreams.Publisher<V>> T doWithVault(Function<WebClient, ? extends T> clientCallback) throws VaultException, WebClientExceptionDescription copied from interface:ReactiveVaultOperations
Executes a VaultRestOperationsCallback
. Allows to interact with Vault usingRestOperations
without requiring a session.- Specified by:
doWithVault
in interfaceReactiveVaultOperations
- Parameters:
clientCallback
- the request.- Returns:
- the
RestOperationsCallback
return value. - Throws:
VaultException
- when aHttpStatusCodeException
occurs.WebClientException
- exceptions fromWebClient
.
-
doWithSession
public <V,T extends org.reactivestreams.Publisher<V>> T doWithSession(Function<WebClient, ? extends T> sessionCallback) throws VaultException, WebClientExceptionDescription copied from interface:ReactiveVaultOperations
Executes a VaultRestOperationsCallback
. Allows to interact with Vault in an authenticated session.- Specified by:
doWithSession
in interfaceReactiveVaultOperations
- Parameters:
sessionCallback
- the request.- Returns:
- the
RestOperationsCallback
return value. - Throws:
VaultException
- when aHttpStatusCodeException
occurs.WebClientException
- exceptions fromWebClient
.
-