@@ -20,6 +20,7 @@ const (
2020
2121var allRedactions RedactionList
2222var redactionListMut sync.Mutex
23+ var pendingRedactions sync.WaitGroup
2324
2425func init () {
2526 allRedactions = RedactionList {
@@ -45,13 +46,6 @@ type Redaction struct {
4546 File string
4647}
4748
48- func addRedaction (redaction Redaction ) {
49- redactionListMut .Lock ()
50- defer redactionListMut .Unlock ()
51- allRedactions .ByRedactor [redaction .RedactorName ] = append (allRedactions .ByRedactor [redaction .RedactorName ], redaction )
52- allRedactions .ByFile [redaction .File ] = append (allRedactions .ByFile [redaction .File ], redaction )
53- }
54-
5549func Redact (input []byte , path string , additionalRedactors []* troubleshootv1beta1.Redact ) ([]byte , error ) {
5650 redactors , err := getRedactors (path )
5751 if err != nil {
@@ -77,6 +71,22 @@ func Redact(input []byte, path string, additionalRedactors []*troubleshootv1beta
7771 return redacted , nil
7872}
7973
74+ func GetRedactionList () RedactionList {
75+ pendingRedactions .Wait ()
76+ redactionListMut .Lock ()
77+ defer redactionListMut .Unlock ()
78+ return allRedactions
79+ }
80+
81+ func ResetRedactionList () {
82+ redactionListMut .Lock ()
83+ defer redactionListMut .Unlock ()
84+ allRedactions = RedactionList {
85+ ByRedactor : map [string ][]Redaction {},
86+ ByFile : map [string ][]Redaction {},
87+ }
88+ }
89+
8090func buildAdditionalRedactors (path string , redacts []* troubleshootv1beta1.Redact ) ([]Redactor , error ) {
8191 additionalRedactors := []Redactor {}
8292 for i , redact := range redacts {
@@ -281,6 +291,17 @@ func readLine(r *bufio.Reader) (string, error) {
281291 return string (completeLine ), nil
282292}
283293
294+ func addRedaction (redaction Redaction ) {
295+ pendingRedactions .Add (1 )
296+ go func (redaction Redaction ) {
297+ redactionListMut .Lock ()
298+ defer redactionListMut .Unlock ()
299+ defer pendingRedactions .Done ()
300+ allRedactions .ByRedactor [redaction .RedactorName ] = append (allRedactions .ByRedactor [redaction .RedactorName ], redaction )
301+ allRedactions .ByFile [redaction .File ] = append (allRedactions .ByFile [redaction .File ], redaction )
302+ }(redaction )
303+ }
304+
284305func redactorName (redactorNum , withinRedactorNum int , redactorName , redactorType , redactorLiteral string ) string {
285306 if redactorName != "" {
286307 return fmt .Sprintf ("%s-%d" , redactorName , withinRedactorNum )
0 commit comments