File tree 17 files changed +550
-8
lines changed
17 files changed +550
-8
lines changed Original file line number Diff line number Diff line change 13
13
// limitations under the License.
14
14
package custom
15
15
16
+ import "mosn.io/layotto/components/ref"
17
+
16
18
type Config struct {
19
+ ref.Config
17
20
Type string `json:"type"`
18
21
Version string `json:"version"`
19
22
Metadata map [string ]string `json:"metadata"`
Original file line number Diff line number Diff line change 13
13
// limitations under the License.
14
14
package lock
15
15
16
+ import "mosn.io/layotto/components/ref"
17
+
16
18
type Feature string
17
19
18
20
// Lock's metadata
19
21
type Config struct {
22
+ ref.Config
20
23
Type string `json:"type"`
21
24
Metadata map [string ]string `json:"metadata"`
22
25
}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2021 Layotto Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package ref
18
+
19
+ //Config is ref json config
20
+ type Config struct {
21
+ SecretRef []* Item `json:"secret_ref"`
22
+ }
23
+
24
+ type Item struct {
25
+ Name string `json:"name"`
26
+ Key string `json:"key"`
27
+ }
Original file line number Diff line number Diff line change 11
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
+
14
15
package sequencer
15
16
17
+ import "mosn.io/layotto/components/ref"
18
+
16
19
type Config struct {
20
+ ref.Config
17
21
Type string `json:"type"`
18
22
BiggerThan map [string ]int64 `json:"biggerThan"`
19
23
Metadata map [string ]string `json:"metadata"`
Original file line number Diff line number Diff line change
1
+ {
2
+ "servers" : [
3
+ {
4
+ "default_log_path" : " stdout" ,
5
+ "default_log_level" : " DEBUG" ,
6
+ "routers" : [
7
+ {
8
+ "router_config_name" : " actuator_dont_need_router"
9
+ }
10
+ ],
11
+ "listeners" : [
12
+ {
13
+ "name" : " grpc" ,
14
+ "address" : " 127.0.0.1:34904" ,
15
+ "bind_port" : true ,
16
+ "filter_chains" : [
17
+ {
18
+ "filters" : [
19
+ {
20
+ "type" : " grpc" ,
21
+ "config" : {
22
+ "server_name" : " runtime" ,
23
+ "grpc_config" : {
24
+ "hellos" : {
25
+ "helloworld" : {
26
+ "type" : " helloworld" ,
27
+ "hello" : " greeting"
28
+ }
29
+ },
30
+ "secret_store" : {
31
+ "local.file" : {
32
+ "type" :" local.file" ,
33
+ "metadata" : {
34
+ "secretsFile" : " ../../configs/secret/config_secret_local_file.json"
35
+ }
36
+ },
37
+ "local.env" : {
38
+ "type" :" local.env" ,
39
+ "metadata" : {
40
+ }
41
+ }
42
+ },
43
+ "sequencer" : {
44
+ "redis" : {
45
+ "type" :" redis" ,
46
+ "metadata" : {
47
+ "redisHost" : " 127.0.0.1:6380" ,
48
+ "redisPassword" : " "
49
+ },
50
+ "secret_ref" : [
51
+ {
52
+ "name" : " local.file" ,
53
+ "key" : " redisPassword"
54
+ }
55
+ ]
56
+ }
57
+ },
58
+ "app" : {
59
+ "app_id" : " app1" ,
60
+ "grpc_callback_port" : 9999
61
+ }
62
+ }
63
+ }
64
+ }
65
+ ]
66
+ }
67
+ ]
68
+ },
69
+ {
70
+ "name" : " actuator" ,
71
+ "address" : " 127.0.0.1:34999" ,
72
+ "bind_port" : true ,
73
+ "filter_chains" : [
74
+ {
75
+ "filters" : [
76
+ {
77
+ "type" : " proxy" ,
78
+ "config" : {
79
+ "downstream_protocol" : " Http1" ,
80
+ "upstream_protocol" : " Http1" ,
81
+ "router_config_name" : " actuator_dont_need_router"
82
+ }
83
+ }
84
+ ]
85
+ }
86
+ ],
87
+ "stream_filters" : [
88
+ {
89
+ "type" : " actuator_filter"
90
+ }
91
+ ]
92
+ }
93
+ ]
94
+ }
95
+ ]
96
+ }
Original file line number Diff line number Diff line change 2
2
"db-user-pass" : {
3
3
"username" : " devuser" ,
4
4
"password" : " S!S*d$zDsb="
5
- }
5
+ },
6
+ "redisPassword" : " redis123"
6
7
}
Original file line number Diff line number Diff line change
1
+ # use Secret Ref to obtain secret
2
+
3
+ we can inject secrets to other components using secret store.
4
+
5
+ using ` secret_ref ` config:
6
+
7
+ ``` json
8
+ {
9
+ "sequencer" : {
10
+ "redis" : {
11
+ "type" : " redis" ,
12
+ "metadata" : {
13
+ "redisHost" : " 127.0.0.1:6380" ,
14
+ "redisPassword" : " "
15
+ },
16
+ "secret_ref" : [
17
+ {
18
+ "name" : " local.file" ,
19
+ "key" : " redisPassword"
20
+ }
21
+ ]
22
+ }
23
+ }
24
+ }
25
+ ```
26
+
27
+ ## Quick start
28
+
29
+ This example shows how to inject redis password to sequencer component using redis store
30
+
31
+ ### Step 0: Run Redis with password
32
+
33
+ ``` shell
34
+ docker run --name redis -p 6380:6379 -d --restart=always redis:5.0.3 redis-server --appendonly yes --requirepass " redis123"
35
+ ```
36
+
37
+ ### Step 1: Run Layotto
38
+
39
+ After downloading the project code to the local, switch the code directory and compile:
40
+
41
+ ``` shell
42
+ cd ${project_path} /cmd/layotto
43
+ ```
44
+
45
+ build:
46
+
47
+ ``` shell @if.not.exist layotto
48
+ go build -o layotto
49
+ ```
50
+
51
+ Once finished, the layotto file will be generated in the directory, run it:
52
+
53
+ ``` shell @background
54
+ ./layotto start -c ../../configs/config_ref_example.json
55
+ ```
56
+
57
+ ### Step 2: Run the client program and call Layotto to get the sequence
58
+
59
+ ``` shell
60
+ cd ${project_path} /demo/sequencer/common/
61
+ ```
62
+
63
+ ``` shell @if.not.exist client
64
+ go build -o client
65
+ ```
66
+
67
+ ``` shell
68
+ ./client -s " redis"
69
+ ```
70
+
71
+ If the following information is printed, the demo is successful:
72
+
73
+ ``` bash
74
+ Try to get next id.Key:key666
75
+ Next id:next_id:1
76
+ Next id:next_id:2
77
+ Next id:next_id:3
78
+ Next id:next_id:4
79
+ Next id:next_id:5
80
+ Next id:next_id:6
81
+ Next id:next_id:7
82
+ Next id:next_id:8
83
+ Next id:next_id:9
84
+ Next id:next_id:10
85
+ Demo success!
86
+
87
+ ```
Original file line number Diff line number Diff line change
1
+ # 使用 Secret Ref 注入secret
2
+
3
+ 我们可以用secret store将secrets注入到其他组件。
4
+
5
+ 用 ` secret_ref ` 来配置:
6
+
7
+ ``` json
8
+ {
9
+ "sequencer" : {
10
+ "redis" : {
11
+ "type" : " redis" ,
12
+ "metadata" : {
13
+ "redisHost" : " 127.0.0.1:6380" ,
14
+ "redisPassword" : " "
15
+ },
16
+ "secret_ref" : [
17
+ {
18
+ "name" : " local.file" ,
19
+ "key" : " redisPassword"
20
+ }
21
+ ]
22
+ }
23
+ }
24
+ }
25
+ ```
26
+
27
+ ## 快速开始
28
+
29
+ 该示例展示了如何注入redis password到sequencer组件
30
+
31
+
32
+ ### Step 0: 运行redis并初试密码
33
+
34
+ ``` shell
35
+ docker run --name redis -p 6380:6379 -d --restart=always redis:5.0.3 redis-server --appendonly yes --requirepass " redis123"
36
+ ```
37
+
38
+ ### Step 1: 运行 Layotto
39
+
40
+ 将项目代码下载到本地后,切换代码目录、编译:
41
+
42
+ ``` shell
43
+ cd ${project_path} /cmd/layotto
44
+ ```
45
+
46
+ build:
47
+
48
+ ``` shell @if.not.exist layotto
49
+ go build -o layotto
50
+ ```
51
+
52
+ 完成后目录下会生成layotto文件,运行它:
53
+
54
+ ``` shell @background
55
+ ./layotto start -c ../../configs/config_ref_example.json
56
+ ```
57
+
58
+ ### 第二步:运行客户端程序,调用 Layotto 获取sequence
59
+
60
+ ``` shell
61
+ cd ${project_path} /demo/sequencer/common/
62
+ ```
63
+
64
+ ``` shell @if.not.exist client
65
+ go build -o client
66
+ ```
67
+
68
+ ``` shell
69
+ ./client -s " redis"
70
+ ```
71
+
72
+ 打印出如下信息则代表调用成功:
73
+
74
+ ``` bash
75
+ Try to get next id.Key:key666
76
+ Next id:next_id:1
77
+ Next id:next_id:2
78
+ Next id:next_id:3
79
+ Next id:next_id:4
80
+ Next id:next_id:5
81
+ Next id:next_id:6
82
+ Next id:next_id:7
83
+ Next id:next_id:8
84
+ Next id:next_id:9
85
+ Next id:next_id:10
86
+ Demo success!
87
+
88
+ ```
Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ quickstarts_in_default="docs/en/start/configuration/start.md
39
39
docs/zh/start/wasm/start.md
40
40
docs/en/start/secret/start.md
41
41
docs/zh/start/secret/start.md
42
+ docs/en/start/secret/secret_ref.md
43
+ docs/zh/start/secret/secret_ref.md
42
44
"
43
45
44
46
# In advance mod, we test these docs with golang 1.17
Original file line number Diff line number Diff line change 16
16
17
17
package bindings
18
18
19
+ import "mosn.io/layotto/components/ref"
20
+
19
21
type Metadata struct {
22
+ ref.Config
20
23
Type string `json:"type"`
21
24
Version string
22
25
Metadata map [string ]string `json:"metadata"`
Original file line number Diff line number Diff line change 16
16
17
17
package pubsub
18
18
19
+ import "mosn.io/layotto/components/ref"
20
+
19
21
// Config wraps configuration for a pubsub implementation
20
22
type Config struct {
23
+ ref.Config
21
24
Type string `json:"type"`
22
25
Metadata map [string ]string `json:"metadata"`
23
26
}
You can’t perform that action at this time.
0 commit comments