github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/settings/masked.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package settings 12 13 // MaskedSetting is a pseudo-variable constructed on-the-fly by Lookup 14 // when the actual setting is non-reportable. 15 type MaskedSetting struct { 16 setting WritableSetting 17 } 18 19 var _ Setting = &MaskedSetting{} 20 21 // UnderlyingSetting retrieves the actual setting object. 22 func (s *MaskedSetting) UnderlyingSetting() WritableSetting { 23 return s.setting 24 } 25 26 // String hides the underlying value. 27 func (s *MaskedSetting) String(sv *Values) string { 28 // Special case for non-reportable strings: we still want 29 // to distinguish empty from non-empty (= customized). 30 if st, ok := s.UnderlyingSetting().(*StringSetting); ok && st.String(sv) == "" { 31 return "" 32 } 33 return "<redacted>" 34 } 35 36 // Visibility returns the visibility setting for the underlying setting. 37 func (s *MaskedSetting) Visibility() Visibility { 38 return s.setting.Visibility() 39 } 40 41 // Description returns the description string for the underlying setting. 42 func (s *MaskedSetting) Description() string { 43 return s.setting.Description() 44 } 45 46 // Typ returns the short (1 char) string denoting the type of setting. 47 func (s *MaskedSetting) Typ() string { 48 return s.setting.Typ() 49 }