-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_config.go
186 lines (165 loc) · 4.12 KB
/
run_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Copyright (c) 2022 Gobalsky Labs Limited
//
// Use of this software is governed by the Business Source License included
// in the LICENSE file and at https://www.mariadb.com/bsl11.
//
// Change Date: 18 months from the later of the date of the first publicly
// available Distribution of this version of the repository, and 25 June 2022.
//
// On the date above, in accordance with the Business Source License, use
// of this software will be governed by version 3 or later of the GNU General
// Public License.
package config
import (
"fmt"
"github.com/zeta-protocol/zeta/paths"
)
/*
description: Allows you to configure a binary and its arguments.
example:
type: toml
value: |
path = "/path/binary"
args = ["--arg1", "val1", "--arg2"]
*/
type BinaryConfig struct {
/*
description: Path to the binary.
note: |
The absolute or relative path can be used.
Relative path is relative to a parent folder of this config file.
*/
Path string `toml:"path"`
/*
description: Arguments that will be applied to the binary.
note: |
Each element the list represents one space separated argument.
*/
Args []string `toml:"args"`
}
/*
description: Allows you to configure a connection to a core node's exposed UNIX socket RPC API.
example:
type: toml
value: |
[zeta.rpc]
socketPath = "/path/socket.sock"
httpPath = "/rpc"
*/
type RPCConfig struct {
/*
description: Path of the mounted socket.
note: This path can be configured in Zeta core node configuration.
*/
SocketPath string `toml:"socketPath"`
/*
description: HTTP path of the socket path.
note: This path can be configured in Zeta core node configuration.
*/
HTTPPath string `toml:"httpPath"`
}
/*
description: Allows you to configure the Zeta binary and its arguments.
example:
type: toml
value: |
[zeta]
[zeta.binary]
path = "/path/zeta-binary"
args = ["--arg1", "val1", "--arg2"]
[zeta.rpc]
socketPath = "/path/socket.sock"
httpPath = "/rpc"
*/
type ZetaConfig struct {
/*
description: Configuration of Zeta binary to be run.
example:
type: toml
value: |
[zeta.binary]
path = "/path/zeta-binary"
args = ["--arg1", "val1", "--arg2"]
*/
Binary BinaryConfig `toml:"binary"`
/*
description: |
Visor communicates with the core node via RPC API that runs over UNIX socket.
This parameter allows you to configure the UNIX socket to match the core node configuration.
example:
type: toml
value: |
[zeta.binary]
path = "/path/zeta-binary"
args = ["--arg1", "val1", "--arg2"]
*/
RCP RPCConfig `toml:"rpc"`
}
/*
description: Allows you to configure a data node binary and its arguments.
example:
type: toml
value: |
[data_node]
[data_node.binary]
path = "/path/data-node-binary"
args = ["--arg1", "val1", "--arg2"]
*/
type DataNodeConfig struct {
Binary BinaryConfig `toml:"binary"`
}
/*
description: Root of the config file
example:
type: toml
value: |
name = "v1.65.0"
[zeta]
[zeta.binary]
path = "/path/zeta-binary"
args = ["--arg1", "val1", "--arg2"]
[zeta.rpc]
socketPath = "/path/socket.sock"
httpPath = "/rpc"
*/
type RunConfig struct {
/*
description: Name of the upgrade.
note: It is recommended that you use the upgrade version as the name.
*/
Name string `toml:"name"`
// description: Configuration of a Zeta node.
Zeta ZetaConfig `toml:"zeta"`
// description: Configuration of a data node.
DataNode *DataNodeConfig `toml:"data_node"`
}
func ExampleRunConfig(name string, withDataNode bool) *RunConfig {
c := &RunConfig{
Name: name,
Zeta: ZetaConfig{
Binary: BinaryConfig{
Path: "zeta",
Args: []string{"arg1", "arg2", "..."},
},
},
}
if withDataNode {
c.DataNode = &DataNodeConfig{
Binary: BinaryConfig{
Path: "zeta data-node",
Args: []string{"arg1", "arg2", "..."},
},
}
}
return c
}
func ParseRunConfig(path string) (*RunConfig, error) {
conf := RunConfig{}
if err := paths.ReadStructuredFile(path, &conf); err != nil {
return nil, fmt.Errorf("failed to parse RunConfig: %w", err)
}
return &conf, nil
}
func (rc *RunConfig) WriteToFile(path string) error {
return paths.WriteStructuredFile(path, rc)
}