@@ -79,7 +79,7 @@ func Redact(input []byte, path string, additionalRedactors []*troubleshootv1beta
7979
8080func buildAdditionalRedactors (path string , redacts []* troubleshootv1beta1.Redact ) ([]Redactor , error ) {
8181 additionalRedactors := []Redactor {}
82- for _ , redact := range redacts {
82+ for i , redact := range redacts {
8383 if redact == nil {
8484 continue
8585 }
@@ -93,28 +93,30 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact
9393 continue
9494 }
9595
96+ withinRedactNum := 0 // give unique redaction names
97+
9698 for _ , re := range redact .Regex {
97- r , err := NewSingleLineRedactor (re , MASK_TEXT , path )
99+ r , err := NewSingleLineRedactor (re , MASK_TEXT , path , redactorName ( i , withinRedactNum , redact . Name , "regex" , "" ) )
98100 if err != nil {
99101 return nil , errors .Wrapf (err , "redactor %q" , re )
100102 }
101103 additionalRedactors = append (additionalRedactors , r )
102104 }
103105
104106 for _ , literal := range redact .Values {
105- additionalRedactors = append (additionalRedactors , literalString (literal , path ))
107+ additionalRedactors = append (additionalRedactors , literalString (literal , path , redactorName ( i , withinRedactNum , redact . Name , "literal" , "" ) ))
106108 }
107109
108110 for _ , re := range redact .MultiLine {
109- r , err := NewMultiLineRedactor (re .Selector , re .Redactor , MASK_TEXT , path )
111+ r , err := NewMultiLineRedactor (re .Selector , re .Redactor , MASK_TEXT , path , redactorName ( i , withinRedactNum , redact . Name , "multiLine" , "" ) )
110112 if err != nil {
111113 return nil , errors .Wrapf (err , "multiline redactor %+v" , re )
112114 }
113115 additionalRedactors = append (additionalRedactors , r )
114116 }
115117
116118 for _ , yaml := range redact .Yaml {
117- r := NewYamlRedactor (yaml , path )
119+ r := NewYamlRedactor (yaml , path , redactorName ( i , withinRedactNum , redact . Name , "yaml" , "" ) )
118120 additionalRedactors = append (additionalRedactors , r )
119121 }
120122 }
@@ -190,8 +192,8 @@ func getRedactors(path string) ([]Redactor, error) {
190192 }
191193
192194 redactors := make ([]Redactor , 0 )
193- for _ , re := range singleLines {
194- r , err := NewSingleLineRedactor (re , MASK_TEXT , path )
195+ for i , re := range singleLines {
196+ r , err := NewSingleLineRedactor (re , MASK_TEXT , path , redactorName ( - 1 , i , "" , "defaultRegex" , re ) )
195197 if err != nil {
196198 return nil , err // maybe skip broken ones?
197199 }
@@ -232,8 +234,8 @@ func getRedactors(path string) ([]Redactor, error) {
232234 },
233235 }
234236
235- for _ , l := range doubleLines {
236- r , err := NewMultiLineRedactor (l .line1 , l .line2 , MASK_TEXT , path )
237+ for i , l := range doubleLines {
238+ r , err := NewMultiLineRedactor (l .line1 , l .line2 , MASK_TEXT , path , redactorName ( - 1 , i , "" , "defaultMultiLine" , l . line1 ) )
237239 if err != nil {
238240 return nil , err // maybe skip broken ones?
239241 }
@@ -278,3 +280,13 @@ func readLine(r *bufio.Reader) (string, error) {
278280 }
279281 return string (completeLine ), nil
280282}
283+
284+ func redactorName (redactorNum , withinRedactorNum int , redactorName , redactorType , redactorLiteral string ) string {
285+ if redactorName != "" {
286+ return fmt .Sprintf ("%s-%d" , redactorName , withinRedactorNum )
287+ }
288+ if redactorLiteral == "" {
289+ return fmt .Sprintf ("unnamed-%d.%d-%s" , redactorNum , withinRedactorNum , redactorType )
290+ }
291+ return fmt .Sprintf ("%s.%d-%q" , redactorType , withinRedactorNum , redactorLiteral )
292+ }
0 commit comments