-
Notifications
You must be signed in to change notification settings - Fork 2
/
configuration.go
59 lines (52 loc) · 1.39 KB
/
configuration.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
57
58
59
package treblle
var Config internalConfiguration
// Configuration sets up and customizes communication with the Treblle API
type Configuration struct {
APIKey string
ProjectID string
AdditionalFieldsToMask []string
}
// internalConfiguration is used for communication with Treblle API and contains optimizations
type internalConfiguration struct {
Configuration
FieldsMap map[string]bool
serverInfo ServerInfo
languageInfo LanguageInfo
Debug bool
}
func Configure(config Configuration) {
if config.APIKey != "" {
Config.APIKey = config.APIKey
}
if config.ProjectID != "" {
Config.ProjectID = config.ProjectID
}
if len(config.AdditionalFieldsToMask) > 0 {
Config.AdditionalFieldsToMask = config.AdditionalFieldsToMask
}
Config.FieldsMap = generateFieldsToMask(Config.AdditionalFieldsToMask)
Config.serverInfo = getServerInfo()
Config.languageInfo = getLanguageInfo()
}
func generateFieldsToMask(additionalFieldsToMask []string) map[string]bool {
defaultFieldsToMask := []string{
"password",
"pwd",
"secret",
"password_confirmation",
"passwordConfirmation",
"cc",
"card_number",
"cardNumber",
"ccv",
"ssn",
"credit_score",
"creditScore",
}
fields := append(defaultFieldsToMask, additionalFieldsToMask...)
fieldsToMask := make(map[string]bool)
for _, field := range fields {
fieldsToMask[field] = true
}
return fieldsToMask
}