Skip to content
Snippets Groups Projects
Commit f2075728 authored by Jano Hendriks's avatar Jano Hendriks
Browse files

Add function to mask API key

parent acc016cf
Branches
Tags v1.84.0
No related merge requests found
......@@ -32,3 +32,14 @@ func GetApiKeyFromHeaders(headers map[string]string) string {
}
return ""
}
// MaskAPIKey masks an API key in the form "abc***xyz"
func MaskAPIKey(key string) string {
keyRunes := []rune(key)
keyLength := len(keyRunes)
if keyLength > 6 {
return string(keyRunes[:3]) + "***" + string(keyRunes[keyLength-3:])
}
// This shouldn't happen, but if we don't have more than 6 characters, mask in the form "***z"
return "***" + string(keyRunes[keyLength-1])
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment