-
Notifications
You must be signed in to change notification settings - Fork 307
/
admin.go
89 lines (78 loc) · 2.7 KB
/
admin.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package backendconfig
import (
"encoding/json"
"fmt"
"reflect"
"strings"
)
// admin is container object to expose admin functions
type admin struct{}
// RoutingConfig reports current backend config and process config after masking secret fields
func (bca *admin) RoutingConfig(filterProcessor bool, reply *string) (err error) { // skipcq: RVV-A0005
defer func() {
if r := recover(); r != nil {
pkgLogger.Error(r)
err = fmt.Errorf("internal Rudder server error: %v", r)
}
}()
outputJSON := getConfig()
if filterProcessor {
outputJSON = filterProcessorEnabledDestinations(outputJSON)
}
outputObj := make([]interface{}, 0)
for _, source := range outputJSON.Sources {
destinations := make([]interface{}, 0)
for _, destination := range source.Destinations { // TODO skipcq: CRT-P0006
destinationConfigCopy := make(map[string]interface{})
for k, v := range destination.Config {
destinationConfigCopy[k] = v
}
// Mask secret config fields by replacing latter 2/3rd of the field with 'x's
destinationSecretKeys, ok := destination.DestinationDefinition.Config["secretKeys"]
if !ok {
destinationSecretKeys = []interface{}{}
}
rt := reflect.TypeOf(destinationSecretKeys)
switch rt.Kind() {
case reflect.Array:
case reflect.Slice:
default:
return fmt.Errorf("secretKeys field of destination definition config is not an array. Destination definition name: %s", destination.DestinationDefinition.DisplayName)
}
for _, k := range destinationSecretKeys.([]interface{}) {
secretKey := k.(string)
secret, ok := destinationConfigCopy[secretKey]
if ok {
switch v := secret.(type) {
case string:
s := secret.(string)
mask := strings.Repeat("x", (len(s)*2)/3)
destinationConfigCopy[secretKey] = s[0:len(s)-len(mask)] + mask
default:
return fmt.Errorf("I don't know how to handle secret config field of type %T", v)
}
}
}
destinations = append(destinations, map[string]interface{}{
"name": destination.Name,
"enabled": destination.Enabled,
"processor-enabled": destination.IsProcessorEnabled,
"id": destination.ID,
"config": destinationConfigCopy,
"type": destination.DestinationDefinition.DisplayName,
})
}
outputObj = append(outputObj, map[string]interface{}{
"name": source.Name,
"config": source.Config,
"writekey": source.WriteKey,
"id": source.ID,
"enabled": source.Enabled,
"destinations": destinations,
"type": source.SourceDefinition.Name,
})
}
formattedOutput, err := json.MarshalIndent(outputObj, "", " ")
*reply = string(formattedOutput)
return err
}