-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add secret demo and doc (#525)
* add secret client * add secret client * add license * add secret demo of file\env\k8s * add secret doc * clean code * add start doc * fix * fix * delete demo * add quickstart test * add quickstart test Co-authored-by: seeflood <349895584@qq.com>
- Loading branch information
Showing
11 changed files
with
317 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"servers": [ | ||
{ | ||
"default_log_path": "stdout", | ||
"default_log_level": "DEBUG", | ||
"routers": [ | ||
{ | ||
"router_config_name": "actuator_dont_need_router" | ||
} | ||
], | ||
"listeners": [ | ||
{ | ||
"name": "grpc", | ||
"address": "127.0.0.1:34904", | ||
"bind_port": true, | ||
"filter_chains": [ | ||
{ | ||
"filters": [ | ||
{ | ||
"type": "grpc", | ||
"config": { | ||
"server_name": "runtime", | ||
"grpc_config": { | ||
"hellos": { | ||
"helloworld": { | ||
"hello": "greeting" | ||
} | ||
}, | ||
"secret_store": { | ||
"local.file": { | ||
"metadata": { | ||
"secretsFile": "../../configs/secret/config_secret_local_file.json" | ||
} | ||
}, | ||
"local.env": { | ||
"metadata": { | ||
} | ||
} | ||
}, | ||
"app": { | ||
"app_id": "app1", | ||
"grpc_callback_port": 9999 | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "actuator", | ||
"address": "127.0.0.1:34999", | ||
"bind_port": true, | ||
"filter_chains": [ | ||
{ | ||
"filters": [ | ||
{ | ||
"type": "proxy", | ||
"config": { | ||
"downstream_protocol": "Http1", | ||
"upstream_protocol": "Http1", | ||
"router_config_name": "actuator_dont_need_router" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"stream_filters": [ | ||
{ | ||
"type": "actuator_filter" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"db-user-pass": { | ||
"username": "devuser", | ||
"password": "S!S*d$zDsb=" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"mosn.io/layotto/sdk/go-sdk/client" | ||
|
||
runtimev1pb "mosn.io/layotto/spec/proto/runtime/v1" | ||
) | ||
|
||
var storeName string | ||
|
||
func init() { | ||
flag.StringVar(&storeName, "s", "", "set `storeName`") | ||
} | ||
|
||
func main() { | ||
|
||
flag.Parse() | ||
if storeName == "" { | ||
panic("storeName is empty.") | ||
} | ||
cli, err := client.NewClient() | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer cli.Close() | ||
ctx := context.Background() | ||
//2. get the secret | ||
resp, err := cli.GetSecret(ctx, &runtimev1pb.GetSecretRequest{ | ||
StoreName: storeName, | ||
Key: "db-user-pass:password", | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if resp == nil || len(resp.Data) == 0 { | ||
panic("no response data") | ||
} | ||
fmt.Println(resp) | ||
|
||
//3. get the bulk secret | ||
bulkSecrets, err := cli.GetBulkSecret(ctx, &runtimev1pb.GetBulkSecretRequest{ | ||
StoreName: storeName, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if bulkSecrets == nil || len(bulkSecrets.Data) == 0 { | ||
panic("no response data") | ||
} | ||
fmt.Println(bulkSecrets) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Secret Store component | ||
This component can access secrets from local files, environment variables, k8s, etc., Layotto use dapr's secret API, learn more: https://docs.dapr.io/operations/components/setup-secret-store/ | ||
**Configuration file structure** | ||
|
||
The json configuration file has the following structure: | ||
```json | ||
"secretStores": { | ||
"<STORE NAME>": { | ||
"metadata": { | ||
"<KEY>": "<VALUE>", | ||
"<KEY>": "<VALUE>" | ||
} | ||
} | ||
} | ||
``` | ||
Configuration examples of local file keys, local environment variables, and k8s keys: | ||
``` | ||
"secretStores": { | ||
"local.file": { | ||
"metadata": { | ||
"secretsFile": "../../configs/config_secret_local_file.json" | ||
} | ||
}, | ||
"local.env": { | ||
"metadata": { | ||
} | ||
}, | ||
"kubernetes": { | ||
"metadata": { | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# use Secret API to obtain secret | ||
## What is Secret API | ||
The secret API is used to obtain secret from file, env, k8s, etc | ||
|
||
Get all API and secret support | ||
## Quick start | ||
|
||
This example shows how to obtain the secret in file, env and k8s through the Layotto secret API | ||
|
||
|
||
|
||
### Step 1: Run Layotto | ||
|
||
After downloading the project code to the local, switch the code directory and compile: | ||
|
||
```shell | ||
cd ${project_path}/cmd/layotto | ||
``` | ||
|
||
build: | ||
```shell @if.not.exist layotto | ||
go build -o layotto | ||
``` | ||
|
||
Once finished, the layotto file will be generated in the directory, run it: | ||
|
||
```shell @background | ||
./layotto start -c ../../configs/config_secret_file.json | ||
``` | ||
|
||
### Step 2: Run the client program and call Layotto to generate a unique id | ||
|
||
```shell | ||
cd ${project_path}/demo/secret/common/ | ||
``` | ||
|
||
```shell @if.not.exist client | ||
go build -o client | ||
``` | ||
|
||
```shell | ||
./client -s "local.file" | ||
``` | ||
|
||
If the following information is printed, the demo is successful: | ||
|
||
```bash | ||
data:{key:"db-user-pass:password" value:"S!S*d$zDsb="} | ||
data:{key:"db-user-pass:password" value:{secrets:{key:"db-user-pass:password" value:"S!S*d$zDsb="}}} data:{key:"db-user-pass:username" value:{secrets:{key:"db-user-pass:username" value:"devuser"}}} | ||
``` | ||
|
||
|
||
## Want to learn more about Secret API? | ||
Layotto reuse Dapr Secret API,learn more:https://docs.dapr.io/operations/components/setup-secret-store/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# 秘钥组件 | ||
该组件可以从本地文件、环境变量、k8s等获取秘钥,复用了dapr的secret API,了解更多:https://docs.dapr.io/operations/components/setup-secret-store/ | ||
|
||
**配置文件结构** | ||
|
||
json配置文件有如下结构: | ||
```json | ||
"secretStores": { | ||
"<STORE NAME>": { | ||
"metadata": { | ||
"<KEY>": "<VALUE>", | ||
"<KEY>": "<VALUE>" | ||
} | ||
} | ||
} | ||
``` | ||
本地文件秘钥、本地环境变量、k8s秘钥的配置例子: | ||
``` | ||
"secretStores": { | ||
"local.file": { | ||
"metadata": { | ||
"secretsFile": "../../configs/config_secret_local_file.json" | ||
} | ||
}, | ||
"local.env": { | ||
"metadata": { | ||
} | ||
}, | ||
"kubernetes": { | ||
"metadata": { | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 使用Secret API获取secret | ||
## 什么是Secret API | ||
Secret API用于从file、env、k8s等获取secret | ||
|
||
Secret API支持获取单个和所有secret | ||
## 快速开始 | ||
|
||
该示例展示了如何通过Layotto Secret API 获取 file、env、k8s中的secret | ||
|
||
|
||
### 第一步:运行Layotto | ||
|
||
将项目代码下载到本地后,切换代码目录、编译: | ||
|
||
```shell | ||
cd ${project_path}/cmd/layotto | ||
``` | ||
构建: | ||
```shell @if.not.exist layotto | ||
go build -o layotto | ||
``` | ||
完成后目录下会生成layotto文件,运行它: | ||
|
||
```shell @background | ||
./layotto start -c ../../configs/config_secret_file.json | ||
``` | ||
|
||
### 第二步:运行客户端程序,调用Layotto生成唯一id | ||
|
||
```shell | ||
cd ${project_path}/demo/secret/common/ | ||
``` | ||
|
||
```shell @if.not.exist client | ||
go build -o client | ||
``` | ||
```shell | ||
./client -s "local.file" | ||
``` | ||
|
||
打印出如下信息则代表调用成功: | ||
|
||
```bash | ||
data:{key:"db-user-pass:password" value:"S!S*d$zDsb="} | ||
data:{key:"db-user-pass:password" value:{secrets:{key:"db-user-pass:password" value:"S!S*d$zDsb="}}} data:{key:"db-user-pass:username" value:{secrets:{key:"db-user-pass:username" value:"devuser"}}} | ||
``` | ||
|
||
|
||
## 想要详细了解Secret API? | ||
Layotto复用了Dapr的Secret API,了解更多:https://docs.dapr.io/operations/components/setup-secret-store/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters