Class VaultPropertySource


public class VaultPropertySource extends EnumerablePropertySource<VaultOperations>
PropertySource that reads keys and values from a VaultTemplate and path. Transforms properties after retrieving these from Vault using PropertyTransformer.
Author:
Mark Paluch
See Also:
  • Constructor Details

    • VaultPropertySource

      public VaultPropertySource(VaultOperations vaultOperations, String path)
      Create a new VaultPropertySource given a VaultTemplate and path inside of Vault. This property source loads properties upon construction.
      Parameters:
      vaultOperations - must not be null.
      path - the path inside Vault (e.g. secret/myapp/myproperties. Must not be empty or null.
    • VaultPropertySource

      public VaultPropertySource(String name, VaultOperations vaultOperations, String path)
      Create a new VaultPropertySource given a name, VaultTemplate and path inside of Vault. This property source loads properties upon construction.
      Parameters:
      name - name of the property source, must not be null.
      vaultOperations - must not be null.
      path - the path inside Vault (e.g. secret/myapp/myproperties. Must not be empty or null.
    • VaultPropertySource

      public VaultPropertySource(String name, VaultOperations vaultOperations, String path, PropertyTransformer propertyTransformer)
      Create a new VaultPropertySource given a name, VaultTemplate and path inside of Vault. This property source loads properties upon construction and transforms these by applying PropertyTransformer.
      Parameters:
      name - name of the property source, must not be null.
      vaultOperations - must not be null.
      path - the path inside Vault (e.g. secret/myapp/myproperties. Must not be empty or null.
      propertyTransformer - object to transform properties.
      See Also:
    • VaultPropertySource

      public VaultPropertySource(String name, VaultOperations vaultOperations, String path, PropertyTransformer propertyTransformer, boolean ignoreSecretNotFound)
      Create a new VaultPropertySource given a name, VaultTemplate and path inside of Vault. This property source loads properties upon construction and transforms these by applying PropertyTransformer.
      Parameters:
      name - name of the property source, must not be null.
      vaultOperations - must not be null.
      path - the path inside Vault (e.g. secret/myapp/myproperties. Must not be empty or null.
      propertyTransformer - object to transform properties.
      ignoreSecretNotFound - indicate if failure to find a secret at path should be ignored.
      Since:
      2.2
      See Also:
  • Method Details

    • loadProperties

      protected void loadProperties()
      Initialize property source and read properties from Vault.
    • getProperty

      public @Nullable Object getProperty(String name)
      Specified by:
      getProperty in class PropertySource<VaultOperations>
    • getPropertyNames

      public String[] getPropertyNames()
      Specified by:
      getPropertyNames in class EnumerablePropertySource<VaultOperations>
    • doGetProperties

      protected @Nullable Map<String,Object> doGetProperties(String path) throws VaultException
      Hook method to obtain properties from Vault.
      Parameters:
      path - the path, must not be empty or null.
      Returns:
      the resulting Map or null if properties were not found.
      Throws:
      VaultException - on problems retrieving properties
    • doTransformProperties

      protected Map<String,Object> doTransformProperties(Map<String,Object> properties)
      Hook method to transform properties using PropertyTransformer.
      Parameters:
      properties - must not be null.
      Returns:
      the transformed properties.
    • flattenMap

      protected Map<String,Object> flattenMap(Map<String,Object> data)
      Utility method converting a String/Object map to a flat String/Object map. Nested objects are represented with property path keys.
      Parameters:
      data - the map
      Returns:
      the flattened map.
      Since:
      2.0