mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
include whether a redaction is from a default redactor in reports
This commit is contained in:
@@ -11,6 +11,7 @@ type literalRedactor struct {
|
||||
matchString string
|
||||
filePath string
|
||||
redactName string
|
||||
isDefault bool
|
||||
}
|
||||
|
||||
func literalString(matchString, path, name string) Redactor {
|
||||
@@ -58,6 +59,7 @@ func (r literalRedactor) Redact(input io.Reader) io.Reader {
|
||||
CharactersRemoved: len(line) - len(clean),
|
||||
Line: lineNum,
|
||||
File: r.filePath,
|
||||
IsDefaultRedactor: r.isDefault,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,10 @@ type MultiLineRedactor struct {
|
||||
maskText string
|
||||
filePath string
|
||||
redactName string
|
||||
isDefault bool
|
||||
}
|
||||
|
||||
func NewMultiLineRedactor(re1, re2, maskText, path, name string) (*MultiLineRedactor, error) {
|
||||
func NewMultiLineRedactor(re1, re2, maskText, path, name string, isDefault bool) (*MultiLineRedactor, error) {
|
||||
compiled1, err := regexp.Compile(re1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -24,7 +25,7 @@ func NewMultiLineRedactor(re1, re2, maskText, path, name string) (*MultiLineReda
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &MultiLineRedactor{re1: compiled1, re2: compiled2, maskText: maskText, filePath: path, redactName: name}, nil
|
||||
return &MultiLineRedactor{re1: compiled1, re2: compiled2, maskText: maskText, filePath: path, redactName: name, isDefault: isDefault}, nil
|
||||
}
|
||||
|
||||
func (r *MultiLineRedactor) Redact(input io.Reader) io.Reader {
|
||||
@@ -75,6 +76,7 @@ func (r *MultiLineRedactor) Redact(input io.Reader) io.Reader {
|
||||
CharactersRemoved: len(line2) - len(clean),
|
||||
Line: lineNum,
|
||||
File: r.filePath,
|
||||
IsDefaultRedactor: r.isDefault,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ type Redaction struct {
|
||||
CharactersRemoved int `json:"charactersRemoved" yaml:"charactersRemoved"`
|
||||
Line int `json:"line" yaml:"line"`
|
||||
File string `json:"file" yaml:"file"`
|
||||
IsDefaultRedactor bool `json:"isDefaultRedactor" yaml:"isDefaultRedactor"`
|
||||
}
|
||||
|
||||
func Redact(input []byte, path string, additionalRedactors []*troubleshootv1beta1.Redact) ([]byte, error) {
|
||||
@@ -104,7 +105,7 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact
|
||||
}
|
||||
|
||||
for j, re := range redact.Regex {
|
||||
r, err := NewSingleLineRedactor(re, MASK_TEXT, path, redactorName(i, j, redact.Name, "regex"))
|
||||
r, err := NewSingleLineRedactor(re, MASK_TEXT, path, redactorName(i, j, redact.Name, "regex"), false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "redactor %q", re)
|
||||
}
|
||||
@@ -116,7 +117,7 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact
|
||||
}
|
||||
|
||||
for j, re := range redact.MultiLine {
|
||||
r, err := NewMultiLineRedactor(re.Selector, re.Redactor, MASK_TEXT, path, redactorName(i, j, redact.Name, "multiLine"))
|
||||
r, err := NewMultiLineRedactor(re.Selector, re.Redactor, MASK_TEXT, path, redactorName(i, j, redact.Name, "multiLine"), false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "multiline redactor %+v", re)
|
||||
}
|
||||
@@ -258,7 +259,7 @@ func getRedactors(path string) ([]Redactor, error) {
|
||||
|
||||
redactors := make([]Redactor, 0)
|
||||
for _, re := range singleLines {
|
||||
r, err := NewSingleLineRedactor(re.regex, MASK_TEXT, path, re.name)
|
||||
r, err := NewSingleLineRedactor(re.regex, MASK_TEXT, path, re.name, true)
|
||||
if err != nil {
|
||||
return nil, err // maybe skip broken ones?
|
||||
}
|
||||
@@ -308,7 +309,7 @@ func getRedactors(path string) ([]Redactor, error) {
|
||||
}
|
||||
|
||||
for _, l := range doubleLines {
|
||||
r, err := NewMultiLineRedactor(l.line1, l.line2, MASK_TEXT, path, l.name)
|
||||
r, err := NewMultiLineRedactor(l.line1, l.line2, MASK_TEXT, path, l.name, true)
|
||||
if err != nil {
|
||||
return nil, err // maybe skip broken ones?
|
||||
}
|
||||
|
||||
@@ -12,14 +12,15 @@ type SingleLineRedactor struct {
|
||||
maskText string
|
||||
filePath string
|
||||
redactName string
|
||||
isDefault bool
|
||||
}
|
||||
|
||||
func NewSingleLineRedactor(re, maskText, path, name string) (*SingleLineRedactor, error) {
|
||||
func NewSingleLineRedactor(re, maskText, path, name string, isDefault bool) (*SingleLineRedactor, error) {
|
||||
compiled, err := regexp.Compile(re)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SingleLineRedactor{re: compiled, maskText: maskText, filePath: path, redactName: name}, nil
|
||||
return &SingleLineRedactor{re: compiled, maskText: maskText, filePath: path, redactName: name, isDefault: isDefault}, nil
|
||||
}
|
||||
|
||||
func (r *SingleLineRedactor) Redact(input io.Reader) io.Reader {
|
||||
@@ -67,6 +68,7 @@ func (r *SingleLineRedactor) Redact(input io.Reader) io.Reader {
|
||||
CharactersRemoved: len(line) - len(clean),
|
||||
Line: lineNum,
|
||||
File: r.filePath,
|
||||
IsDefaultRedactor: r.isDefault,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ func TestNewSingleLineRedactor(t *testing.T) {
|
||||
defer scopetest.End()
|
||||
|
||||
req := require.New(t)
|
||||
reRunner, err := NewSingleLineRedactor(tt.re, MASK_TEXT, "testfile", tt.name)
|
||||
reRunner, err := NewSingleLineRedactor(tt.re, MASK_TEXT, "testfile", tt.name, false)
|
||||
req.NoError(err)
|
||||
|
||||
outReader := reRunner.Redact(bytes.NewReader([]byte(tt.inputString)))
|
||||
|
||||
@@ -16,6 +16,7 @@ type YamlRedactor struct {
|
||||
foundMatch bool
|
||||
filePath string
|
||||
redactName string
|
||||
isDefault bool
|
||||
}
|
||||
|
||||
func NewYamlRedactor(yamlPath, filePath, name string) *YamlRedactor {
|
||||
@@ -69,6 +70,7 @@ func (r *YamlRedactor) Redact(input io.Reader) io.Reader {
|
||||
CharactersRemoved: len(doc) - len(newBytes),
|
||||
Line: 0, // line 0 because we have no way to tell what line was impacted
|
||||
File: r.filePath,
|
||||
IsDefaultRedactor: r.isDefault,
|
||||
})
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user