|
此版本仍在开发中,目前尚不稳定。如需最新稳定版本,请使用 Spring Cloud Config 5.0.1! |
CredHub 后端
Spring Cloud Config Server 支持 CredHub 作为配置属性的后端。
您可以通过添加对 Spring CredHub 的依赖来启用此功能。
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.credhub</groupId>
<artifactId>spring-credhub-starter</artifactId>
</dependency>
</dependencies>
以下配置使用双向 TLS 访问 CredHub:
spring:
profiles:
active: credhub
cloud:
config:
server:
credhub:
url: https://credhub:8844
属性应以 JSON 格式存储,例如:
credhub set --name "/demo-app/default/master/toggles" --type=json
value: {"toggle.button": "blue", "toggle.link": "red"}
credhub set --name "/demo-app/default/master/abs" --type=json
value: {"marketing.enabled": true, "external.enabled": false}
所有名称为 spring.cloud.config.name=demo-app 的客户端应用程序都将拥有以下属性:
{
toggle.button: "blue",
toggle.link: "red",
marketing.enabled: true,
external.enabled: false
}
当未指定标签时,将使用默认值 master。您可以通过设置 spring.cloud.config.server.credhub.defaultLabel 来更改此值。 |
当未指定配置文件时,将使用 default。 |
添加到 application 的值将被所有应用程序共享。 |
OAuth 2.0
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
</dependencies>
以下配置使用 OAuth 2.0 和 UAA 访问 CredHub:
spring:
profiles:
active: credhub
cloud:
config:
server:
credhub:
url: https://credhub:8844
oauth2:
registration-id: credhub-client
security:
oauth2:
client:
registration:
credhub-client:
provider: uaa
client-id: credhub_config_server
client-secret: asecret
authorization-grant-type: client_credentials
provider:
uaa:
token-uri: https://uaa:8443/oauth/token
所使用的 UAA 客户端 ID 应具有 credhub.read 作为作用域。 |
以下表格描述了 CredHub 的配置属性。
| 属性名称 | 备注 |
|---|---|
url |
CredHub 服务器 URL。 |
路径 |
所有凭证的基准路径。可选,默认为空。 |
defaultLabel |
默认标签,当客户端应用程序未提供时使用。可选,默认为 |
OAuth2 |
OAuth2 配置,用于访问 CredHub。可选。 |