-
Notifications
You must be signed in to change notification settings - Fork 7
/
helpers.go
56 lines (46 loc) · 1.05 KB
/
helpers.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package secret
import (
"fmt"
"strings"
)
func (p *Printer) printOnlykeys(secrets map[string]interface{}) map[string]interface{} {
res := map[string]interface{}{}
for k, v := range secrets {
m, ok := v.(map[string]interface{})
if ok {
res[k] = p.printOnlykeys(m)
} else {
res[k] = ""
}
}
return res
}
func (p *Printer) printOnlyPaths(secrets map[string]interface{}) map[string]interface{} {
res := map[string]interface{}{}
for k, v := range secrets {
m, ok := v.(map[string]interface{})
if ok {
res[k] = p.printOnlyPaths(m)
} else {
res[k] = nil
}
}
return res
}
func (p *Printer) maskValues(secrets map[string]interface{}) map[string]interface{} {
res := map[string]interface{}{}
for k, v := range secrets {
m, ok := v.(map[string]interface{})
if ok {
res[k] = p.maskValues(m)
} else {
n := fmt.Sprintf("%v", v)
if len(n) > p.valueLength && p.valueLength != -1 {
secrets[k] = strings.Repeat(maskChar, p.valueLength)
} else {
secrets[k] = strings.Repeat(maskChar, len(n))
}
}
}
return secrets
}