-
Notifications
You must be signed in to change notification settings - Fork 0
/
envprivacy.go
45 lines (38 loc) · 921 Bytes
/
envprivacy.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
package main
import (
"fmt"
"os"
"strings"
)
const (
minLenForCensorHint = 5
)
func hiddenEnvVars() []string {
return strings.Split(os.Getenv(HideEnvVarsEnvVar), ":")
}
func censoredEnvVars() []string {
retv := strings.Split(os.Getenv(CensorEnvVarsEnvVar), ":")
retv = append(retv, SMTPPassEnvVar)
retv = append(retv, NtfyAccessTokenEnvVar)
return retv
}
func shouldHideEnvVar(varName string) bool {
return stringSliceContains(hiddenEnvVars(), varName)
}
func censoredEnvVarValue(varName, value string) string {
if !stringSliceContains(censoredEnvVars(), varName) {
return value
}
if len(value) < minLenForCensorHint {
return fmt.Sprintf("[%d chars]", len(value))
}
return fmt.Sprintf("%c[%d chars]%c", value[0], len(value)-2, value[len(value)-1])
}
func stringSliceContains(slice []string, value string) bool {
for _, v := range slice {
if v == value {
return true
}
}
return false
}