Skip to content

Commit 8def226

Browse files
committed
cli/command/image: deprecate AuthResolver and un-export
This function was exported to share it between "trust" and "image", but was only a shallow wrapper, so split the implementations where used. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 7ad113c) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent bb2ed91 commit 8def226

File tree

7 files changed

+28
-16
lines changed

7 files changed

+28
-16
lines changed

cli/command/image/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func runPull(ctx context.Context, dockerCLI command.Cli, opts pullOptions) error
8585
}
8686
}
8787

88-
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(dockerCLI), distributionRef.String())
88+
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, authResolver(dockerCLI), distributionRef.String())
8989
if err != nil {
9090
return err
9191
}

cli/command/image/trust.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/distribution/reference"
1010
"github.com/docker/cli/cli/command"
11+
"github.com/docker/cli/cli/config"
1112
"github.com/docker/cli/cli/streams"
1213
"github.com/docker/cli/cli/trust"
1314
"github.com/docker/cli/internal/jsonstream"
@@ -68,7 +69,7 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image
6869
if err != nil {
6970
return err
7071
}
71-
updatedImgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(cli), trustedRef.String())
72+
updatedImgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, authResolver(cli), trustedRef.String())
7273
if err != nil {
7374
return err
7475
}
@@ -172,7 +173,7 @@ func imagePullPrivileged(ctx context.Context, cli command.Cli, imgRefAndAuth tru
172173

173174
// TrustedReference returns the canonical trusted reference for an image reference
174175
func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedTagged) (reference.Canonical, error) {
175-
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(cli), ref.String())
176+
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, authResolver(cli), ref.String())
176177
if err != nil {
177178
return nil, err
178179
}
@@ -210,9 +211,16 @@ func convertTarget(t client.Target) (target, error) {
210211
}, nil
211212
}
212213

213-
// AuthResolver returns an auth resolver function from a command.Cli
214-
func AuthResolver(cli command.Cli) func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
214+
// AuthResolver returns an auth resolver function from a [config.Provider].
215+
//
216+
// Deprecated: this function was only used internally and will be removed in the next release.
217+
func AuthResolver(dockerCLI config.Provider) func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
218+
return authResolver(dockerCLI)
219+
}
220+
221+
// authResolver returns an auth resolver function from a [config.Provider].
222+
func authResolver(dockerCLI config.Provider) func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
215223
return func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
216-
return command.ResolveAuthConfig(cli.ConfigFile(), index)
224+
return command.ResolveAuthConfig(dockerCLI.ConfigFile(), index)
217225
}
218226
}

cli/command/trust/common.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import (
88
"strings"
99

1010
"github.com/docker/cli/cli/command"
11-
"github.com/docker/cli/cli/command/image"
11+
"github.com/docker/cli/cli/config"
1212
"github.com/docker/cli/cli/trust"
13+
registrytypes "github.com/docker/docker/api/types/registry"
1314
"github.com/fvbommel/sortorder"
1415
"github.com/sirupsen/logrus"
1516
"github.com/theupdateframework/notary"
@@ -66,7 +67,7 @@ func newNotaryClient(cli command.Streams, imgRefAndAuth trust.ImageRefAndAuth, a
6667
// lookupTrustInfo returns processed signature and role information about a notary repository.
6768
// This information is to be pretty printed or serialized into a machine-readable format.
6869
func lookupTrustInfo(ctx context.Context, cli command.Cli, remote string) ([]trustTagRow, []client.RoleWithSignatures, []data.Role, error) {
69-
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, image.AuthResolver(cli), remote)
70+
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, authResolver(cli), remote)
7071
if err != nil {
7172
return []trustTagRow{}, []client.RoleWithSignatures{}, []data.Role{}, err
7273
}
@@ -167,3 +168,10 @@ func matchReleasedSignatures(allTargets []client.TargetSignedStruct) []trustTagR
167168
})
168169
return signatureRows
169170
}
171+
172+
// authResolver returns an auth resolver function from a [config.Provider].
173+
func authResolver(dockerCLI config.Provider) func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
174+
return func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
175+
return command.ResolveAuthConfig(dockerCLI.ConfigFile(), index)
176+
}
177+
}

cli/command/trust/revoke.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/docker/cli/cli"
88
"github.com/docker/cli/cli/command"
9-
"github.com/docker/cli/cli/command/image"
109
"github.com/docker/cli/cli/trust"
1110
"github.com/docker/cli/internal/prompt"
1211
"github.com/pkg/errors"
@@ -35,7 +34,7 @@ func newRevokeCommand(dockerCLI command.Cli) *cobra.Command {
3534
}
3635

3736
func revokeTrust(ctx context.Context, dockerCLI command.Cli, remote string, options revokeOptions) error {
38-
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, image.AuthResolver(dockerCLI), remote)
37+
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, authResolver(dockerCLI), remote)
3938
if err != nil {
4039
return err
4140
}

cli/command/trust/sign.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/distribution/reference"
1212
"github.com/docker/cli/cli"
1313
"github.com/docker/cli/cli/command"
14-
"github.com/docker/cli/cli/command/image"
1514
"github.com/docker/cli/cli/trust"
1615
imagetypes "github.com/docker/docker/api/types/image"
1716
registrytypes "github.com/docker/docker/api/types/registry"
@@ -45,7 +44,7 @@ func newSignCommand(dockerCLI command.Cli) *cobra.Command {
4544

4645
func runSignImage(ctx context.Context, dockerCLI command.Cli, options signOptions) error {
4746
imageName := options.imageName
48-
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, image.AuthResolver(dockerCLI), imageName)
47+
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, authResolver(dockerCLI), imageName)
4948
if err != nil {
5049
return err
5150
}

cli/command/trust/signer_add.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/docker/cli/cli"
1212
"github.com/docker/cli/cli/command"
13-
"github.com/docker/cli/cli/command/image"
1413
"github.com/docker/cli/cli/trust"
1514
"github.com/docker/cli/internal/lazyregexp"
1615
"github.com/docker/cli/opts"
@@ -80,7 +79,7 @@ func addSigner(ctx context.Context, dockerCLI command.Cli, options signerAddOpti
8079
}
8180

8281
func addSignerToRepo(ctx context.Context, dockerCLI command.Cli, signerName string, repoName string, signerPubKeys []data.PublicKey) error {
83-
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, image.AuthResolver(dockerCLI), repoName)
82+
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, authResolver(dockerCLI), repoName)
8483
if err != nil {
8584
return err
8685
}

cli/command/trust/signer_remove.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/docker/cli/cli"
99
"github.com/docker/cli/cli/command"
10-
"github.com/docker/cli/cli/command/image"
1110
"github.com/docker/cli/cli/trust"
1211
"github.com/docker/cli/internal/prompt"
1312
"github.com/pkg/errors"
@@ -91,7 +90,7 @@ func maybePromptForSignerRemoval(ctx context.Context, dockerCLI command.Cli, rep
9190
// removeSingleSigner attempts to remove a single signer and returns whether signer removal happened.
9291
// The signer not being removed doesn't necessarily raise an error e.g. user choosing "No" when prompted for confirmation.
9392
func removeSingleSigner(ctx context.Context, dockerCLI command.Cli, repoName, signerName string, forceYes bool) (bool, error) {
94-
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, image.AuthResolver(dockerCLI), repoName)
93+
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, authResolver(dockerCLI), repoName)
9594
if err != nil {
9695
return false, err
9796
}

0 commit comments

Comments
 (0)