-
Notifications
You must be signed in to change notification settings - Fork 19
/
run_config.go
193 lines (171 loc) · 4.65 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
187
188
189
190
191
192
193
// Copyright (C) 2023 Gobalsky Labs Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package config
import (
"fmt"
"code.vegaprotocol.io/vega/paths"
)
/*
description: Configuration options for the Vega binary and its arguments.
example:
type: toml
value: |
path = "/path/binary"
args = ["--arg1", "val1", "--arg2"]
*/
type BinaryConfig struct {
/*
description: Path to the Vega 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: Configures a connection to a core node's exposed UNIX socket RPC API.
example:
type: toml
value: |
[vega.rpc]
socketPath = "/path/socket.sock"
httpPath = "/rpc"
*/
type RPCConfig struct {
/*
description: Path of the mounted socket.
note: This path can be configured in the Vega core node configuration and can be found in the [Admin.Server] section.
*/
SocketPath string `toml:"socketPath"`
/*
description: HTTP path of the socket path.
note: This path can be configured in the Vega core node configuration and can be found in the [Admin.Server] section.
*/
HTTPPath string `toml:"httpPath"`
}
/*
description: Configuration options for the Vega binary and its arguments.
example:
type: toml
value: |
[vega]
[vega.binary]
path = "/path/vega-binary"
args = ["--arg1", "val1", "--arg2"]
[vega.rpc]
socketPath = "/path/socket.sock"
httpPath = "/rpc"
*/
type VegaConfig struct {
/*
description: Configuration of Vega binary and the arguments to run it.
example:
type: toml
value: |
[vega.binary]
path = "/path/vega-binary"
args = ["--arg1", "val1", "--arg2"]
*/
Binary BinaryConfig `toml:"binary"`
/*
description: |
Visor communicates with the core node via RPC API that runs over a UNIX socket.
This parameter configures the UNIX socket to match the core node configuration.
This value can be found in the config.toml file used by the core node under the heading [Admin.Server]
example:
type: toml
value: |
[vega.binary]
path = "/path/vega-binary"
args = ["--arg1", "val1", "--arg2"]
*/
RCP RPCConfig `toml:"rpc"`
}
/*
description: Configures 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"
[vega]
[vega.binary]
path = "/path/vega-binary"
args = ["--arg1", "val1", "--arg2"]
[vega.rpc]
socketPath = "/path/socket.sock"
httpPath = "/rpc"
*/
type RunConfig struct {
/*
description: Name of the upgrade.
note: |
It is recommended to use the Vega version you wish to upgrade to as the name. These can be found in the releases list of the Vega Github repository
(https://github.com/vegaprotocol/vega/releases).
*/
Name string `toml:"name"`
// description: Configuration of a Vega node.
Vega VegaConfig `toml:"vega"`
// description: Configuration of a data node.
DataNode *DataNodeConfig `toml:"data_node"`
}
func ExampleRunConfig(name string, withDataNode bool) *RunConfig {
c := &RunConfig{
Name: name,
Vega: VegaConfig{
Binary: BinaryConfig{
Path: "vega",
Args: []string{"arg1", "arg2", "..."},
},
},
}
if withDataNode {
c.DataNode = &DataNodeConfig{
Binary: BinaryConfig{
Path: "vega 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)
}