Skip to content

Commit 81d757b

Browse files
committed
feat: hidden mongo url credentials
1 parent 298451b commit 81d757b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

types/host.go

+17
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,20 @@ func (h *Host) GetType() HostType {
9696
}
9797
return HttpType
9898
}
99+
100+
// SecureURL - returns a secure url that can be used in logs or alerts. It will hide the password if present.
101+
func (h *Host) SecureURL() string {
102+
url := h.URL
103+
if strings.HasPrefix(url, "mongodb://") {
104+
if strings.Contains(url, "@") {
105+
parts := strings.Split(url, "@")
106+
creds := strings.Split(parts[0], ":")
107+
if len(creds) == 3 {
108+
creds[2] = "*****"
109+
url = strings.Join(creds, ":") + "@" + parts[1]
110+
}
111+
}
112+
return url
113+
}
114+
return url
115+
}

0 commit comments

Comments
 (0)