(urlIn string, passwordOnly bool)
| 99 | } |
| 100 | |
| 101 | func RedactBasicAuthURL(urlIn string, passwordOnly bool) (string, error) { |
| 102 | urlParsed, err := url.Parse(urlIn) |
| 103 | if err != nil { |
| 104 | // err can't be wrapped or logged as it contains unredacted data from the provided url |
| 105 | return "", fmt.Errorf("unable to redact URL, returning empty string") |
| 106 | } |
| 107 | if urlParsed.User != nil { |
| 108 | user := urlParsed.User.Username() |
| 109 | if !passwordOnly { |
| 110 | user = RedactedStr |
| 111 | } |
| 112 | urlParsed.User = url.UserPassword(user, RedactedStr) |
| 113 | } |
| 114 | |
| 115 | return urlParsed.String(), nil |
| 116 | } |
| 117 | |
| 118 | // GenerateRandomSecret returns a cryptographically-secure 160-bit random number encoded as a hex string. |
| 119 | func GenerateRandomSecret() (string, error) { |
no test coverage detected