public class VaultClient extends VaultAccessor
HTTP methods
. VaultClient
is configured with an VaultEndpoint
and
RestTemplate
. It does not maintain any session or token state. See VaultTemplate
and
SessionManager
for authenticated and stateful Vault access.
VaultClient
encapsulates base URI and path construction and uses VaultAccessor
for request and error
handling by returning VaultResponseEntity
for requests.VaultResponseEntity
,
VaultTemplate
VaultAccessor.RestTemplateCallback<T>
Modifier and Type | Field and Description |
---|---|
static String |
VAULT_TOKEN |
Constructor and Description |
---|
VaultClient()
|
VaultClient(RestTemplate restTemplate,
VaultEndpoint endpoint)
|
Modifier and Type | Method and Description |
---|---|
protected URI |
buildUri(String pathTemplate,
Map<String,?> uriVariables)
|
static HttpHeaders |
createHeaders(VaultToken vaultToken)
Create
HttpHeaders for a VaultToken . |
<T,S extends T> |
deleteForEntity(String path,
VaultToken vaultToken,
Class<T> responseType)
Delete a resource by DELETEing from the path, and returns the response as
VaultResponseEntity . |
<T> T |
doWithRestTemplate(String pathTemplate,
Map<String,?> uriVariables,
VaultAccessor.RestTemplateCallback<T> callback)
Executes a
RestTemplateCallback . |
<T,S extends T> |
exchange(String pathTemplate,
HttpMethod method,
HttpEntity<?> requestEntity,
Class<T> responseType,
Map<String,?> uriVariables)
Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the
response as
VaultResponseEntity . |
<T,S extends T> |
exchange(String pathTemplate,
HttpMethod method,
HttpEntity<?> requestEntity,
ParameterizedTypeReference<T> responseType,
Map<String,?> uriVariables)
Execute the HTTP method to the given path template, writing the given request entity to the request, and returns
the response as
VaultResponseEntity . |
VaultEndpoint |
getEndpoint() |
<T,S extends T> |
getForEntity(String path,
Class<T> responseType)
Retrieve a resource by GETting from the path, and returns the response as
VaultResponseEntity . |
<T,S extends T> |
getForEntity(String path,
VaultToken vaultToken,
Class<T> responseType)
Retrieve a resource by GETting from the path, and returns the response as
VaultResponseEntity . |
<T,S extends T> |
postForEntity(String path,
Object request,
Class<T> responseType)
Issue a POST request using the given object to the path, and returns the response as
VaultResponseEntity . |
<T,S extends T> |
postForEntity(String path,
VaultToken vaultToken,
Object request,
Class<T> responseType)
Issue a POST request using the given object to the path, and returns the response as
VaultResponseEntity . |
<T,S extends T> |
putForEntity(String path,
Object request,
Class<T> responseType)
Create a new resource by PUTting the given object to the path, and returns the response as
VaultResponseEntity . |
<T,S extends T> |
putForEntity(String path,
VaultToken vaultToken,
Object request,
Class<T> responseType)
Create a new resource by PUTting the given object to the path, and returns the response as
VaultResponseEntity . |
<T> T |
unwrap(String wrappedResponse,
Class<T> responseType)
Unwrap a wrapped response created by Vault Response Wrapping
|
doWithRestTemplate, exchange, exchange, getRestTemplate
public static final String VAULT_TOKEN
public VaultClient()
VaultEndpoint
public VaultClient(RestTemplate restTemplate, VaultEndpoint endpoint)
restTemplate
- must not be null.endpoint
- must not be null.public <T,S extends T> VaultResponseEntity<S> getForEntity(String path, Class<T> responseType)
VaultResponseEntity
.path
- the path.responseType
- the type of the return valueVaultResponseEntity
public <T,S extends T> VaultResponseEntity<S> getForEntity(String path, VaultToken vaultToken, Class<T> responseType)
VaultResponseEntity
.path
- the path.vaultToken
- the VaultToken
.responseType
- the type of the return valueVaultResponseEntity
public <T,S extends T> VaultResponseEntity<S> postForEntity(String path, Object request, Class<T> responseType)
VaultResponseEntity
.path
- the path.request
- the Object to be POSTed, may be null
.responseType
- the type of the return valueVaultResponseEntity
public <T,S extends T> VaultResponseEntity<S> postForEntity(String path, VaultToken vaultToken, Object request, Class<T> responseType)
VaultResponseEntity
.path
- the path.vaultToken
- the VaultToken
.request
- the Object to be POSTed, may be null
.responseType
- the type of the return valueVaultResponseEntity
public <T,S extends T> VaultResponseEntity<S> putForEntity(String path, Object request, Class<T> responseType)
VaultResponseEntity
.path
- the path.request
- the Object to be PUT.responseType
- the type of the return valueVaultResponseEntity
public <T,S extends T> VaultResponseEntity<S> putForEntity(String path, VaultToken vaultToken, Object request, Class<T> responseType)
VaultResponseEntity
.path
- the path.vaultToken
- the VaultToken
.request
- the Object to be PUT.responseType
- the type of the return valueVaultResponseEntity
public <T,S extends T> VaultResponseEntity<S> deleteForEntity(String path, VaultToken vaultToken, Class<T> responseType)
VaultResponseEntity
.path
- the path.vaultToken
- the VaultToken
.responseType
- the type of the return valueVaultResponseEntity
public <T,S extends T> VaultResponseEntity<S> exchange(String pathTemplate, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Map<String,?> uriVariables) throws RestClientException
VaultResponseEntity
. URI Template variables are using the given URI variables, if any.pathTemplate
- the path template.method
- the HTTP method (GET, POST, etc).requestEntity
- the entity (headers and/or body) to write to the request, may be null
.responseType
- the type of the return value.uriVariables
- the variables to expand in the template.RestClientException
public <T,S extends T> VaultResponseEntity<S> exchange(String pathTemplate, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, Map<String,?> uriVariables) throws RestClientException
VaultResponseEntity
. The given ParameterizedTypeReference
is used to pass generic
type information:
ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {}; ResponseEntity<List<MyBean>> response = client.exchange("http://example.com", HttpMethod.GET, null, myBean, null);
pathTemplate
- the path template.method
- the HTTP method (GET, POST, etc).requestEntity
- the entity (headers and/or body) to write to the request, may be null
.responseType
- the type of the return value.uriVariables
- the variables to expand in the template.RestClientException
public <T> T doWithRestTemplate(String pathTemplate, Map<String,?> uriVariables, VaultAccessor.RestTemplateCallback<T> callback)
RestTemplateCallback
. Allows to interact with the underlying RestTemplate
and benefit
from optional parameter expansion.pathTemplate
- the path template.uriVariables
- the variables to expand in the templatecallback
- the request.RestTemplateCallback
return value.public VaultEndpoint getEndpoint()
VaultEndpoint
.protected URI buildUri(String pathTemplate, Map<String,?> uriVariables)
URI
based on the given VaultEndpoint
and pathTemplate
. URI template
variables will be expanded using uriVariables
.pathTemplate
- must not be empty or null.uriVariables
- must not be null.UriComponentsBuilder
public static HttpHeaders createHeaders(VaultToken vaultToken)
HttpHeaders
for a VaultToken
.vaultToken
- must not be null.HttpHeaders
for a VaultToken
.Copyright © 2016 Pivotal Software, Inc.. All rights reserved.