improvements to config parsing

This commit is contained in:
JackDoan committed 2026-10-01 10:18:30 -05:00
1 parent ed8ae57fee
commit 04e80f0dcf
6 files changed
+58 -7

No files matched your search

+7 -2
View File
@@ -159,6 +159,9 @@ func yamlToConfigRule(l *slog.Logger, p any, table string, i int) (configRule, e
if len(v) > 1 {
return r, errors.New("group should contain a single value, an array with more than one entry was provided")
}
if len(v) == 0 {
return r, errors.New("group should contain a single value, an empty array was provided")
}
l.Warn("group was an array with a single value, converting to simple value",
"table", table,
@@ -169,13 +172,15 @@ func yamlToConfigRule(l *slog.Logger, p any, table string, i int) (configRule, e
singleGroup := toString("group", m)
if rg, ok := m["groups"]; ok {
// A null value, `groups:` with nothing after it, is the same as no groups
if rg, ok := m["groups"]; ok && rg != nil {
switch reflect.TypeOf(rg).Kind() {
case reflect.Slice:
// Every entry is read as a string, as the other fields are, so `groups: [1, 2]` is the groups "1" and "2"
v := reflect.ValueOf(rg)
r.Groups = make([]string, v.Len())
for i := 0; i < v.Len(); i++ {
r.Groups[i] = v.Index(i).Interface().(string)
r.Groups[i] = fmt.Sprintf("%v", v.Index(i).Interface())
}
case reflect.String:
r.Groups = []string{rg.(string)}