/
config.go
60 lines (49 loc) · 1.46 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
package config
import (
"errors"
"os"
yaml "gopkg.in/yaml.v2"
)
type RoutingAPIConfig struct {
URI string `yaml:"uri"`
Port int `yaml:"port"`
AuthDisabled bool `yaml:"auth_disabled"`
ClientCertificatePath string `yaml:"client_cert_path"`
ClientPrivateKeyPath string `yaml:"client_private_key_path"`
CACertificatePath string `yaml:"ca_cert_path"`
}
type OAuthConfig struct {
TokenEndpoint string `yaml:"token_endpoint"`
Port int `yaml:"port"`
SkipSSLValidation bool `yaml:"skip_ssl_validation"`
ClientName string `yaml:"client_name"`
ClientSecret string `yaml:"client_secret"`
CACerts string `yaml:"ca_certs"`
}
type Config struct {
OAuth OAuthConfig `yaml:"oauth"`
RoutingAPI RoutingAPIConfig `yaml:"routing_api"`
HaProxyPidFile string `yaml:"haproxy_pid_file"`
IsolationSegments []string `yaml:"isolation_segments"`
ReservedSystemComponentPorts []int `yaml:"reserved_system_component_ports"`
}
func New(path string) (*Config, error) {
c := &Config{}
err := c.initConfigFromFile(path)
if err != nil {
return nil, err
}
return c, nil
}
func (c *Config) initConfigFromFile(path string) error {
var e error
b, e := os.ReadFile(path)
if e != nil {
return e
}
yaml.Unmarshal(b, &c)
if c.HaProxyPidFile == "" {
return errors.New("haproxy_pid_file is required")
}
return nil
}