-
Notifications
You must be signed in to change notification settings - Fork 35
/
config.go
125 lines (115 loc) · 3.76 KB
/
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
package stellar
import (
"encoding/json"
"net"
"time"
"github.com/stellarproject/element"
)
// Config is the configuration used for the stellar server
// Note: in order to make user configuration from file a better user experience
// there is a custom marshal/unmarshal below. Those must be updated if fields are
// added or removed from `Config`.
type Config struct {
// NodeID is the id of the node
NodeID string
// NodeLabels are labels for the node
NodeLabels map[string]string
// GRPCAddress is the address for the grpc server
GRPCAddress string
// TLSCertificate is the certificate used for grpc communication
TLSServerCertificate string
// TLSKey is the key used for grpc communication
TLSServerKey string
// TLSClientCertificate is the client certificate used for communication
TLSClientCertificate string
// TLSClientKey is the client key used for communication
TLSClientKey string
// TLSInsecureSkipVerify disables certificate verification
TLSInsecureSkipVerify bool
// AgentConfig is the element config for the server
AgentConfig *element.Config `json:"-"`
// ContainerdAddr is the address to the containerd socket
ContainerdAddr string
// Namespace is the containerd namespace to manage
Namespace string
// Subnet is the subnet to use for stellar networking
Subnet *net.IPNet
// DataDir is the directory used to store stellar data
DataDir string
// State is the directory to store run state
StateDir string
// Bridge is the name of the bridge for networking
Bridge string
// UpstreamDNSAddr is the address to use for external queries
UpstreamDNSAddr string
// ProxyHTTPPort is the http port to use for the proxy service
ProxyHTTPPort int
// ProxyHTTPSPort is the https port to use for the proxy service
ProxyHTTPSPort int
// ProxyTLSEmail is the email address used when requesting letsencrypt certs
ProxyTLSEmail string
// ProxyHealthcheckInterval is the interval used by the proxy service to check upstreams
ProxyHealthcheckInterval time.Duration
// GatewayAddress is the http addr to use for the http/json API
GatewayAddress string
// EventsAddress is the address for the events service
EventsAddress string
// EventsClusterAddress is the address for the events cluster service
EventsClusterAddress string
// EventsHTTPAddress is the management address for the events service
EventsHTTPAddress string
// CNIBinPaths are paths to search for CNI plugin binaries
CNIBinPaths []string
}
// MarshalJSON is a custom json marshaller for better ux
func (c *Config) MarshalJSON() ([]byte, error) {
type Alias Config
type Agent element.Config
return json.Marshal(&struct {
*Alias
*Agent
Peers []string
Subnet string
ProxyHealthcheckInterval string
}{
Alias: (*Alias)(c),
Agent: (*Agent)(c.AgentConfig),
Peers: c.AgentConfig.Peers,
Subnet: c.Subnet.String(),
ProxyHealthcheckInterval: c.ProxyHealthcheckInterval.String(),
})
}
// UnmarshalJSON is a custom json unmarshaller for better ux
func (c *Config) UnmarshalJSON(data []byte) error {
type Alias Config
type Agent element.Config
tmp := &struct {
*Alias
*Agent
Subnet string
ProxyHealthcheckInterval string
}{
Alias: (*Alias)(c),
Agent: (*Agent)(c.AgentConfig),
}
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
c.AgentConfig = &element.Config{
ClusterAddress: tmp.ClusterAddress,
AdvertiseAddress: tmp.AdvertiseAddress,
ConnectionType: tmp.ConnectionType,
Peers: tmp.Peers,
}
_, subnet, err := net.ParseCIDR(tmp.Subnet)
if err != nil {
return err
}
c.Subnet = subnet
d, err := time.ParseDuration(tmp.ProxyHealthcheckInterval)
if err != nil {
return err
}
c.ProxyHealthcheckInterval = d
return nil
}