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
|
|
|
|
2016-06-10 06:07:23 -04:00
|
|
|
// AddTrustedFlags adds content trust flags to the current command flagset
|
2016-05-31 19:49:32 -04:00
|
|
|
func AddTrustedFlags(fs *pflag.FlagSet, verify bool) {
|
|
|
|
trusted, message := setupTrustedFlag(verify)
|
|
|
|
fs.BoolVar(&untrusted, "disable-content-trust", !trusted, message)
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupTrustedFlag(verify bool) (bool, string) {
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
message := "Skip image signing"
|
|
|
|
if verify {
|
|
|
|
message = "Skip image verification"
|
|
|
|
}
|
2016-05-31 19:49:32 -04:00
|
|
|
return trusted, message
|
2015-07-15 16:42:45 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 01:19:13 -04:00
|
|
|
// IsTrusted returns true if content trust is enabled
|
|
|
|
func IsTrusted() bool {
|
2015-07-15 16:42:45 -04:00
|
|
|
return !untrusted
|
|
|
|
}
|