Package com.mimecast.robin.util
Class VaultMagicProvider
java.lang.Object
com.mimecast.robin.util.VaultMagicProvider
Vault magic provider for integrating HashiCorp Vault secrets with Magic variables.
This utility bridges Vault secrets with the Magic variable system, allowing secrets to be referenced using the standard magic variable syntax: {$vaultSecretName}
Secrets are cached in memory after first retrieval to improve performance. The cache can be cleared to force re-fetching of secrets.
Example usage:
// Initialize with VaultClient
VaultMagicProvider.initialize(vaultClient);
// Register Vault paths for secrets
VaultMagicProvider.registerSecretPath("secret/data/robin/passwords");
// Use in magic variables
String config = "password={$vault.keystore.password}";
String replaced = Magic.magicReplace(config, session);
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static booleanprivate static final org.apache.logging.log4j.Loggerprivate static VaultClient -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringautoResolveAndFetch(String magicVariableName) Auto-resolves Vault path from magic variable name and fetches the secret.static voidClears the secrets cache, forcing re-fetch on next access.static StringGets a secret value by magic variable name.static voidinitialize(VaultClient client) Initializes the Vault magic provider with a VaultClient.static booleanChecks if Vault magic provider is initialized and enabled.
-
Field Details
-
log
private static final org.apache.logging.log4j.Logger log -
vaultClient
-
secretsCache
-
initialized
private static boolean initialized
-
-
Constructor Details
-
VaultMagicProvider
private VaultMagicProvider()Private constructor to prevent instantiation.
-
-
Method Details
-
initialize
Initializes the Vault magic provider with a VaultClient.- Parameters:
client- VaultClient instance.
-
isEnabled
public static boolean isEnabled()Checks if Vault magic provider is initialized and enabled.- Returns:
- true if initialized and Vault is enabled.
-
getSecret
Gets a secret value by magic variable name. Automatically resolves the Vault path from the magic variable name and fetches on-demand.- Parameters:
magicVariableName- Magic variable name (e.g., "vault.keystore.password").- Returns:
- Secret value, or null if not found.
-
autoResolveAndFetch
Auto-resolves Vault path from magic variable name and fetches the secret. Supports multiple path structures: - vault.keyname -> secret/data/vault with key "keyname" - vault.keystore.password -> secret/data/vault/keystore with key "password" - vault.api.key -> secret/data/vault/api with key "key"- Parameters:
magicVariableName- Magic variable name.- Returns:
- Secret value, or null if not found.
-
clearCache
public static void clearCache()Clears the secrets cache, forcing re-fetch on next access.
-