From 15b100e0eee9f7dfc6af5a1402bf39816a5e32e8 Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Mon, 27 Apr 2020 22:01:04 -0400 Subject: [PATCH] support * when redacting yaml maps --- pkg/redact/yaml.go | 8 ++++++++ pkg/redact/yaml_test.go | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pkg/redact/yaml.go b/pkg/redact/yaml.go index 59e93f801..772286a6b 100644 --- a/pkg/redact/yaml.go +++ b/pkg/redact/yaml.go @@ -94,6 +94,14 @@ func (r *YamlRedactor) redactYaml(in interface{}, path []string) interface{} { } return typed case map[interface{}]interface{}: + if path[0] == "*" && len(typed) > 0 { + newMap := map[interface{}]interface{}{} + for key, child := range typed { + newMap[key] = r.redactYaml(child, path[1:]) + } + return newMap + } + child, ok := typed[path[0]] if ok { newChild := r.redactYaml(child, path[1:]) diff --git a/pkg/redact/yaml_test.go b/pkg/redact/yaml_test.go index 617bb4e8f..3df6ecbd8 100644 --- a/pkg/redact/yaml_test.go +++ b/pkg/redact/yaml_test.go @@ -152,6 +152,26 @@ xyz: inputString: `improperly-formatted: yaml`, wantString: `improperly-formatted: yaml`, }, + { + name: "star index in map", + path: []string{"abc", "xyz", "*"}, + inputString: ` +abc: + xyz: + a: b + c: d + e: f +xyz: + hello: {}`, + wantString: `abc: + xyz: + a: '***HIDDEN***' + c: '***HIDDEN***' + e: '***HIDDEN***' +xyz: + hello: {} +`, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {