Skip to content

Commit

Permalink
Merge pull request #186 from replicatedhq/laverya/redact-yaml-star-ma…
Browse files Browse the repository at this point in the history
…p-support

support * when redacting yaml maps
  • Loading branch information
laverya authored Apr 28, 2020
2 parents 94ccf28 + 15b100e commit 6d3321c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/redact/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:])
Expand Down
20 changes: 20 additions & 0 deletions pkg/redact/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6d3321c

Please sign in to comment.