diff --git a/client.go b/client.go index 014a86213..d33e078b2 100644 --- a/client.go +++ b/client.go @@ -293,11 +293,16 @@ func (c *httpClient) logRequest(req *http.Request, method, url string, bodyBuffe reqBody = "nil" } + headers := req.Header.Clone() + + // Sanitize the header for logging purposes + headers.Set("Authorization", "Bearer *******************************") + var logBuf bytes.Buffer err := reqLogTemplate.Execute(&logBuf, map[string]interface{}{ "Method": method, "URL": url, - "Headers": req.Header, + "Headers": headers, "Body": reqBody, }) if err == nil { @@ -699,16 +704,6 @@ func (c *Client) SetHeader(name, value string) { c.resty.SetHeader(name, value) } -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 func NewClient(hc *http.Client) (client Client) { if hc != nil { @@ -755,8 +750,7 @@ func NewClient(hc *http.Client) (client Client) { SetRetryWaitTime(APISecondsPerPoll * time.Second). SetPollDelay(APISecondsPerPoll * time.Second). SetRetries(). - SetDebug(envDebug). - enableLogSanitization() + SetDebug(envDebug) return } diff --git a/go.work.sum b/go.work.sum index 5cc18d7e6..091549699 100644 --- a/go.work.sum +++ b/go.work.sum @@ -47,9 +47,12 @@ golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY= golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= +golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=