forked from cisco-app-networking/nsm-nse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
65 lines (49 loc) · 1.33 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
package nseconfig
import (
"strings"
)
type config interface {
validate() error
}
type Config struct {
Endpoints []*Endpoint
}
type Endpoint struct {
Name string `yaml:"name"`
Labels Labels `yaml:"labels"`
NseName string `yaml:"nseName"` //TODO temporary in order to be able to run examples
NseControl *NseControl `yaml:"nseControl"`
VL3 VL3 `yaml:"vl3"`
}
type NseControl struct {
Name string `yaml:"name"`
Address string `yaml:"address"`
AccessToken string `yaml:"accessToken"`
ConnectivityDomain string `yaml:"connectivityDomain"`
}
type VL3 struct {
IPAM IPAM `yaml:"ipam"`
Ifname string `yaml:"ifName"`
NameServers []string `yaml:"nameServers"`
DNSZones []string `yaml:"dnsZones"`
}
type IPAM struct {
DefaultPrefixPool string `yaml:"defaultPrefixPool"`
PrefixLength int `yaml:"prefixLength"`
Routes []string `yaml:"routes"`
ServerAddress string `yaml:"serverAddress"`
}
type decoder interface {
Decode(v interface{}) error
}
type DecoderFn func(v interface{}) error
func (d DecoderFn) Decode(v interface{}) error { return d(v) }
func NewConfig(decoder decoder, cfg config) error {
if err := decoder.Decode(cfg); err != nil {
return err
}
return cfg.validate()
}
func empty(s string) bool {
return len(strings.Trim(s, " ")) == 0
}