github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/trace/trace.go (about)

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