| 1 | // Copyright The OpenTelemetry Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | package configopaque // import "go.opentelemetry.io/collector/config/configopaque" |
| 5 | |
| 6 | import ( |
| 7 | "fmt" |
| 8 | ) |
| 9 | |
| 10 | // String alias that is marshaled and printed in an opaque way. |
| 11 | // To recover the original value, cast it to a string. |
| 12 | type String string |
| 13 | |
| 14 | const maskedString = "[REDACTED]" |
| 15 | |
| 16 | // MarshalText marshals the string as `[REDACTED]`. |
| 17 | func (s String) MarshalText() ([]byte, error) { |
| 18 | return []byte(maskedString), nil |
| 19 | } |
| 20 | |
| 21 | // String formats the string as `[REDACTED]`. |
| 22 | // This is used for the %s and %q verbs. |
| 23 | func (s String) String() string { |
| 24 | return maskedString |
| 25 | } |
| 26 | |
| 27 | // GoString formats the string as `[REDACTED]`. |
| 28 | // This is used for the %#v verb. |
| 29 | func (s String) GoString() string { |
| 30 | return fmt.Sprintf("%#v", maskedString) |
| 31 | } |
| 32 | |
| 33 | // MarshalBinary marshals the string `[REDACTED]` as []byte. |
| 34 | func (s String) MarshalBinary() (text []byte, err error) { |
| 35 | return []byte(maskedString), nil |
| 36 | } |