github.com/thanos-io/thanos@v0.32.5/internal/cortex/util/flagext/secret.go (about) 1 // Copyright (c) The Cortex Authors. 2 // Licensed under the Apache License 2.0. 3 4 package flagext 5 6 type Secret struct { 7 Value string 8 } 9 10 // String implements flag.Value 11 func (v Secret) String() string { 12 return v.Value 13 } 14 15 // Set implements flag.Value 16 func (v *Secret) Set(s string) error { 17 v.Value = s 18 return nil 19 } 20 21 // UnmarshalYAML implements yaml.Unmarshaler. 22 func (v *Secret) UnmarshalYAML(unmarshal func(interface{}) error) error { 23 var s string 24 if err := unmarshal(&s); err != nil { 25 return err 26 } 27 28 return v.Set(s) 29 } 30 31 // MarshalYAML implements yaml.Marshaler. 32 func (v Secret) MarshalYAML() (interface{}, error) { 33 if len(v.Value) == 0 { 34 return "", nil 35 } 36 return "********", nil 37 }