Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move scrubber into its own package #393

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions internal/engine/experiment/tor/tor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
"github.com/ooni/probe-cli/v3/internal/runtimex"
"github.com/ooni/probe-cli/v3/internal/scrubber"
)

const (
Expand Down Expand Up @@ -282,7 +283,7 @@ func maybeSanitize(input TargetResults, kt keytarget) TargetResults {
// Implementation note: here we are using a strict scrubbing policy where
// we remove all IP _endpoints_, mainly for convenience, because we already
// have a well tested implementation that does that.
data = []byte(errorx.Scrub(string(data)))
data = []byte(scrubber.Scrub(string(data)))
var out TargetResults
err = json.Unmarshal(data, &out)
runtimex.PanicOnError(err, "json.Unmarshal should not fail here")
Expand Down Expand Up @@ -332,23 +333,23 @@ type scrubbingLogger struct {
}

func (sl scrubbingLogger) Debug(message string) {
sl.Logger.Debug(errorx.Scrub(message))
sl.Logger.Debug(scrubber.Scrub(message))
}

func (sl scrubbingLogger) Debugf(format string, v ...interface{}) {
sl.Debug(fmt.Sprintf(format, v...))
}

func (sl scrubbingLogger) Info(message string) {
sl.Logger.Info(errorx.Scrub(message))
sl.Logger.Info(scrubber.Scrub(message))
}

func (sl scrubbingLogger) Infof(format string, v ...interface{}) {
sl.Info(fmt.Sprintf(format, v...))
}

func (sl scrubbingLogger) Warn(message string) {
sl.Logger.Warn(errorx.Scrub(message))
sl.Logger.Warn(scrubber.Scrub(message))
}

func (sl scrubbingLogger) Warnf(format string, v ...interface{}) {
Expand Down
4 changes: 3 additions & 1 deletion internal/engine/netx/errorx/errorx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"fmt"
"regexp"
"strings"

"github.com/ooni/probe-cli/v3/internal/scrubber"
)

const (
Expand Down Expand Up @@ -287,7 +289,7 @@ func toFailureString(err error) string {
return FailureGenericTimeoutError
}
formatted := fmt.Sprintf("unknown_failure: %s", s)
return Scrub(formatted) // scrub IP addresses in the error
return scrubber.Scrub(formatted) // scrub IP addresses in the error
}

func toOperationString(err error, operation string) string {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package errorx
package scrubber

import "regexp"

Expand Down Expand Up @@ -64,7 +64,7 @@ func scrub(b []byte) []byte {
}

// Scrub sanitizes a string containing an error such that
// any occurrence of IP endpoints is scrubbed
// any occurrence of IP endpoints is scrubbed.
func Scrub(s string) string {
return string(scrub([]byte(s)))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package errorx
package scrubber

import (
"testing"
Expand Down