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。 |
path |
所有憑據的基本路徑。可選,預設為空。 |
defaultLabel |
當客戶端應用程式未提供標籤時使用的預設標籤。可選,預設為 |
oauth2 |
用於訪問 CredHub 的 OAuth2 配置。可選。 |