Skip to content

Commit

Permalink
add opt out of redacting log output
Browse files Browse the repository at this point in the history
  • Loading branch information
jvatic committed Aug 21, 2021
1 parent ffbc0df commit d852106
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions audible/round_tripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import (
log "github.com/sirupsen/logrus"
)

var redactEnabled = true

func init() {
if v := os.Getenv("REDACT_DISABLE"); v == "true" {
redactEnabled = false
}
}

type roundTripper struct {
}

Expand Down Expand Up @@ -103,6 +111,9 @@ func logHeader(h http.Header, name string) log.LogFunction {
}

func redactURL(u *url.URL) *url.URL {
if !redactEnabled {
return u
}
redacted := &url.URL{
Scheme: u.Scheme,
Opaque: u.Opaque,
Expand All @@ -116,6 +127,9 @@ func redactURL(u *url.URL) *url.URL {
var redactQueryAllowlist = map[string]bool{"ipRedirectOverride": true}

func redactQuery(q url.Values) url.Values {
if !redactEnabled {
return q
}
redacted := make(url.Values, len(q))
for k, v := range q {
if allowed, ok := redactQueryAllowlist[k]; allowed && ok {
Expand All @@ -133,6 +147,9 @@ var (
)

func redactHTML(data []byte) []byte {
if !redactEnabled {
return data
}
doc, err := htmlquery.Parse(bytes.NewReader(data))
if err != nil {
return data
Expand Down

0 comments on commit d852106

Please sign in to comment.