Skip to content

Commit 2ef1b4e

Browse files
authored
Merge pull request #6495 from thaJeztah/28.x_backport_deprecate_ContentTrustEnabled
[28.x backport] cli/command: deprecate DockerCli.ContentTrustEnabled
2 parents bea31fc + 118548d commit 2ef1b4e

File tree

16 files changed

+39
-27
lines changed

16 files changed

+39
-27
lines changed

cli/command/cli.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ type Cli interface {
5050
ServerInfo() ServerInfo
5151
DefaultVersion() string
5252
CurrentVersion() string
53-
ContentTrustEnabled() bool
5453
BuildKitEnabled() (bool, error)
5554
ContextStore() store.Store
5655
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
@@ -96,7 +96,7 @@ func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
9696
addPlatformFlag(flags, &options.platform)
9797
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
9898

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

102102
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
@@ -10,6 +10,7 @@ import (
1010
"github.com/docker/cli/cli"
1111
"github.com/docker/cli/cli/command"
1212
"github.com/docker/cli/cli/command/completion"
13+
"github.com/docker/cli/cli/trust"
1314
"github.com/docker/cli/opts"
1415
"github.com/docker/docker/api/types/container"
1516
"github.com/moby/sys/signal"
@@ -74,7 +75,7 @@ func newRunCommand(dockerCLI command.Cli) *cobra.Command {
7475

7576
// TODO(thaJeztah): consider adding platform as "image create option" on containerOptions
7677
addPlatformFlag(flags, &options.platform)
77-
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCLI.ContentTrustEnabled(), "Skip image verification")
78+
flags.BoolVar(&options.untrusted, "disable-content-trust", !trust.Enabled(), "Skip image verification")
7879
copts = addFlags(flags)
7980

8081
_ = 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
@@ -151,7 +151,7 @@ func newBuildCommand(dockerCli command.Cli) *cobra.Command {
151151
flags.SetAnnotation("target", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#target"})
152152
flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file")
153153

154-
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
154+
flags.BoolVar(&options.untrusted, "disable-content-trust", !trust.Enabled(), "Skip image verification")
155155

156156
flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
157157
flags.SetAnnotation("platform", "version", []string{"1.38"})

cli/command/image/pull.go

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

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

6161
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
6262

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 image.PullOptions) (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
@@ -15,6 +15,7 @@ import (
1515
"github.com/docker/cli/cli/command"
1616
"github.com/docker/cli/cli/command/completion"
1717
"github.com/docker/cli/cli/streams"
18+
"github.com/docker/cli/cli/trust"
1819
"github.com/docker/cli/internal/jsonstream"
1920
"github.com/docker/cli/internal/registry"
2021
"github.com/docker/cli/internal/tui"
@@ -64,7 +65,7 @@ func newPushCommand(dockerCLI command.Cli) *cobra.Command {
6465
flags := cmd.Flags()
6566
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Push all tags of an image to the repository")
6667
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output")
67-
flags.BoolVar(&opts.untrusted, "disable-content-trust", !dockerCLI.ContentTrustEnabled(), "Skip image signing")
68+
flags.BoolVar(&opts.untrusted, "disable-content-trust", !trust.Enabled(), "Skip image signing")
6869

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

cli/command/plugin/install.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/docker/cli/cli"
99
"github.com/docker/cli/cli/command"
1010
"github.com/docker/cli/cli/command/image"
11+
"github.com/docker/cli/cli/trust"
1112
"github.com/docker/cli/internal/jsonstream"
1213
"github.com/docker/cli/internal/prompt"
1314
"github.com/docker/cli/internal/registry"
@@ -28,9 +29,9 @@ type pluginOptions struct {
2829
untrusted bool
2930
}
3031

31-
func loadPullFlags(dockerCli command.Cli, opts *pluginOptions, flags *pflag.FlagSet) {
32+
func loadPullFlags(opts *pluginOptions, flags *pflag.FlagSet) {
3233
flags.BoolVar(&opts.grantPerms, "grant-all-permissions", false, "Grant all permissions necessary to run the plugin")
33-
flags.BoolVar(&opts.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
34+
flags.BoolVar(&opts.untrusted, "disable-content-trust", !trust.Enabled(), "Skip image verification")
3435
}
3536

3637
func newInstallCommand(dockerCli command.Cli) *cobra.Command {
@@ -49,7 +50,7 @@ func newInstallCommand(dockerCli command.Cli) *cobra.Command {
4950
}
5051

5152
flags := cmd.Flags()
52-
loadPullFlags(dockerCli, &options, flags)
53+
loadPullFlags(&options, flags)
5354
flags.BoolVar(&options.disable, "disable", false, "Do not enable the plugin on install")
5455
flags.StringVar(&options.localName, "alias", "", "Local name for plugin")
5556
return cmd

0 commit comments

Comments
 (0)