public class VaultClient extends Object
New API requests are created via the "newRequest" method, passing in the request class to instantiate.
| Modifier and Type | Class and Description |
|---|---|
static class |
VaultClient.AuthenticationType
Type of Authentication with the Vault API
|
static class |
VaultClient.Builder |
static class |
VaultClient.Settings |
| Modifier and Type | Field and Description |
|---|---|
static String |
VAULT_API_VERSION
The current Vault API Version "v24.1".
|
| Modifier | Constructor and Description |
|---|---|
protected |
VaultClient() |
| Modifier and Type | Method and Description |
|---|---|
String |
getAPIEndpoint(boolean includeVersion)
Get the fully formed root API URL consisting of the Vault DNS
|
String |
getAPIEndpoint(String endpoint)
Get a fully formed API URL consisting of the Vault DNS,
API version, and the API endpoint.
|
String |
getAPIEndpoint(String endpoint,
boolean includeVersion)
Get a fully formed API URL consisting of the Vault DNS,
API version, and the API endpoint.
|
AuthenticationResponse |
getAuthenticationResponse() |
String |
getHrefEndpoint(String href) |
String |
getLoginEndpoint(String endpoint)
Get a fully formed API URL consisting of the Vault login URL
and the API endpoint.
|
String |
getPaginationEndpoint(String pageUrl)
Get a fully formed API URL consisting of the Vault DNS,
API version, and the API endpoint.
|
String |
getPassword() |
String |
getSessionId()
Returns the session ID from the Vault client's auth response.
|
String |
getUserId()
Returns the user ID from the Vault client's auth response.
|
String |
getUsername() |
String |
getVaultClientId() |
String |
getVaultDNS() |
String |
getVaultUrl() |
boolean |
hasSessionId()
Check if the Vault client has an auth response with a session ID.
|
Boolean |
isLogApiErrorsEnabled()
Indicates whether or not to log api errors.
|
static VaultClient.Builder |
newClientBuilder(VaultClient.AuthenticationType authenticationType)
Create a new instance of a
VaultClient.Builder |
static VaultClient.Builder |
newClientBuilderFromSettings(File settingsFile)
Create a new instance of a
VaultClient.Builder with client
parameters initialized from a .json file |
static VaultClient.Builder |
newClientBuilderFromSettings(String settingsJson)
Create a new instance of a
VaultClient.Builder with client
parameters initialized from a JSON string |
static VaultClient.Builder |
newClientBuilderFromSettings(VaultClient.Settings vaultClientSettings) |
<T> T |
newRequest(Class<T> requestClass)
Instantiate a new request to the Vault API endpoint.
|
protected void |
setAuthenticationResponse(AuthenticationResponse authenticationResponse) |
VaultClient |
setLogApiErrors(boolean logApiErrors)
Sets whether or not to log api errors.
|
void |
setPassword(String password) |
void |
setUsername(String username) |
protected void |
setVaultClientId(String vaultClientId)
Set the client id for Vault API requests
|
void |
setVaultDNS(String vaultDNS) |
boolean |
validateSession()
Validate the current sessionId.
|
public static final String VAULT_API_VERSION
public <T> T newRequest(Class<T> requestClass)
The Vault Client Id is required for all new requests. An error is thrown if no client id is set.
T - The request class to instantiaterequestClass - The request class to instantiatepublic String getVaultDNS()
public void setVaultDNS(String vaultDNS)
vaultDNS - Vault DNS in format "myvault.veevavault.com"public String getVaultUrl()
public String getUsername()
public String getPassword()
public void setPassword(String password)
password - to setpublic void setUsername(String username)
username - to setpublic String getVaultClientId()
protected void setVaultClientId(String vaultClientId)
vaultClientId - Vault Client Idpublic String getAPIEndpoint(boolean includeVersion)
includeVersion - include versionpublic String getAPIEndpoint(String endpoint)
endpoint - API endpoint in form "/objects/documents"public String getAPIEndpoint(String endpoint, boolean includeVersion)
endpoint - API endpoint in form "/objects/documents"includeVersion - include version in final endpointpublic String getLoginEndpoint(String endpoint)
endpoint - API endpoint in form "/objects/documents"public String getPaginationEndpoint(String pageUrl)
pageUrl - The URL from the previous_page or next_page parameterpublic AuthenticationResponse getAuthenticationResponse()
public String getSessionId()
public boolean hasSessionId()
public String getUserId()
public VaultClient setLogApiErrors(boolean logApiErrors)
logApiErrors - true/falseVaultClientpublic Boolean isLogApiErrorsEnabled()
protected void setAuthenticationResponse(AuthenticationResponse authenticationResponse)
public boolean validateSession()
public static VaultClient.Builder newClientBuilder(VaultClient.AuthenticationType authenticationType)
VaultClient.BuilderauthenticationType - VaultClient.AuthenticationTypeVaultClient.Builderpublic static VaultClient.Builder newClientBuilderFromSettings(File settingsFile)
VaultClient.Builder with client
parameters initialized from a .json file
Example
File settingsFile = new File("settings.json");
VaultClient vaultClient = VaultClient
.newClientBuilderFromSettings(settingsFile)
.build();
settingsFile - settings from a .json fileVaultClient.Builderpublic static VaultClient.Builder newClientBuilderFromSettings(String settingsJson)
VaultClient.Builder with client
parameters initialized from a JSON string
Example
String jsonString =
"{\n" +
" \"authenticationType\": \"BASIC\",\n" +
" \"idpOauthAccessToken\": \"\",\n" +
" \"idpOauthScope\": \"openid\",\n" +
" \"idpUsername\": \"\",\n" +
" \"idpPassword\": \"\",\n" +
" \"vaultUsername\": \"USERNAME\",\n" +
" \"vaultPassword\": \"PASSWORD\",\n" +
" \"vaultDNS\": \"DNS\",\n" +
" \"vaultSessionId\": \"\",\n" +
" \"vaultClientId\": \"veeva-vault-devsupport-client-vapil\",\n" +
" \"vaultOauthClientId\": \"\",\n" +
" \"vaultOauthProfileId\": \"\",\n" +
" \"logApiErrors\": true,\n" +
" \"httpTimeout\": null,\n" +
" \"validateSession\": true\n" +
"}";
VaultClient vaultClient = VaultClient
.newClientBuilderFromSettings(jsonString)
.build();
settingsJson - settings in JSON formatVaultClient.Builderpublic static VaultClient.Builder newClientBuilderFromSettings(VaultClient.Settings vaultClientSettings)
Copyright © 2024. All rights reserved.