spring-cloud / spring-cloud-vault

Configuration Integration with HashiCorp Vault
http://cloud.spring.io/spring-cloud-vault/
Apache License 2.0
274 stars 152 forks source link

Ability to supply custom reactive ClientHttpConnector #564

Closed schulzh closed 3 years ago

schulzh commented 3 years ago

I need to supply a custom ClientHttpConnector for connecting to vault because I need to use a custom KeyManager in the reactive client which cannot be configured using config properties.

Since 3.0.0 this is easy for the normal VaultAutoConfiguration, I can just create a bootstrap configuration class that supplies a bean of type AbstractVaultConfiguration.ClientFactoryWrapper with higher precedence, which will then be used in AbstractVaultConfiguration#vaultTemplate() to build the VaultTemplate. However, for the ReactiveVaultTemplate this is not straight forward, since the ClientHttpConnector is not exposed as a bean.

Am I missing a straight forward way of achieving this? I have a solution kind of working using reflections in a BeanPostProcessor, but that is very error prone. If not, I would also like to implement this. What would be the best way to approach this? Create a wrapper class like ClientFactoryWrapper for the ClientHttpConnector that is exposed as a bean?

mp911de commented 3 years ago

VaultReactiveAutoConfiguration doesn't expose ClientHttpConnector, instead it gets created in the createConnector(…) method which allows creation in the afterPropertiesSet() method. Until now, no one asked for further customizations so we didn't implement a wrapper around ClientHttpConnector. A connector is a pretty generic bean therefore exposing it as top-level type isn't a good idea since it might interfere with other components that want to use a reactive HTTP client.

That being said, feel free to submit a pull request to align VaultReactiveAutoConfiguration with VaultAutoConfiguration. Make sure to have also a look at VaultConfigDataLoader.ReactiveInfrastructure#registerClientHttpConnector as parts of the configuration are registered early on to work with Spring Boot's ConfigData API.

mp911de commented 3 years ago

Allowing a custom connector requires some additional API and a bit more changes therefore we can do this only in the 3.x line.