2016-09-08 13:11:39 -04:00
|
|
|
package command
|
2015-07-15 16:42:45 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
|
2016-05-31 19:49:32 -04:00
|
|
|
"github.com/spf13/pflag"
|
2015-07-15 16:42:45 -04:00
|
|
|
)
|
|
|
|
|
2015-12-18 21:47:35 -05:00
|
|
|
var (
|
2016-08-29 14:45:29 -04:00
|
|
|
// TODO: make this not global
|
|
|
|
untrusted bool
|
2015-12-18 21:47:35 -05:00
|
|
|
)
|
2015-07-15 16:42:45 -04:00
|
|
|
|
2017-01-17 09:46:07 -05:00
|
|
|
// AddTrustVerificationFlags adds content trust flags to the provided flagset
|
|
|
|
func AddTrustVerificationFlags(fs *pflag.FlagSet) {
|
|
|
|
trusted := getDefaultTrustState()
|
|
|
|
fs.BoolVar(&untrusted, "disable-content-trust", !trusted, "Skip image verification")
|
2016-05-31 19:49:32 -04:00
|
|
|
}
|
|
|
|
|
2017-01-17 09:46:07 -05:00
|
|
|
// AddTrustSigningFlags adds "signing" flags to the provided flagset
|
|
|
|
func AddTrustSigningFlags(fs *pflag.FlagSet) {
|
|
|
|
trusted := getDefaultTrustState()
|
|
|
|
fs.BoolVar(&untrusted, "disable-content-trust", !trusted, "Skip image signing")
|
|
|
|
}
|
|
|
|
|
|
|
|
// getDefaultTrustState returns true if content trust is enabled through the $DOCKER_CONTENT_TRUST environment variable.
|
|
|
|
func getDefaultTrustState() bool {
|
2015-07-15 16:42:45 -04:00
|
|
|
var trusted bool
|
2015-07-24 04:59:42 -04:00
|
|
|
if e := os.Getenv("DOCKER_CONTENT_TRUST"); e != "" {
|
2015-07-15 16:42:45 -04:00
|
|
|
if t, err := strconv.ParseBool(e); t || err != nil {
|
|
|
|
// treat any other value as true
|
|
|
|
trusted = true
|
|
|
|
}
|
|
|
|
}
|
2017-01-17 09:46:07 -05:00
|
|
|
return trusted
|
2015-07-15 16:42:45 -04:00
|
|
|
}
|
|
|
|
|
2017-01-17 09:46:07 -05:00
|
|
|
// IsTrusted returns true if content trust is enabled, either through the $DOCKER_CONTENT_TRUST environment variable,
|
|
|
|
// or through `--disabled-content-trust=false` on a command.
|
2016-06-01 01:19:13 -04:00
|
|
|
func IsTrusted() bool {
|
2015-07-15 16:42:45 -04:00
|
|
|
return !untrusted
|
|
|
|
}
|