github.com/cloudfoundry/cli@v7.1.0+incompatible/util/ui/redacted_value.go (about) 1 package ui 2 3 import ( 4 "net/http" 5 "regexp" 6 ) 7 8 // RedactedValue is the text that is displayed for redacted content. (eg 9 // authorization tokens, passwords, etc.) 10 const RedactedValue = "[PRIVATE DATA HIDDEN]" 11 12 func RedactHeaders(header http.Header) http.Header { 13 redactedHeaders := make(http.Header) 14 re := regexp.MustCompile(`([&?]code)=[A-Za-z0-9\-._~!$'()*+,;=:@/?]*`) 15 for key, value := range header { 16 if key == "Authorization" || key == "Set-Cookie" { 17 redactedHeaders[key] = []string{RedactedValue} 18 } else { 19 for index, v := range value { 20 value[index] = re.ReplaceAllString(v, "$1="+RedactedValue) 21 } 22 redactedHeaders[key] = value 23 } 24 } 25 return redactedHeaders 26 }