The documentation you are viewing is for Dapr v1.4 which is an older version of Dapr. For up-to-date documentation, see the latest version.
本地文件 (用于开发)
这个Dapr密钥仓库组件不使用身份认证,而是读取JSON文本。
Warning
这种密钥管理的方法不建议用于生产环境。配置
要设置基于本地文件密钥仓库,请创建一个类型为secretstores.local.file
的组件。 在你的./components
目录下创建一个包含以下内容的文件:
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: local-secret-store
namespace: default
spec:
type: secretstores.local.file
version: v1
metadata:
- name: secretsFile
value: [path to the JSON file]
- name: nestedSeparator
value: ":"
- name: multiValued
value: "false"
元数据字段规范
字段 | 必填 | 详情 | 示例 |
---|---|---|---|
secretsFile | Y | 存储密钥的文件路径 | "path/to/file.json" |
nestedSeparator | N | 在将JSON层次结构扁平化为map时,被仓库使用 默认值为 ":" 默认值为 ":" |
":" |
multiValued | N | Allows one level of multi-valued key/value pairs before flattening JSON hierarchy. 默认值为 "false" |
"true" |
设置 JSON 文件来保存密钥
Given the following JSON loaded from secretsFile
:
{
"redisPassword": "your redis password",
"connectionStrings": {
"sql": "your sql connection string",
"mysql": "your mysql connection string"
}
}
If multiValued
is "false"
, the store will load the file and create a map with the following key value pairs:
扁平键 | 值 |
---|---|
“redis” | “your redis password” |
“connectionStrings:sql” | “your sql connection string” |
“connectionStrings:mysql” | “your mysql connection string” |
使用扁平键 (connectionStrings:sql
)来访问密钥。 The following JSON map returned:
{
"connectionStrings:sql": "your sql connection string"
}
If multiValued
is "true"
, you would instead use the top level key. In this example, connectionStrings
would return the following map:
{
"sql": "your sql connection string",
"mysql": "your mysql connection string"
}
Nested structures after the top level will be flattened. In this example, connectionStrings
would return the following map:
JSON from secretsFile
:
{
"redisPassword": "your redis password",
"connectionStrings": {
"mysql": {
"username": "your mysql username",
"password": "your mysql password"
}
}
}
响应:
{
"mysql:username": "your mysql username",
"mysql:password": "your mysql password"
}
This is useful in order to mimic secret stores like Vault or Kubernetes that return multiple key/value pairs per secret key.
相关链接
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.