github.com/fabiokung/docker@v0.11.2-0.20170222101415-4534dcd49497/cli/command/trust.go (about) 1 package command 2 3 import ( 4 "os" 5 "strconv" 6 7 "github.com/spf13/pflag" 8 ) 9 10 var ( 11 // TODO: make this not global 12 untrusted bool 13 ) 14 15 // AddTrustVerificationFlags adds content trust flags to the provided flagset 16 func AddTrustVerificationFlags(fs *pflag.FlagSet) { 17 trusted := getDefaultTrustState() 18 fs.BoolVar(&untrusted, "disable-content-trust", !trusted, "Skip image verification") 19 } 20 21 // AddTrustSigningFlags adds "signing" flags to the provided flagset 22 func AddTrustSigningFlags(fs *pflag.FlagSet) { 23 trusted := getDefaultTrustState() 24 fs.BoolVar(&untrusted, "disable-content-trust", !trusted, "Skip image signing") 25 } 26 27 // getDefaultTrustState returns true if content trust is enabled through the $DOCKER_CONTENT_TRUST environment variable. 28 func getDefaultTrustState() bool { 29 var trusted bool 30 if e := os.Getenv("DOCKER_CONTENT_TRUST"); e != "" { 31 if t, err := strconv.ParseBool(e); t || err != nil { 32 // treat any other value as true 33 trusted = true 34 } 35 } 36 return trusted 37 } 38 39 // IsTrusted returns true if content trust is enabled, either through the $DOCKER_CONTENT_TRUST environment variable, 40 // or through `--disabled-content-trust=false` on a command. 41 func IsTrusted() bool { 42 return !untrusted 43 }