forked from hashicorp/go-getter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url.go
28 lines (24 loc) · 733 Bytes
/
url.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package getter
import "net/url"
// RedactURL is a port of url.Redacted from the standard library,
// which is like url.String but replaces any password with "redacted".
// Only the password in u.URL is redacted. This allows the library
// to maintain compatibility with go1.14.
// This port was also extended to redact SSH key from URL query parameter.
func RedactURL(u *url.URL) string {
if u == nil {
return ""
}
ru := *u
if _, has := ru.User.Password(); has {
ru.User = url.UserPassword(ru.User.Username(), "redacted")
}
q := ru.Query()
if q.Get("sshkey") != "" {
q.Set("sshkey", "redacted")
ru.RawQuery = q.Encode()
}
return ru.String()
}