-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathmask.go
More file actions
24 lines (19 loc) · 721 Bytes
/
mask.go
File metadata and controls
24 lines (19 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package mask
import "regexp"
const maskReplacement = "×××"
var (
RepositoryConfidentialPart = regexp.MustCompile("[:/][^:/@]+?:([^:@]+?)@[^:/@]+?") // user:pass@host
// httpHeaderNames = regexp.MustCompile("(?i)^(Authorization)$")
// urlEnvKeys = regexp.MustCompile("(?i)^.+(_AUTH|_URL)$")
// hiddenEnvKeys = regexp.MustCompile("(?i)^(.+_KEY|.+_TOKEN|.*PASSWORD.*|.*SECRET.*)$")
)
func Submatches(pattern *regexp.Regexp, value string) string {
if matches := pattern.FindStringSubmatchIndex(value); len(matches) > 2 {
for i := len(matches) - 2; i > 1; i -= 2 {
start := matches[i]
end := matches[i+1]
value = value[0:start] + maskReplacement + value[end:]
}
}
return value
}