forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
removed.go
49 lines (38 loc) · 980 Bytes
/
removed.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
package cfgwarn
import (
"fmt"
"strings"
"github.com/joeshaw/multierror"
"github.com/elastic/beats/libbeat/common"
)
func CheckRemoved5xSettings(cfg *common.Config, settings ...string) error {
var errs multierror.Errors
for _, setting := range settings {
if err := CheckRemoved5xSetting(cfg, setting); err != nil {
errs = append(errs, err)
}
}
return errs.Err()
}
// CheckRemoved5xSetting prints a warning if the obsolete setting is used.
func CheckRemoved5xSetting(cfg *common.Config, setting string) error {
segments := strings.Split(setting, ".")
L := len(segments)
name := segments[L-1]
path := segments[:L-1]
current := cfg
for _, p := range path {
current, _ := current.Child(p, -1)
if current == nil {
break
}
}
// full path to setting not available -> setting not found
if current == nil {
return nil
}
if !current.HasField(name) {
return nil
}
return fmt.Errorf("setting '%v' has been removed", current.PathOf(name))
}