Skip to content

Commit

Permalink
fix config checker to support yaml tag flow (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard authored May 19, 2024
1 parent 8704bfc commit 1aafce7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkgconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"
"os"
"reflect"
"strings"

"github.com/pkg/errors"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -112,12 +113,16 @@ func CheckConfigWithTags(v reflect.Value, userCfg map[string]interface{}) error
for i := 0; i < v.NumField(); i++ {
fieldValue := v.Field(i)
fieldType := t.Field(i)

// get name from yaml tag
fieldTag := fieldType.Tag.Get("yaml")
tagClean := strings.TrimSuffix(fieldTag, ",flow")

if fieldTag == k {
// compare
if tagClean == k {
keyExist = true
}
if fieldValue.Kind() == reflect.Struct && fieldTag == k {
if fieldValue.Kind() == reflect.Struct && tagClean == k {
if kvMap, ok := kv.(map[string]interface{}); ok {
err := CheckConfigWithTags(fieldValue, kvMap)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions pkgconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@ multiplexer:
routes:
- from: [ tap ]
to: [ scalyr ]
`,
wantErr: false,
},
{
name: "Valid tranforms key with flow argument",
content: `
multiplexer:
collectors:
- name: tap
dnstap:
listen-ip: 0.0.0.0
transforms:
atags:
tags: [ "TXT:google", "MX:apple" ]
`,
wantErr: false,
},
Expand Down

0 comments on commit 1aafce7

Please sign in to comment.