Skip to content

Commit f45dab0

Browse files
committed
cli/command/image: imagePullPrivileged: move to non-trust file
This function is a wrapper around apiClient.ImagePull and not directly related to docker content trust; it just happens to also be called when using content trust (through the trustedPull utility). Move it together with the `runPull` function to separate it from trust-related code. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent c97482f commit f45dab0

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

cli/command/image/pull.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"io"
78

89
"github.com/distribution/reference"
910
"github.com/docker/cli/cli"
1011
"github.com/docker/cli/cli/command"
1112
"github.com/docker/cli/cli/command/completion"
13+
"github.com/docker/cli/cli/streams"
1214
"github.com/docker/cli/cli/trust"
15+
"github.com/docker/cli/internal/jsonstream"
16+
"github.com/moby/moby/api/pkg/authconfig"
17+
registrytypes "github.com/moby/moby/api/types/registry"
18+
"github.com/moby/moby/client"
1319
"github.com/spf13/cobra"
1420
)
1521

@@ -91,3 +97,27 @@ func runPull(ctx context.Context, dockerCLI command.Cli, opts pullOptions) error
9197
_, _ = fmt.Fprintln(dockerCLI.Out(), imgRefAndAuth.Reference().String())
9298
return nil
9399
}
100+
101+
// imagePullPrivileged pulls the image and displays it to the output
102+
func imagePullPrivileged(ctx context.Context, dockerCLI command.Cli, ref reference.Named, authConfig *registrytypes.AuthConfig, opts pullOptions) error {
103+
encodedAuth, err := authconfig.Encode(*authConfig)
104+
if err != nil {
105+
return err
106+
}
107+
responseBody, err := dockerCLI.Client().ImagePull(ctx, reference.FamiliarString(ref), client.ImagePullOptions{
108+
RegistryAuth: encodedAuth,
109+
PrivilegeFunc: nil,
110+
All: opts.all,
111+
Platform: opts.platform,
112+
})
113+
if err != nil {
114+
return err
115+
}
116+
defer responseBody.Close()
117+
118+
out := dockerCLI.Out()
119+
if opts.quiet {
120+
out = streams.NewOut(io.Discard)
121+
}
122+
return jsonstream.Display(ctx, responseBody, out)
123+
}

cli/command/image/trust.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ import (
1010
"github.com/distribution/reference"
1111
"github.com/docker/cli/cli/command"
1212
"github.com/docker/cli/cli/config"
13-
"github.com/docker/cli/cli/streams"
1413
"github.com/docker/cli/cli/trust"
15-
"github.com/docker/cli/internal/jsonstream"
1614
"github.com/docker/cli/internal/registry"
17-
"github.com/moby/moby/api/pkg/authconfig"
1815
registrytypes "github.com/moby/moby/api/types/registry"
19-
"github.com/moby/moby/client"
2016
"github.com/opencontainers/go-digest"
2117
"github.com/sirupsen/logrus"
2218
notaryclient "github.com/theupdateframework/notary/client"
@@ -155,30 +151,6 @@ func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth)
155151
return []target{r}, err
156152
}
157153

158-
// imagePullPrivileged pulls the image and displays it to the output
159-
func imagePullPrivileged(ctx context.Context, cli command.Cli, ref reference.Named, authConfig *registrytypes.AuthConfig, opts pullOptions) error {
160-
encodedAuth, err := authconfig.Encode(*authConfig)
161-
if err != nil {
162-
return err
163-
}
164-
responseBody, err := cli.Client().ImagePull(ctx, reference.FamiliarString(ref), client.ImagePullOptions{
165-
RegistryAuth: encodedAuth,
166-
PrivilegeFunc: nil,
167-
All: opts.all,
168-
Platform: opts.platform,
169-
})
170-
if err != nil {
171-
return err
172-
}
173-
defer responseBody.Close()
174-
175-
out := cli.Out()
176-
if opts.quiet {
177-
out = streams.NewOut(io.Discard)
178-
}
179-
return jsonstream.Display(ctx, responseBody, out)
180-
}
181-
182154
// TrustedReference returns the canonical trusted reference for an image reference
183155
func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedTagged) (reference.Canonical, error) {
184156
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, authResolver(cli), ref.String())

0 commit comments

Comments
 (0)