Skip to content

Commit

Permalink
Refactoring: renaming to be bit more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator committed Jan 17, 2020
1 parent 3501706 commit fbd3122
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions libbeat/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func DebugString(c *Config, filterPrivate bool) string {
return fmt.Sprintf("<config error> %v", err)
}
if filterPrivate {
filterDebugObject(content)
applyLoggingMask(content)
}
j, _ := json.MarshalIndent(content, "", " ")
bufs = append(bufs, string(j))
Expand All @@ -368,7 +368,7 @@ func DebugString(c *Config, filterPrivate bool) string {
return fmt.Sprintf("<config error> %v", err)
}
if filterPrivate {
filterDebugObject(content)
applyLoggingMask(content)
}
j, _ := json.MarshalIndent(content, "", " ")
bufs = append(bufs, string(j))
Expand Down
10 changes: 5 additions & 5 deletions libbeat/common/logging.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package common

var debugMasklist = MakeStringSet(
var maskList = MakeStringSet(
"password",
"passphrase",
"key_passphrase",
Expand All @@ -12,11 +12,11 @@ var debugMasklist = MakeStringSet(
"hosts",
)

func filterDebugObject(c interface{}) {
func applyLoggingMask(c interface{}) {
switch cfg := c.(type) {
case map[string]interface{}:
for k, v := range cfg {
if debugMasklist.Has(k) {
if maskList.Has(k) {
if arr, ok := v.([]interface{}); ok {
for i := range arr {
arr[i] = "xxxxx"
Expand All @@ -25,13 +25,13 @@ func filterDebugObject(c interface{}) {
cfg[k] = "xxxxx"
}
} else {
filterDebugObject(v)
applyLoggingMask(v)
}
}

case []interface{}:
for _, elem := range cfg {
filterDebugObject(elem)
applyLoggingMask(elem)
}
}
}
4 changes: 2 additions & 2 deletions libbeat/common/mapstr.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (m MapStr) MarshalLogObject(enc zapcore.ObjectEncoder) error {
}

debugM := m.Clone()
filterDebugObject(map[string]interface{}(debugM))
applyLoggingMask(map[string]interface{}(debugM))

keys := make([]string, 0, len(debugM))
for k := range debugM {
Expand All @@ -246,7 +246,7 @@ func (m MapStr) Format(f fmt.State, c rune) {
}

debugM := m.Clone()
filterDebugObject(map[string]interface{}(debugM))
applyLoggingMask(map[string]interface{}(debugM))

io.WriteString(f, debugM.String())
}
Expand Down

0 comments on commit fbd3122

Please sign in to comment.