Files
mostlymatter/vendor/github.com/splitio/go-toolkit/v3/logging/functions.go
Christopher Speller 1aadd36644 MM-28859 Add feature flag managment system using split.io and remove viper. (#15954)
* Add feature flag managment system using split.io and remove viper.

* Fixing tests.

* Attempt to fix postgres tests.

* Fix watch filepath for advanced logging.

* Review fixes.

* Some error wrapping.

* Remove unessisary store interface.

* Desanitize SplitKey

* Simplify.

* Review feedback.

* Rename split mlog adatper to split logger.

* fsInner

* Style.

* Restore oldcfg test.

* Downgrading non-actionable feature flag errors to warnings.

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-29 15:54:39 -07: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
}