-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.go
32 lines (23 loc) · 864 Bytes
/
trace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package trace
import (
"fmt"
"regexp"
. "code.cloudfoundry.org/cli/cf/i18n"
)
var LoggingToStdout bool
func Sanitize(input string) string {
re := regexp.MustCompile(`(?m)^Authorization: .*`)
sanitized := re.ReplaceAllString(input, "Authorization: "+PrivateDataPlaceholder())
re = regexp.MustCompile(`password=[^&]*&`)
sanitized = re.ReplaceAllString(sanitized, "password="+PrivateDataPlaceholder()+"&")
sanitized = sanitizeJSON("token", sanitized)
sanitized = sanitizeJSON("password", sanitized)
return sanitized
}
func sanitizeJSON(propertySubstring string, json string) string {
regex := regexp.MustCompile(fmt.Sprintf(`(?i)"([^"]*%s[^"]*)":\s*"[^\,]*"`, propertySubstring))
return regex.ReplaceAllString(json, fmt.Sprintf(`"$1":"%s"`, PrivateDataPlaceholder()))
}
func PrivateDataPlaceholder() string {
return T("[PRIVATE DATA HIDDEN]")
}