config.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2016 The Prometheus Authors
  2. // Licensed under the Apache License, Version 2.0 (the "License");
  3. // you may not use this file except in compliance with the License.
  4. // You may obtain a copy of the License at
  5. //
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. package config
  14. import (
  15. "fmt"
  16. "strings"
  17. )
  18. func checkOverflow(m map[string]interface{}, ctx string) error {
  19. if len(m) > 0 {
  20. var keys []string
  21. for k := range m {
  22. keys = append(keys, k)
  23. }
  24. return fmt.Errorf("unknown fields in %s: %s", ctx, strings.Join(keys, ", "))
  25. }
  26. return nil
  27. }
  28. // Secret special type for storing secrets.
  29. type Secret string
  30. // MarshalYAML implements the yaml.Marshaler interface for Secrets.
  31. func (s Secret) MarshalYAML() (interface{}, error) {
  32. if s != "" {
  33. return "<secret>", nil
  34. }
  35. return nil, nil
  36. }
  37. //UnmarshalYAML implements the yaml.Unmarshaler interface for Secrets.
  38. func (s *Secret) UnmarshalYAML(unmarshal func(interface{}) error) error {
  39. type plain Secret
  40. return unmarshal((*plain)(s))
  41. }