Ste*_*ins 7 java spring spring-cloud spring-cloud-config
我一直在修改 Spring Cloud Config,但有一个用例,其中配置属性分为两种类型:
非秘密值,开发人员应该能够查看和维护(例如 JDBC URL 等)
秘密值,只能由具有特殊访问权限(例如密码)的指定人员查看和维护
所以我对“复合环境存储库”的支持非常感兴趣,目前在快照版本中可用。似乎我可以将 Git 用于开发人员管理的属性,将 Vault 用于机密属性,并对其进行配置,以便在发生冲突时 Vault 始终优先于 Git。
但是,我发现 Vault 不仅总是优先……它被用作唯一的后端。根本不返回来自 Git 的任何属性。
我的application.yml看起来像这样:
spring:
profiles:
active: git, vault
cloud:
config:
server:
vault:
order: 1
git:
uri: https://github.com/spring-cloud-samples/config-repo
basedir: target/config
order: 2
Run Code Online (Sandbox Code Playgroud)
我已经像这样向 Vault 写了一个属性:
vault write secret/foo foo=vault
Run Code Online (Sandbox Code Playgroud)
我像这样调用我的配置服务器:
curl -X "GET" "http://127.0.0.1:8888/foo/default" -H "X-Config-Token: a9384085-f048-7c99-ebd7-e607840bc24e"
Run Code Online (Sandbox Code Playgroud)
但是,JSON 响应负载仅包含 Vault 属性。没有来自 Git:
{
"name": "foo",
"profiles": [
"default"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "vault:foo",
"source": {
"foo": "vault"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
如果我颠倒 中的order设置application.yml,给 Git 比 Vault 更高的优先级,这并不重要。只要 Vault 配置文件处于活动状态,它就会充当专有后端。
但是,如果我停用保管库配置文件,则相同的 curl 操作确实会从 Git 后端返回结果:
{
"name": "foo",
"profiles": [
"default"
],
"label": "master",
"version": "30f5f4a144dba41e23575ebe46369222b7cbc90d",
"state": null,
"propertySources": [
{
"name": "https://github.com/spring-cloud-samples/config-repo/foo.properties",
"source": {
"democonfigclient.message": "hello spring io",
"foo": "from foo props"
}
},
{
"name": "https://github.com/spring-cloud-samples/config-repo/application.yml",
"source": {
"info.description": "Spring Cloud Samples",
"info.url": "https://github.com/spring-cloud-samples",
"eureka.client.serviceUrl.defaultZone": "http://localhost:8761/eureka/",
"foo": "from-default"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
有什么我可能会错过的吗?为什么 Git 属性和 Vault 属性没有……好吧,“复合”在一起?
文档中的唯一示例显示 Git 和 Subversion 一起使用,并且有一条注释警告您所有存储库都应包含相同的标签(例如master)。我想知道这是否是问题所在,因为标签总是null用于 Vault。
小智 6
我相信您的依赖项一定有问题。我还设置了一个带有 git 和 vault 的 spring 云配置服务器,它工作得很好。我认为强制使用 1.3.0-BUILD.SNAPSHOT 是不够的。Spring cloud config 1.3.0-BUILD.SNAPSHOT 依赖于 spring-vault-core。您可能缺少此依赖项。这可能会导致您在评论之一中提到的 bean 创建失败。这是带有 git 和 vault 的示例项目的链接。随意检查一下。
| 归档时间: |
|
| 查看次数: |
4268 次 |
| 最近记录: |