Files
mostlymatter/vendor/github.com/splitio/go-toolkit/v4/logging/functions.go
Joram Wilander aba00a3cfd Update split SDK to 6.0.2 to fix sync bug (#17060)
* Update split SDK to 6.0.2 to fix sync bug

* Vendor and tidy
2021-03-04 11:16:08 -05:00

34 строки
830 B
Go

package logging
import (
"fmt"
"net/http"
"regexp"
"strings"
)
// ObfuscateAPIKey obfucate part of api key
func ObfuscateAPIKey(apikey string) string {
obfuscationIndex := 80
total := len(apikey)
charsToObfuscate := obfuscationIndex * total / 100
toShow := (total - charsToObfuscate) / 2
return strings.Join([]string{apikey[:toShow], apikey[len(apikey)-toShow:]}, "...")
}
// ObfuscateHTTPHeader obfuscates sensitive data into headers
func ObfuscateHTTPHeader(headers http.Header) string {
var re = regexp.MustCompile(`Authorization:\[Bearer ([0-9|a-z|A-Z|\s]*)\]`)
var str = fmt.Sprint(headers)
match := re.FindStringSubmatch(str)
if len(match) == 2 {
str = strings.Replace(str, match[1], ObfuscateAPIKey(match[1]), 1)
return fmt.Sprint("[REQUEST_HEADERS]", str, "[END_REQUEST_HEADERS]")
}
return str
}