Skip to content

Commit ef3c19a

Browse files
authored
Merge pull request #6494 from thaJeztah/deprecate_ContentTrustEnabled
cli/command: deprecate DockerCli.ContentTrustEnabled
2 parents 734328e + 11d4048 commit ef3c19a

File tree

15 files changed

+34
-24
lines changed

15 files changed

+34
-24
lines changed

cli/command/cli.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ type Cli interface {
4848
config.Provider
4949
ServerInfo() ServerInfo
5050
CurrentVersion() string
51-
ContentTrustEnabled() bool
5251
BuildKitEnabled() (bool, error)
5352
ContextStore() store.Store
5453
CurrentContext() string
@@ -160,6 +159,8 @@ func (cli *DockerCli) ServerInfo() ServerInfo {
160159

161160
// ContentTrustEnabled returns whether content trust has been enabled by an
162161
// environment variable.
162+
//
163+
// Deprecated: check the value of the DOCKER_CONTENT_TRUST environment variable to detect whether content-trust is enabled.
163164
func (cli *DockerCli) ContentTrustEnabled() bool {
164165
return cli.contentTrust
165166
}

cli/command/container/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
9090
addPlatformFlag(flags, &options.platform)
9191
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms())
9292

93-
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCLI.ContentTrustEnabled(), "Skip image verification")
93+
flags.BoolVar(&options.untrusted, "disable-content-trust", !trust.Enabled(), "Skip image verification")
9494
copts = addFlags(flags)
9595

9696
addCompletions(cmd, dockerCLI)

