Class VaultPropertySource
java.lang.Object
org.springframework.core.env.PropertySource<T>
org.springframework.core.env.EnumerablePropertySource<VaultOperations>
org.springframework.vault.core.env.VaultPropertySource
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.core.env.PropertySource
PropertySource.StubPropertySource
-
Field Summary
Fields inherited from class org.springframework.core.env.PropertySource
name, source
-
Constructor Summary
ConstructorDescriptionVaultPropertySource
(String name, VaultOperations vaultOperations, String path) VaultPropertySource
(String name, VaultOperations vaultOperations, String path, PropertyTransformer propertyTransformer) VaultPropertySource
(String name, VaultOperations vaultOperations, String path, PropertyTransformer propertyTransformer, boolean ignoreSecretNotFound) VaultPropertySource
(VaultOperations vaultOperations, String path) -
Method Summary
Modifier and TypeMethodDescriptiondoGetProperties
(String path) Hook method to obtain properties from Vault.doTransformProperties
(Map<String, Object> properties) Hook method to transform properties usingPropertyTransformer
.flattenMap
(Map<String, Object> data) Utility method converting aString/Object
map to a flatString/Object
map.getProperty
(String name) String[]
protected void
Initialize property source and read properties from Vault.Methods inherited from class org.springframework.core.env.EnumerablePropertySource
containsProperty
-
Constructor Details
-
VaultPropertySource
Create a newVaultPropertySource
given aVaultTemplate
andpath
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
Create a newVaultPropertySource
given aname
,VaultTemplate
andpath
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 newVaultPropertySource
given aname
,VaultTemplate
andpath
inside of Vault. This property source loads properties upon construction and transforms these by applyingPropertyTransformer
.- 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 newVaultPropertySource
given aname
,VaultTemplate
andpath
inside of Vault. This property source loads properties upon construction and transforms these by applyingPropertyTransformer
.- 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 atpath
should be ignored.- Since:
- 2.2
- See Also:
-
-
Method Details
-
loadProperties
protected void loadProperties()Initialize property source and read properties from Vault. -
getProperty
- Specified by:
getProperty
in classPropertySource<VaultOperations>
-
getPropertyNames
- Specified by:
getPropertyNames
in classEnumerablePropertySource<VaultOperations>
-
doGetProperties
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
Hook method to transform properties usingPropertyTransformer
.- Parameters:
properties
- must not be null.- Returns:
- the transformed properties.
-
flattenMap
Utility method converting aString/Object
map to a flatString/Object
map. Nested objects are represented with property path keys.- Parameters:
data
- the map- Returns:
- the flattened map.
- Since:
- 2.0
-