spring-vault icon indicating copy to clipboard operation
spring-vault copied to clipboard

Allow specifying custom `PropertyTransformer(s)` in `@VaultPropertySource` annotation

Open LeMakhno opened this issue 1 month ago • 1 comments

Currently VaultPropertySourceRegistrar, when registering vault property sources, adds property transformer depending on @VaultPropertySource propertyNamePrefix attribute, either transformer that appends prefix, or noop, if no propertyNamePrefix specified.

Please allow specifying more custom transformers as attribute in @VaultPropertySource, e. g. as array of classes, that implement PropertyTransformer interface. PropertyTransformer allows chaining, so additional transformers could be added on top of default one (prefix transformer or noop).

Why? There is a necessity to remap property names, returned by vault from dynamic auth backends, directly to spring Environment, with names, as various autoconfigurations expect them, to avoid explicit bean redefinitions. For example, postgres dynamic credential provider returns secret {"username": "u", "pwd": "p", "url": "postgres:jdbc://"}, what i can do now is only append prefix to those properties, but it would be very convenient to map these properties to spring.data.datasource.user, spring.data.datasource.password and so on, so that spring could build DataSource automatically, without defining DataSource bean explicitly.

And resulting @VaultPropertySource would look like @VaultPropertySource( value = "db/postgres", renewal = VaultPropertySource.Renewal.RENEW, ignoreSecretNotFound = false, propertyTransformers = { MyPropertyTransformer.class } )

LeMakhno avatar Nov 24 '25 14:11 LeMakhno

Upd: pull request https://github.com/spring-projects/spring-vault/pull/958

LeMakhno avatar Nov 24 '25 16:11 LeMakhno