Package com.mimecast.robin.util
Class VaultClient
java.lang.Object
com.mimecast.robin.util.VaultClient
HashiCorp Vault client utility for secrets management.
This utility provides methods to interact with HashiCorp Vault to fetch secrets securely. It supports both KV v1 and KV v2 secret engines.
Example usage:
VaultClient client = new VaultClient.Builder()
.withAddress("https://vault.example.com:8200")
.withToken("s.abc123xyz")
.build();
String secret = client.getSecret("secret/data/myapp/config", "password");
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for VaultClient.static classException thrown when Vault operations fail. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate final booleanprivate final com.google.gson.Gsonprivate final okhttp3.OkHttpClientprivate static final okhttp3.MediaTypeprivate static final org.apache.logging.log4j.Loggerprivate final Stringprivate final Stringprivate final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateVaultClient(VaultClient.Builder builder) Constructs a new VaultClient instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidconfigureTrustAllCerts(okhttp3.OkHttpClient.Builder builder) Configure the HTTP client to trust all certificates.getAllSecrets(String path) Fetches all secrets from a given path.Fetches a secret from Vault.booleanChecks if Vault integration is enabled.voidwriteSecret(String path, Map<String, String> secrets) Writes a secret to Vault.
-
Field Details
-
log
private static final org.apache.logging.log4j.Logger log -
JSON
private static final okhttp3.MediaType JSON -
DEFAULT_TIMEOUT
private static final int DEFAULT_TIMEOUT- See Also:
-
vaultAddress
-
vaultToken
-
namespace
-
httpClient
private final okhttp3.OkHttpClient httpClient -
gson
private final com.google.gson.Gson gson -
enabled
private final boolean enabled
-
-
Constructor Details
-
VaultClient
Constructs a new VaultClient instance.- Parameters:
builder- Builder instance with configuration.
-
-
Method Details
-
configureTrustAllCerts
private void configureTrustAllCerts(okhttp3.OkHttpClient.Builder builder) Configure the HTTP client to trust all certificates. WARNING: This should only be used in development environments.- Parameters:
builder- OkHttpClient.Builder to configure.
-
isEnabled
public boolean isEnabled()Checks if Vault integration is enabled.- Returns:
- true if enabled, false otherwise.
-
getSecret
Fetches a secret from Vault.- Parameters:
path- Path to the secret (e.g., "secret/data/myapp/config" for KV v2).key- Key within the secret to retrieve.- Returns:
- Secret value as string, or null if not found.
- Throws:
VaultClient.VaultException- if the request fails.
-
getAllSecrets
Fetches all secrets from a given path.- Parameters:
path- Path to the secret.- Returns:
- Map of all key-value pairs in the secret, or empty map if not found.
- Throws:
VaultClient.VaultException- if the request fails.
-
writeSecret
Writes a secret to Vault.- Parameters:
path- Path where the secret will be stored.secrets- Map of key-value pairs to store.- Throws:
VaultClient.VaultException- if the request fails.
-