trust.go 830 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package command
  2. import (
  3. "os"
  4. "strconv"
  5. "github.com/spf13/pflag"
  6. )
  7. var (
  8. // TODO: make this not global
  9. untrusted bool
  10. )
  11. // AddTrustedFlags adds content trust flags to the current command flagset
  12. func AddTrustedFlags(fs *pflag.FlagSet, verify bool) {
  13. trusted, message := setupTrustedFlag(verify)
  14. fs.BoolVar(&untrusted, "disable-content-trust", !trusted, message)
  15. }
  16. func setupTrustedFlag(verify bool) (bool, string) {
  17. var trusted bool
  18. if e := os.Getenv("DOCKER_CONTENT_TRUST"); e != "" {
  19. if t, err := strconv.ParseBool(e); t || err != nil {
  20. // treat any other value as true
  21. trusted = true
  22. }
  23. }
  24. message := "Skip image signing"
  25. if verify {
  26. message = "Skip image verification"
  27. }
  28. return trusted, message
  29. }
  30. // IsTrusted returns true if content trust is enabled
  31. func IsTrusted() bool {
  32. return !untrusted
  33. }