Package com.veeva.vault.vapil.api.client
Class VaultClient
java.lang.Object
com.veeva.vault.vapil.api.client.VaultClient
Base class for all Vault integration calls where a Vault session is established via:
1. Basic authentication using Vault user name and password
2. Existing Vault session, such as a session passed from Vault Web Action/Tab or Vault Job Scheduler
3. OAuth
1. Basic authentication using Vault user name and password
2. Existing Vault session, such as a session passed from Vault Web Action/Tab or Vault Job Scheduler
3. OAuth
New API requests are created via the "newRequest" method, passing in the request class to instantiate.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Type of Authentication with the Vault APIstatic class
static class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
getAPIEndpoint
(boolean includeVersion) Get the fully formed root API URL consisting of the Vault DNSgetAPIEndpoint
(String endpoint) Get a fully formed API URL consisting of the Vault DNS, API version, and the API endpoint.getAPIEndpoint
(String endpoint, boolean includeVersion) Get a fully formed API URL consisting of the Vault DNS, API version, and the API endpoint.getHrefEndpoint
(String href) getLoginEndpoint
(String endpoint) Get a fully formed API URL consisting of the Vault login URL and the API endpoint.getPaginationEndpoint
(String pageUrl) Get a fully formed API URL consisting of the Vault DNS, API version, and the API endpoint.Returns the session ID from the Vault client's auth response.Returns the user ID from the Vault client's auth response.boolean
Check if the Vault client has an auth response with a session ID.Indicates whether or not to log api errors.static VaultClient.Builder
newClientBuilder
(VaultClient.AuthenticationType authenticationType) Create a new instance of aVaultClient.Builder
static VaultClient.Builder
newClientBuilderFromSettings
(VaultClient.Settings vaultClientSettings) static VaultClient.Builder
newClientBuilderFromSettings
(File settingsFile) Create a new instance of aVaultClient.Builder
with client parameters initialized from a .json filestatic VaultClient.Builder
newClientBuilderFromSettings
(String settingsJson) Create a new instance of aVaultClient.Builder
with client parameters initialized from a JSON string<T> T
newRequest
(Class<T> requestClass) Instantiate a new request to the Vault API endpoint.void
setAllowAllCertificates
(boolean allowAllCertificates) Allow Vault Client to trust all certificatesprotected void
setAuthenticationResponse
(AuthenticationResponse authenticationResponse) 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 requestsvoid
setVaultDNS
(String vaultDNS) boolean
Validate the current sessionId.
-
Field Details
-
VAULT_API_VERSION
The current Vault API Version "v25.1". This variable drives the version used in all API calls.- See Also:
-
-
Constructor Details
-
VaultClient
protected VaultClient()
-
-
Method Details
-
newRequest
Instantiate a new request to the Vault API endpoint.The Vault Client Id is required for all new requests. An error is thrown if no client id is set.
- Type Parameters:
T
- The request class to instantiate- Parameters:
requestClass
- The request class to instantiate- Returns:
- Object of the instantiated class
-
getVaultDNS
- Returns:
- Vault DNS in format "myvault.veevavault.com"
-
setVaultDNS
- Parameters:
vaultDNS
- Vault DNS in format "myvault.veevavault.com"
-
getVaultUrl
- Returns:
- Vault URL in format "https://myvault.veevavault.com"
-
getUsername
- Returns:
- Vault user name
-
getPassword
- Returns:
- Vault user password
-
setPassword
- Parameters:
password
- to set
-
setUsername
- Parameters:
username
- to set
-
getVaultClientId
- Returns:
- The client id for Vault API calls
-
setVaultClientId
Set the client id for Vault API requests- Parameters:
vaultClientId
- Vault Client Id
-
setAllowAllCertificates
public void setAllowAllCertificates(boolean allowAllCertificates) Allow Vault Client to trust all certificates- Parameters:
allowAllCertificates
- true/false
-
getAllowAllCertificates
public boolean getAllowAllCertificates() -
getAPIEndpoint
Get the fully formed root API URL consisting of the Vault DNS- Parameters:
includeVersion
- include version- Returns:
- URL for the API endpoint in form https://myvault.com/api/{version}
-
getAPIEndpoint
Get a fully formed API URL consisting of the Vault DNS, API version, and the API endpoint.- Parameters:
endpoint
- API endpoint in form "/objects/documents"- Returns:
- URL for the API endpoint in form https://myvault.com/api/{version}/objects/documents
-
getAPIEndpoint
Get a fully formed API URL consisting of the Vault DNS, API version, and the API endpoint.- Parameters:
endpoint
- API endpoint in form "/objects/documents"includeVersion
- include version in final endpoint- Returns:
- URL for the API endpoint in form: includeVersion(true) - https://myvault.com/api/{version}/objects/documents includeVersion(false) - https://myvault.com/api/mdl/components
-
getLoginEndpoint
Get a fully formed API URL consisting of the Vault login URL and the API endpoint.- Parameters:
endpoint
- API endpoint in form "/objects/documents"- Returns:
- URL for the API endpoint in form https://login.veevavault.com/auth/discovery
-
getPaginationEndpoint
Get a fully formed API URL consisting of the Vault DNS, API version, and the API endpoint.- Parameters:
pageUrl
- The URL from the previous_page or next_page parameter- Returns:
- URL for the API endpoint in form https://myvault.com/api/{version}/objects/documents
-
getHrefEndpoint
-
getAuthenticationResponse
- Returns:
- The response from an authentication request, which includes the Vault session id and the vaults that the user has access to. Note that only the session id is set if VaultConnection was instantiated with an existing Vault session (since an authentication call was not performed).
-
getSessionId
Returns the session ID from the Vault client's auth response.- Returns:
- The Vault session id from an Authentication Response
-
hasSessionId
public boolean hasSessionId()Check if the Vault client has an auth response with a session ID.- Returns:
- true if the Vault Client has an auth response with a session id.
-
getUserId
Returns the user ID from the Vault client's auth response. Note that this will return null if VaultConnection was instantiated with an existing Vault session (since an authentication call was not performed).- Returns:
- The user id for the authenticated user
-
setLogApiErrors
Sets whether or not to log api errors. Default=true- Parameters:
logApiErrors
- true/false- Returns:
VaultClient
-
isLogApiErrorsEnabled
Indicates whether or not to log api errors. Default=true- Returns:
- true/false
-
setAuthenticationResponse
-
validateSession
public boolean validateSession()Validate the current sessionId. The session must be active and the vaultDNS from the request and the response must equal. If the session or vaultDNS is not valid, the current sessionId will be cleared and an error logged.- Returns:
- true if the session is valid.
-
newClientBuilder
public static VaultClient.Builder newClientBuilder(VaultClient.AuthenticationType authenticationType) Create a new instance of aVaultClient.Builder
- Parameters:
authenticationType
-VaultClient.AuthenticationType
- Returns:
VaultClient.Builder
-
newClientBuilderFromSettings
Create a new instance of aVaultClient.Builder
with client parameters initialized from a .json fileExample
File settingsFile = new File("settings.json"); VaultClient vaultClient = VaultClient .newClientBuilderFromSettings(settingsFile) .build();
- Parameters:
settingsFile
- settings from a .json file- Returns:
VaultClient.Builder
-
newClientBuilderFromSettings
Create a new instance of aVaultClient.Builder
with client parameters initialized from a JSON stringExample
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();
- Parameters:
settingsJson
- settings in JSON format- Returns:
VaultClient.Builder
-
newClientBuilderFromSettings
public static VaultClient.Builder newClientBuilderFromSettings(VaultClient.Settings vaultClientSettings)
-