cli/command/container/create_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ func TestNewCreateCommandWithContentTrustErrors(t *testing.T) {
249249
}
250250
for _, tc := range testCases {
251251
t.Run(tc.name, func(t *testing.T) {
252+
t.Setenv("DOCKER_CONTENT_TRUST", "true")
252253
fakeCLI := test.NewFakeCli(&fakeClient{
253254
createContainerFunc: func(config *container.Config,
254255
hostConfig *container.HostConfig,
@@ -258,7 +259,7 @@ func TestNewCreateCommandWithContentTrustErrors(t *testing.T) {
258259
) (container.CreateResponse, error) {
259260
return container.CreateResponse{}, errors.New("shouldn't try to pull image")
260261
},
261-
}, test.EnableContentTrust)
262+
})
262263
fakeCLI.SetNotaryClient(tc.notaryFunc)
263264
cmd := newCreateCommand(fakeCLI)
264265
cmd.SetOut(io.Discard)

cli/command/container/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/docker/cli/cli"
1212
"github.com/docker/cli/cli/command"
1313
"github.com/docker/cli/cli/command/completion"
14+
"github.com/docker/cli/cli/trust"
1415
"github.com/docker/cli/opts"
1516
"github.com/moby/moby/api/types/container"
1617
"github.com/moby/moby/client"
@@ -70,7 +71,7 @@ func newRunCommand(dockerCLI command.Cli) *cobra.Command {
7071

7172
// TODO(thaJeztah): consider adding platform as "image create option" on containerOptions
7273
addPlatformFlag(flags, &options.platform)
73-
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCLI.ContentTrustEnabled(), "Skip image verification")
74+
flags.BoolVar(&options.untrusted, "disable-content-trust", !trust.Enabled(), "Skip image verification")
7475
copts = addFlags(flags)
7576

7677
_ = cmd.RegisterFlagCompletionFunc("detach-keys", completeDetachKeys)

cli/command/container/run_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ func TestRunCommandWithContentTrustErrors(t *testing.T) {
323323
}
324324
for _, tc := range testCases {
325325
t.Run(tc.name, func(t *testing.T) {
326+
t.Setenv("DOCKER_CONTENT_TRUST", "true")
326327
fakeCLI := test.NewFakeCli(&fakeClient{
327328
createContainerFunc: func(config *container.Config,
328329
hostConfig *container.HostConfig,
@@ -332,7 +333,7 @@ func TestRunCommandWithContentTrustErrors(t *testing.T) {
332333
) (container.CreateResponse, error) {
333334
return container.CreateResponse{}, errors.New("shouldn't try to pull image")
334335
},
335-
}, test.EnableContentTrust)
336+
})
336337
fakeCLI.SetNotaryClient(tc.notaryFunc)
337338
cmd := newRunCommand(fakeCLI)
338339
cmd.SetArgs(tc.args)

cli/command/image/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func newBuildCommand(dockerCLI command.Cli) *cobra.Command {
147147
flags.SetAnnotation("target", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#target"})
148148
flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file")
149149

150-
flags.Bool("disable-content-trust", dockerCLI.ContentTrustEnabled(), "Skip image verification (deprecated)")
150+
flags.Bool("disable-content-trust", true, "Skip image verification (deprecated)")
151151
_ = flags.MarkHidden("disable-content-trust")
152152

153153
flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")

cli/command/image/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func newPullCommand(dockerCLI command.Cli) *cobra.Command {
5050
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output")
5151

5252
addPlatformFlag(flags, &opts.platform)
53-
flags.BoolVar(&opts.untrusted, "disable-content-trust", !dockerCLI.ContentTrustEnabled(), "Skip image verification")
53+
flags.BoolVar(&opts.untrusted, "disable-content-trust", !trust.Enabled(), "Skip image verification")
5454

5555
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms())
5656

cli/command/image/pull_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ func TestNewPullCommandWithContentTrustErrors(t *testing.T) {
118118
}
119119
for _, tc := range testCases {
120120
t.Run(tc.name, func(t *testing.T) {
121+
t.Setenv("DOCKER_CONTENT_TRUST", "true")
121122
cli := test.NewFakeCli(&fakeClient{
122123
imagePullFunc: func(ref string, options client.ImagePullOptions) (io.ReadCloser, error) {
123124
return io.NopCloser(strings.NewReader("")), errors.New("shouldn't try to pull image")
124125
},
125-
}, test.EnableContentTrust)
126+
})
126127
cli.SetNotaryClient(tc.notaryFunc)
127128
cmd := newPullCommand(cli)
128129
cmd.SetOut(io.Discard)

cli/command/image/push.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/docker/cli/cli/command"
1717
"github.com/docker/cli/cli/command/completion"
1818
"github.com/docker/cli/cli/streams"
19+
"github.com/docker/cli/cli/trust"
1920
"github.com/docker/cli/internal/jsonstream"
2021
"github.com/docker/cli/internal/registry"
2122
"github.com/docker/cli/internal/tui"
@@ -58,7 +59,7 @@ func newPushCommand(dockerCLI command.Cli) *cobra.Command {
5859
flags := cmd.Flags()
5960
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Push all tags of an image to the repository")
6061
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output")
61-
flags.BoolVar(&opts.untrusted, "disable-content-trust", !dockerCLI.ContentTrustEnabled(), "Skip image signing")
62+
flags.BoolVar(&opts.untrusted, "disable-content-trust", !trust.Enabled(), "Skip image signing")
6263

6364
// Don't default to DOCKER_DEFAULT_PLATFORM env variable, always default to
6465
// pushing the image as-is. This also avoids forcing the platform selection

cli/command/plugin/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func newInstallCommand(dockerCLI command.Cli) *cobra.Command {
4444
flags.BoolVar(&options.grantPerms, "grant-all-permissions", false, "Grant all permissions necessary to run the plugin")
4545
flags.BoolVar(&options.disable, "disable", false, "Do not enable the plugin on install")
4646
flags.StringVar(&options.localName, "alias", "", "Local name for plugin")
47-
flags.Bool("disable-content-trust", dockerCLI.ContentTrustEnabled(), "Skip image verification (deprecated)")
47+
flags.Bool("disable-content-trust", true, "Skip image verification (deprecated)")
4848
_ = flags.MarkHidden("disable-content-trust")
4949
return cmd
5050
}

0 commit comments

Comments
 (0)