validate.go 961 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package cache
  2. import (
  3. "strconv"
  4. "github.com/docker/docker/daemon/logger"
  5. "github.com/docker/docker/daemon/logger/local"
  6. "github.com/pkg/errors"
  7. )
  8. func init() {
  9. for k, v := range local.LogOptKeys {
  10. builtInCacheLogOpts[cachePrefix+k] = v
  11. }
  12. logger.AddBuiltinLogOpts(builtInCacheLogOpts)
  13. logger.RegisterExternalValidator(validateLogCacheOpts)
  14. }
  15. func validateLogCacheOpts(cfg map[string]string) error {
  16. if v := cfg[cacheDisabledKey]; v != "" {
  17. _, err := strconv.ParseBool(v)
  18. if err != nil {
  19. return errors.Errorf("invalid value for option %s: %s", cacheDisabledKey, cfg[cacheDisabledKey])
  20. }
  21. }
  22. return nil
  23. }
  24. // MergeDefaultLogConfig reads the default log opts and makes sure that any caching related keys that exist there are
  25. // added to dst.
  26. func MergeDefaultLogConfig(dst, defaults map[string]string) {
  27. for k, v := range defaults {
  28. if !builtInCacheLogOpts[k] {
  29. continue
  30. }
  31. if _, exists := dst[k]; !exists {
  32. dst[k] = v
  33. }
  34. }
  35. }