Skip to content

Commit 15b100e

Browse files
committed
support * when redacting yaml maps
1 parent 94ccf28 commit 15b100e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

pkg/redact/yaml.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ func (r *YamlRedactor) redactYaml(in interface{}, path []string) interface{} {
9494
}
9595
return typed
9696
case map[interface{}]interface{}:
97+
if path[0] == "*" && len(typed) > 0 {
98+
newMap := map[interface{}]interface{}{}
99+
for key, child := range typed {
100+
newMap[key] = r.redactYaml(child, path[1:])
101+
}
102+
return newMap
103+
}
104+
97105
child, ok := typed[path[0]]
98106
if ok {
99107
newChild := r.redactYaml(child, path[1:])

pkg/redact/yaml_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,26 @@ xyz:
152152
inputString: `improperly-formatted: yaml`,
153153
wantString: `improperly-formatted: yaml`,
154154
},
155+
{
156+
name: "star index in map",
157+
path: []string{"abc", "xyz", "*"},
158+
inputString: `
159+
abc:
160+
xyz:
161+
a: b
162+
c: d
163+
e: f
164+
xyz:
165+
hello: {}`,
166+
wantString: `abc:
167+
xyz:
168+
a: '***HIDDEN***'
169+
c: '***HIDDEN***'
170+
e: '***HIDDEN***'
171+
xyz:
172+
hello: {}
173+
`,
174+
},
155175
}
156176
for _, tt := range tests {
157177
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)