This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
configyaml.go
148 lines (128 loc) · 3.6 KB
/
configyaml.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
package main
import (
"io/ioutil"
"os"
log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
)
var (
qubeTemplateYaml = `
genesis:
# supported: (raft | istanbul | qbft)
consensus: istanbul
Test_QBFT_Block: 0
Quorum_Version: 21.7.1
Tm_Version: 21.7.2
Chain_Id: 1000
nodes:
`
)
type QuorumEntry struct {
Quorum Quorum
Tm Tm
}
type GethEntry struct {
GetStartupParams string `yaml:"Geth_Startup_Params"` //--raftjoinexisting 7
}
type Quorum struct {
Consensus string `yaml:"consensus"`
QuorumVersion string `yaml:"Quorum_Version"`
DockerRepoFull string `yaml:"Docker_Repo_Full,omitempty"` //quorum-local
}
type Tm struct {
Name string `yaml:"Name"`
TmVersion string `yaml:"Tm_Version"`
DockerRepoFull string `yaml:"Docker_Repo_Full,omitempty"` //tessera-local
}
type NodeEntry struct {
NodeUserIdent string `yaml:"Node_UserIdent"`
KeyDir string `yaml:"Key_Dir"`
QuorumEntry QuorumEntry `yaml:"quorum"`
GethEntry GethEntry `yaml:"geth"`
}
type ExternalNodeEntry struct {
NodeUserIdent string `yaml:"Node_UserIdent"`
EnodeUrl string `yaml:"Enode_Url"`
TmUrl string `yaml:"Tm_Url"`
// must be set in the yaml without quotes.
// The hex number will be evaluted to a BigNum and
// template/istanbul-validator.toml.erb will convert back to hex
// https://github.com/mikefarah/yq/issues/19
NodekeyAddress string `yaml:"Node_Acct_Addr,omitempty"`
}
type Prometheus struct {
//#monitor_params_geth: --metrics --metrics.expensive --pprof --pprofaddr=0.0.0.0
//monitorParamsGeth string `yaml:"monitor_params_geth"`
NodePort string `yaml:"nodePort_prom,omitempty"`
Enabled bool `yaml:"enabled,omitempty"`
}
type Cakeshop struct {
Version string `yaml:"version,omitempty"`
Service struct {
Type string `yaml:"type,omitempty"`
NodePort string `yaml:"nodePort,omitempty"`
}
}
type Ingress struct {
//OneToMany | OneToOne
Strategy string `yaml:"Strategy,omitempty"`
Host string `yaml:"Host,omitempty"`
}
type K8s struct {
Service struct {
Type string `yaml:"type,omitempty"`
Ingress Ingress `yaml:"Ingress,omitempty"`
}
}
type QConfig struct {
Genesis struct {
Consensus string `yaml:"consensus"`
TestQBFTBlock string `yaml:"Test_QBFT_Block,omitempty"`
QuorumVersion string `yaml:"Quorum_Version"`
TmVersion string `yaml:"Tm_Version"`
Chain_Id string `yaml:"Chain_Id"`
}
Prometheus Prometheus `yaml:"prometheus,omitempty"`
Cakeshop Cakeshop `yaml:"cakeshop,omitempty"`
K8s K8s `yaml:"k8s,omitempty"`
Nodes []NodeEntry
ExternalNodes []ExternalNodeEntry `yaml:"external_nodes,omitempty"`
}
func GetYamlConfig() QConfig {
config := QConfig{}
err := yaml.Unmarshal([]byte(qubeTemplateYaml), &config)
if err != nil {
log.Fatalf("error: %v", err)
}
return config
}
func LoadYamlConfig(filename string) (QConfig, error) {
config := QConfig{}
fileBytes, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatalf("error reading file: %v err: %v", filename, err)
return config, err
}
err = yaml.Unmarshal(fileBytes, &config)
if err != nil {
log.Fatalf("error unmarshalling file: %v err: %v", filename, err)
return config, err
}
return config, nil
}
func WriteYamlConfig(qconfig QConfig, filename string) (QConfig, error) {
bs, err := yaml.Marshal(&qconfig)
if err != nil {
log.Fatalf("error: %v", err)
return qconfig, err
}
err = ioutil.WriteFile(filename, bs, os.ModePerm)
return qconfig, err
}
func (q QConfig) ToString() string {
d, err := yaml.Marshal(&q)
if err != nil {
log.Fatalf("error: %v", err)
}
return string(d)
}