forked from aerospike/aerospike-management-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asconfig.go
98 lines (80 loc) · 2.18 KB
/
asconfig.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
package asconfig
import (
"bufio"
"io"
"github.com/go-logr/logr"
)
// AsConfig is wrapper over Conf
type AsConfig struct {
baseConf *Conf
log logr.Logger
}
func New(log logr.Logger, bconf *Conf) *AsConfig {
return &AsConfig{
baseConf: bconf,
log: log,
}
}
// ValidationErr represents version validation error
type ValidationErr struct {
Value interface{}
ErrType string
Context string
Description string
Field string
}
// NewMapAsConfig creates AsConfig. Typically, an unmarshalled yaml file is passed in
func NewMapAsConfig(
log logr.Logger, configMap map[string]interface{},
) (*AsConfig, error) {
baseConf := newMap(log, configMap)
return &AsConfig{
log: log,
baseConf: &baseConf,
}, nil
}
// newMap converts passed in map[string]interface{} into Conf
func newMap(log logr.Logger, configMap map[string]interface{}) Conf {
return flattenConf(log, toConf(log, configMap), sep)
}
// IsValid checks validity of config
func (cfg *AsConfig) IsValid(log logr.Logger, version string) (
bool, []*ValidationErr, error,
) {
return confIsValid(log, cfg.baseConf, version)
}
// ToConfFile returns DotConf
func (cfg *AsConfig) ToConfFile() DotConf {
conf := cfg.baseConf
return confToDotConf(cfg.log, conf)
}
// ToMap returns a pointer to the
// expanded map form of AsConfig
func (cfg *AsConfig) ToMap() *Conf {
cpy := cfg.baseConf.DeepClone()
res := expandConf(cfg.log, &cpy, sep)
return &res
}
// GetFlatMap returns a pointer to the copy
// of the flattened config stored in cfg
func (cfg *AsConfig) GetFlatMap() *Conf {
res := cfg.baseConf.DeepClone()
return &res
}
// FromConfFile unmarshales the aerospike config text in "in" into a new *AsConfig
func FromConfFile(log logr.Logger, in io.Reader) (*AsConfig, error) {
scanner := bufio.NewScanner(in)
configMap, err := process(log, scanner, Conf{})
if err != nil {
return nil, err
}
return NewMapAsConfig(log, configMap)
}
// IsSupportedVersion returns true if version supported else false
func IsSupportedVersion(ver string) (bool, error) {
return isSupportedVersion(ver)
}
// BaseVersion returns base-version for ver
func BaseVersion(ver string) (string, error) {
return baseVersion(ver)
}