forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trust.go
39 lines (33 loc) · 830 Bytes
/
trust.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package command
import (
"os"
"strconv"
"github.com/spf13/pflag"
)
var (
// TODO: make this not global
untrusted bool
)
// AddTrustedFlags adds content trust flags to the current command flagset
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) {
var trusted bool
if e := os.Getenv("DOCKER_CONTENT_TRUST"); e != "" {
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"
}
return trusted, message
}
// IsTrusted returns true if content trust is enabled
func IsTrusted() bool {
return !untrusted
}