Skip to content

Commit

Permalink
fix: Prevent unexpected warning from Resty when calling Client.SetDeb…
Browse files Browse the repository at this point in the history
…ug(false) (#508)
  • Loading branch information
lgarber-akamai authored May 21, 2024
1 parent 30da20d commit 3bcb4a6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ func (c *Client) R(ctx context.Context) *resty.Request {
func (c *Client) SetDebug(debug bool) *Client {
c.debug = debug
c.resty.SetDebug(debug)
// this ensures that if there is an Authorization header present, the value is sanitized/masked
c.sanitizeAuthorizationHeader()

return c
}
Expand Down Expand Up @@ -414,12 +412,14 @@ func (c *Client) SetHeader(name, value string) {
c.resty.SetHeader(name, value)
}

func (c *Client) sanitizeAuthorizationHeader() {
func (c *Client) enableLogSanitization() *Client {
c.resty.OnRequestLog(func(r *resty.RequestLog) error {
// masking authorization header
r.Header.Set("Authorization", "Bearer *******************************")
return nil
})

return c
}

// NewClient factory to create new Client struct
Expand Down Expand Up @@ -468,7 +468,8 @@ func NewClient(hc *http.Client) (client Client) {
SetRetryWaitTime(APISecondsPerPoll * time.Second).
SetPollDelay(APISecondsPerPoll * time.Second).
SetRetries().
SetDebug(envDebug)
SetDebug(envDebug).
enableLogSanitization()

return
}
Expand Down

0 comments on commit 3bcb4a6

Please sign in to comment.