Skip to content

Commit

Permalink
More bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
banjoh committed Sep 13, 2023
1 parent 9957fab commit a53acb4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
20 changes: 9 additions & 11 deletions pkg/redact/literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (
)

type literalRedactor struct {
matchString string
filePath string
redactName string
isDefault bool
match []byte
filePath string
redactName string
isDefault bool
}

func literalString(matchString, path, name string) Redactor {
func literalString(match []byte, path, name string) Redactor {
return literalRedactor{
matchString: matchString,
filePath: path,
redactName: name,
match: match,
filePath: path,
redactName: name,
}
}

Expand All @@ -35,9 +35,7 @@ func (r literalRedactor) Redact(input io.Reader, path string) io.Reader {
}
}()

// TODO: Convert to bytes at source
mask := []byte(MASK_TEXT)
match := []byte(r.matchString)

reader := bufio.NewReader(input)
lineNum := 0
Expand All @@ -49,7 +47,7 @@ func (r literalRedactor) Redact(input io.Reader, path string) io.Reader {
return
}

clean := bytes.ReplaceAll(line, match, mask)
clean := bytes.ReplaceAll(line, r.match, mask)

// io.WriteString would be nicer, but scanner strips new lines
fmt.Fprintf(writer, "%s\n", clean)
Expand Down
4 changes: 2 additions & 2 deletions pkg/redact/multi_line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package redact

import (
"bytes"
"io/ioutil"
"io"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -101,7 +101,7 @@ func Test_NewMultiLineRedactorr(t *testing.T) {
req.NoError(err)
outReader := reRunner.Redact(bytes.NewReader([]byte(tt.inputString)), "")

gotBytes, err := ioutil.ReadAll(outReader)
gotBytes, err := io.ReadAll(outReader)
req.NoError(err)
req.Equal(tt.wantString, string(gotBytes))
GetRedactionList()
Expand Down
2 changes: 1 addition & 1 deletion pkg/redact/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta2.Redact
}

for j, literal := range redact.Removals.Values {
additionalRedactors = append(additionalRedactors, literalString(literal, path, redactorName(i, j, redact.Name, "literal")))
additionalRedactors = append(additionalRedactors, literalString([]byte(literal), path, redactorName(i, j, redact.Name, "literal")))
}

for j, re := range redact.Removals.Regex {
Expand Down

0 comments on commit a53acb4

Please sign in to comment.