-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move scrubbing logger to logx (#1319)
This diff is yak shaving for a subsequent diff that attempts to mitigate potential IP addresses leaks caused by using happy eyeballs more aggressively in the codebase. The general idea is that we previously had a netxlite implementation that gave IPv4 preference over IPv6, meaning that we would end up using IPv4 in most cases and very rarely IPv6. As part of my work to make beacons possible, I have introduced happy eyeballs, which means we may sometimes use IPv4 instead of IPv6 if we adopt happy eyeballs more widely. This fact makes it more likely that we include the IPv6 address of a probe when we know its IPv4 address or the other way around into measurements. To mitigate this possible issue before it actually is possible (note that I have not yet changed how we discover the probe IP), I am going to proactively modify the serialization of HTTP bodies and headers to scrub IP endpoints unconditionally. However, to do this, I need to decouple the scrubber package from model such that internal/model/archival.go can use the scrubber package. Part of ooni/probe#2531
- Loading branch information
1 parent
36d2bec
commit 4a86c54
Showing
5 changed files
with
74 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package logx | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ooni/probe-cli/v3/internal/model" | ||
"github.com/ooni/probe-cli/v3/internal/scrubber" | ||
) | ||
|
||
// ScrubberLogger is a [model.Logger] with scrubbing. All messages are scrubbed including the ones | ||
// that won't be emitted. As such, this logger is less efficient than a logger without scrubbing. | ||
// | ||
// The zero value is invalid; please init all MANDATORY fields. | ||
type ScrubberLogger struct { | ||
// Logger is the MANDATORY underlying logger to use. | ||
Logger model.Logger | ||
} | ||
|
||
// Debug scrubs and emits a debug message. | ||
func (sl *ScrubberLogger) Debug(message string) { | ||
sl.Logger.Debug(scrubber.Scrub(message)) | ||
} | ||
|
||
// Debugf scrubs, formats, and emits a debug message. | ||
func (sl *ScrubberLogger) Debugf(format string, v ...interface{}) { | ||
sl.Debug(fmt.Sprintf(format, v...)) | ||
} | ||
|
||
// Info scrubs and emits an informational message. | ||
func (sl *ScrubberLogger) Info(message string) { | ||
sl.Logger.Info(scrubber.Scrub(message)) | ||
} | ||
|
||
// Infof scrubs, formats, and emits an informational message. | ||
func (sl *ScrubberLogger) Infof(format string, v ...interface{}) { | ||
sl.Info(fmt.Sprintf(format, v...)) | ||
} | ||
|
||
// Warn scrubs and emits a warning message. | ||
func (sl *ScrubberLogger) Warn(message string) { | ||
sl.Logger.Warn(scrubber.Scrub(message)) | ||
} | ||
|
||
// Warnf scrubs, formats, and emits a warning message. | ||
func (sl *ScrubberLogger) Warnf(format string, v ...interface{}) { | ||
sl.Warn(fmt.Sprintf(format, v...)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.