go.temporal.io/server/common/masker/masker.go
83 LOC · 45 covered · 38 uncovered · 12 ranges · 46 concepts · 4 introducers · 14 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package masker
import (
"reflect"
"gopkg.in/yaml.v3"
)
const passwordMask = "******"
var (
DefaultFieldNames = []string{"Password", "KeyData"}
DefaultYAMLFieldNames = []string{"password", "keyData"}
)
// MaskYaml replace password values with mask and returns copy of the string.
// Does recursive replacement for entire yamlStr.
fns := make(map[string]struct{}, len(fieldNamesToMask))
for _, fieldName := range fieldNamesToMask {
fns[fieldName] = struct{}{}
}
err := yaml.Unmarshal([]byte(yamlStr), &parsedYaml)
if err != nil {
return yamlStr, err
}
strBytes, err := yaml.Marshal(parsedYaml)
if err != nil {
return yamlStr, err
}
}
// MaskStruct replace password values with mask and returns copy of the strct.
// Original strct value is not modified. Doesn't go recursively through strct properties.
strctV := reflect.ValueOf(strct)
if strct == nil || (strctV.Kind() == reflect.Pointer && strctV.IsNil()) {
}
strctV = strctV.Elem()
}
// strctV is not a pointer now. Create a copy using assignment.
strctCopyPV := pointerTo(strctCopy)
strctCopyV := strctCopyPV.Elem()
for _, passwordFieldName := range fieldNamesToMask {
passwordF := strctCopyV.FieldByName(passwordFieldName)
if passwordF.CanSet() && passwordF.Kind() == reflect.String {
passwordF.SetString(passwordMask)
}
}
}
valPtr := reflect.New(reflect.TypeOf(val))
valPtr.Elem().Set(reflect.ValueOf(val))
return valPtr
}
for key, value := range m {
if _, ok := fns[key]; ok {
m[key] = passwordMask
}
maskMap(valueMap, fns)
}
}
}