mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
Alertmanager URI might contain basic auth username & password, we should replace password with 'xxx' in logs and and error messages. Go will still print it in HTTP request errors, but that will be fixed in the next Go release - https://go-review.googlesource.com/c/go/+/102855 Fixes #259
33 lines
715 B
Go
33 lines
715 B
Go
package uri
|
|
|
|
import (
|
|
"net/url"
|
|
"path"
|
|
)
|
|
|
|
// JoinURL can be used to join a base url (http(s)://domain.com) and a path (/my/path)
|
|
// it will return a joined string or an error (if you supply invalid url)
|
|
func JoinURL(base string, sub string) (string, error) {
|
|
u, err := url.Parse(base)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
u.Path = path.Join(u.Path, sub)
|
|
return u.String(), nil
|
|
}
|
|
|
|
// SanitizeURI returns a copy of an URI string with password replaced by "xxx"
|
|
func SanitizeURI(s string) string {
|
|
u, err := url.Parse(s)
|
|
if err != nil {
|
|
return s
|
|
}
|
|
if u.User != nil {
|
|
if _, pwdSet := u.User.Password(); pwdSet {
|
|
u.User = url.UserPassword(u.User.Username(), "xxx")
|
|
}
|
|
return u.String()
|
|
}
|
|
return s
|
|
}
|