Documentation ¶
Overview ¶
Package configopaque implements String type alias to mask sensitive information. Use configopaque.String on the type of sensitive fields, to mask the opaque string as `[REDACTED]`.
This ensure that no sensitive information is leaked when printing the full Collector configurations.
Example (OpaqueMap) ¶
cfg := &ExampleConfigMap{ Censored: map[string]configopaque.String{ "token": "sensitivetoken", }, Uncensored: map[string]string{ "key": "cloud.zone", "value": "zone-1", }, } // yaml marshaling bytes, err := yaml.Marshal(cfg) if err != nil { panic(err) } fmt.Printf("encoded cfg (YAML) is:\n%s\n\n", string(bytes))
Output: encoded cfg (YAML) is: censored: token: '[REDACTED]' uncensored: key: cloud.zone value: zone-1
Example (OpaqueSlice) ¶
package main import ( "encoding/json" "fmt" "go.opentelemetry.io/collector/config/configopaque" ) func main() { cfg := &ExampleConfigSlice{ Censored: []configopaque.String{"data", "is", "sensitive"}, Uncensored: []string{"data", "is", "not", "sensitive"}, } // JSON marshaling bytes, err := json.MarshalIndent(cfg, "", " ") if err != nil { panic(err) } fmt.Printf("encoded cfg (JSON) is\n%s\n\n", string(bytes)) } type ExampleConfigSlice struct { Censored []configopaque.String Uncensored []string }
Output: encoded cfg (JSON) is { "Censored": [ "[REDACTED]", "[REDACTED]", "[REDACTED]" ], "Uncensored": [ "data", "is", "not", "sensitive" ] }
Example (OpaqueString) ¶
rawBytes := []byte(`{ "Censored": "sensitive", "Uncensored": "not sensitive" }`) // JSON unmarshaling var cfg ExampleConfigString err := json.Unmarshal(rawBytes, &cfg) if err != nil { panic(err) } // YAML marshaling bytes, err := yaml.Marshal(cfg) if err != nil { panic(err) } fmt.Printf("encoded cfg (YAML) is:\n%s\n\n", string(bytes))
Output: encoded cfg (YAML) is: censored: '[REDACTED]' uncensored: not sensitive
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.