9. 自定义要作为 PropertySource 公开的 secret 后端

Spring Cloud Vault 使用基于属性的配置来创建PropertySources 用于键值和发现的 secret 后端。spring-doc.cadn.net.cn

发现的后端提供VaultSecretBackendDescriptorbean 来描述使用 secret backend 的配置状态PropertySource. 一个SecretBackendMetadataFactory需要创建SecretBackendMetadataobject,其中包含 path、name 和 property 转换配置。spring-doc.cadn.net.cn

SecretBackendMetadata用于支持特定的PropertySource.spring-doc.cadn.net.cn

您可以注册一个VaultConfigurer进行定制。 如果您提供VaultConfigurer. 但是,您可以使用SecretBackendConfigurer.registerDefaultKeyValueSecretBackends()SecretBackendConfigurer.registerDefaultDiscoveredSecretBackends().spring-doc.cadn.net.cn

public class CustomizationBean implements VaultConfigurer {

    @Override
    public void addSecretBackends(SecretBackendConfigurer configurer) {

        configurer.add("secret/my-application");

        configurer.registerDefaultKeyValueSecretBackends(false);
        configurer.registerDefaultDiscoveredSecretBackends(true);
    }
}
SpringApplication application = new SpringApplication(MyApplication.class);
application.addBootstrapper(VaultBootstrapper.fromConfigurer(new CustomizationBean()));