Skip to content

Commit f03916c

Browse files
committed
include whether a redaction is from a default redactor in reports
1 parent 252b29f commit f03916c

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

pkg/redact/literal.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type literalRedactor struct {
1111
matchString string
1212
filePath string
1313
redactName string
14+
isDefault bool
1415
}
1516

1617
func literalString(matchString, path, name string) Redactor {
@@ -58,6 +59,7 @@ func (r literalRedactor) Redact(input io.Reader) io.Reader {
5859
CharactersRemoved: len(line) - len(clean),
5960
Line: lineNum,
6061
File: r.filePath,
62+
IsDefaultRedactor: r.isDefault,
6163
})
6264
}
6365
}

pkg/redact/multi_line.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ type MultiLineRedactor struct {
1313
maskText string
1414
filePath string
1515
redactName string
16+
isDefault bool
1617
}
1718

18-
func NewMultiLineRedactor(re1, re2, maskText, path, name string) (*MultiLineRedactor, error) {
19+
func NewMultiLineRedactor(re1, re2, maskText, path, name string, isDefault bool) (*MultiLineRedactor, error) {
1920
compiled1, err := regexp.Compile(re1)
2021
if err != nil {
2122
return nil, err
@@ -24,7 +25,7 @@ func NewMultiLineRedactor(re1, re2, maskText, path, name string) (*MultiLineReda
2425
if err != nil {
2526
return nil, err
2627
}
27-
return &MultiLineRedactor{re1: compiled1, re2: compiled2, maskText: maskText, filePath: path, redactName: name}, nil
28+
return &MultiLineRedactor{re1: compiled1, re2: compiled2, maskText: maskText, filePath: path, redactName: name, isDefault: isDefault}, nil
2829
}
2930

3031
func (r *MultiLineRedactor) Redact(input io.Reader) io.Reader {
@@ -75,6 +76,7 @@ func (r *MultiLineRedactor) Redact(input io.Reader) io.Reader {
7576
CharactersRemoved: len(line2) - len(clean),
7677
Line: lineNum,
7778
File: r.filePath,
79+
IsDefaultRedactor: r.isDefault,
7880
})
7981
}
8082

pkg/redact/redact.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Redaction struct {
4444
CharactersRemoved int `json:"charactersRemoved" yaml:"charactersRemoved"`
4545
Line int `json:"line" yaml:"line"`
4646
File string `json:"file" yaml:"file"`
47+
IsDefaultRedactor bool `json:"isDefaultRedactor" yaml:"isDefaultRedactor"`
4748
}
4849

4950
func Redact(input []byte, path string, additionalRedactors []*troubleshootv1beta1.Redact) ([]byte, error) {
@@ -104,7 +105,7 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact
104105
}
105106

106107
for j, re := range redact.Regex {
107-
r, err := NewSingleLineRedactor(re, MASK_TEXT, path, redactorName(i, j, redact.Name, "regex"))
108+
r, err := NewSingleLineRedactor(re, MASK_TEXT, path, redactorName(i, j, redact.Name, "regex"), false)
108109
if err != nil {
109110
return nil, errors.Wrapf(err, "redactor %q", re)
110111
}
@@ -116,7 +117,7 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact
116117
}
117118

118119
for j, re := range redact.MultiLine {
119-
r, err := NewMultiLineRedactor(re.Selector, re.Redactor, MASK_TEXT, path, redactorName(i, j, redact.Name, "multiLine"))
120+
r, err := NewMultiLineRedactor(re.Selector, re.Redactor, MASK_TEXT, path, redactorName(i, j, redact.Name, "multiLine"), false)
120121
if err != nil {
121122
return nil, errors.Wrapf(err, "multiline redactor %+v", re)
122123
}
@@ -258,7 +259,7 @@ func getRedactors(path string) ([]Redactor, error) {
258259

259260
redactors := make([]Redactor, 0)
260261
for _, re := range singleLines {
261-
r, err := NewSingleLineRedactor(re.regex, MASK_TEXT, path, re.name)
262+
r, err := NewSingleLineRedactor(re.regex, MASK_TEXT, path, re.name, true)
262263
if err != nil {
263264
return nil, err // maybe skip broken ones?
264265
}
@@ -308,7 +309,7 @@ func getRedactors(path string) ([]Redactor, error) {
308309
}
309310

310311
for _, l := range doubleLines {
311-
r, err := NewMultiLineRedactor(l.line1, l.line2, MASK_TEXT, path, l.name)
312+
r, err := NewMultiLineRedactor(l.line1, l.line2, MASK_TEXT, path, l.name, true)
312313
if err != nil {
313314
return nil, err // maybe skip broken ones?
314315
}

pkg/redact/single_line.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ type SingleLineRedactor struct {
1212
maskText string
1313
filePath string
1414
redactName string
15+
isDefault bool
1516
}
1617

17-
func NewSingleLineRedactor(re, maskText, path, name string) (*SingleLineRedactor, error) {
18+
func NewSingleLineRedactor(re, maskText, path, name string, isDefault bool) (*SingleLineRedactor, error) {
1819
compiled, err := regexp.Compile(re)
1920
if err != nil {
2021
return nil, err
2122
}
22-
return &SingleLineRedactor{re: compiled, maskText: maskText, filePath: path, redactName: name}, nil
23+
return &SingleLineRedactor{re: compiled, maskText: maskText, filePath: path, redactName: name, isDefault: isDefault}, nil
2324
}
2425

2526
func (r *SingleLineRedactor) Redact(input io.Reader) io.Reader {
@@ -67,6 +68,7 @@ func (r *SingleLineRedactor) Redact(input io.Reader) io.Reader {
6768
CharactersRemoved: len(line) - len(clean),
6869
Line: lineNum,
6970
File: r.filePath,
71+
IsDefaultRedactor: r.isDefault,
7072
})
7173
}
7274
}

pkg/redact/single_line_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func TestNewSingleLineRedactor(t *testing.T) {
108108
defer scopetest.End()
109109

110110
req := require.New(t)
111-
reRunner, err := NewSingleLineRedactor(tt.re, MASK_TEXT, "testfile", tt.name)
111+
reRunner, err := NewSingleLineRedactor(tt.re, MASK_TEXT, "testfile", tt.name, false)
112112
req.NoError(err)
113113

114114
outReader := reRunner.Redact(bytes.NewReader([]byte(tt.inputString)))

pkg/redact/yaml.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type YamlRedactor struct {
1616
foundMatch bool
1717
filePath string
1818
redactName string
19+
isDefault bool
1920
}
2021

2122
func NewYamlRedactor(yamlPath, filePath, name string) *YamlRedactor {
@@ -69,6 +70,7 @@ func (r *YamlRedactor) Redact(input io.Reader) io.Reader {
6970
CharactersRemoved: len(doc) - len(newBytes),
7071
Line: 0, // line 0 because we have no way to tell what line was impacted
7172
File: r.filePath,
73+
IsDefaultRedactor: r.isDefault,
7274
})
7375

7476
return

0 commit comments

Comments
 (0)