Skip to content

Commit 1d86522

Browse files
committed
cli/command/image: pushTrustedReference: internalize constructing indexInfo
All information needed can be deducted from the image reference, which is used to create a indexInfo, repoInfo, and to resolve auth-config. In some situations this may result in resolving the auth-config twice after it already was resolved to an encoded auth-config. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 183337d commit 1d86522

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

cli/command/image/push.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import (
1616
"github.com/docker/cli/cli/command/completion"
1717
"github.com/docker/cli/cli/streams"
1818
"github.com/docker/cli/internal/jsonstream"
19-
"github.com/docker/cli/internal/registry"
2019
"github.com/docker/cli/internal/tui"
21-
"github.com/moby/moby/api/pkg/authconfig"
2220
"github.com/moby/moby/api/types/auxprogress"
2321
"github.com/moby/moby/client"
2422
"github.com/morikuni/aec"
@@ -107,12 +105,8 @@ To push the complete multi-platform image, remove the --platform flag.
107105
}
108106
}
109107

110-
// Resolve the Repository name from fqn to RepositoryInfo
111-
indexInfo := registry.NewIndexInfo(ref)
112-
113108
// Resolve the Auth config relevant for this server
114-
authConfig := command.ResolveAuthConfig(dockerCli.ConfigFile(), indexInfo)
115-
encodedAuth, err := authconfig.Encode(authConfig)
109+
encodedAuth, err := command.RetrieveAuthTokenFromImage(dockerCli.ConfigFile(), ref.String())
116110
if err != nil {
117111
return err
118112
}
@@ -135,7 +129,7 @@ To push the complete multi-platform image, remove the --platform flag.
135129
}()
136130

137131
if !opts.untrusted {
138-
return pushTrustedReference(ctx, dockerCli, indexInfo, ref, authConfig, responseBody)
132+
return pushTrustedReference(ctx, dockerCli, ref, responseBody)
139133
}
140134

141135
if opts.quiet {

cli/command/image/trust.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/docker/cli/cli/streams"
1313
"github.com/docker/cli/cli/trust"
1414
"github.com/docker/cli/internal/jsonstream"
15+
"github.com/docker/cli/internal/registry"
1516
"github.com/moby/moby/api/pkg/authconfig"
1617
registrytypes "github.com/moby/moby/api/types/registry"
1718
"github.com/moby/moby/client"
@@ -43,12 +44,15 @@ func newNotaryClient(cli command.Streams, imgRefAndAuth trust.ImageRefAndAuth) (
4344
}
4445

4546
// pushTrustedReference pushes a canonical reference to the trust server.
46-
func pushTrustedReference(ctx context.Context, ioStreams command.Streams, indexInfo *registrytypes.IndexInfo, ref reference.Named, authConfig registrytypes.AuthConfig, in io.Reader) error {
47+
func pushTrustedReference(ctx context.Context, dockerCLI command.Cli, ref reference.Named, responseBody io.Reader) error {
48+
// Resolve the Repository name from fqn to RepositoryInfo
49+
indexInfo := registry.NewIndexInfo(ref)
4750
repoInfo := &trust.RepositoryInfo{
4851
Name: reference.TrimNamed(ref),
4952
Index: indexInfo,
5053
}
51-
return trust.PushTrustedReference(ctx, ioStreams, repoInfo, ref, authConfig, in, command.UserAgent())
54+
authConfig := command.ResolveAuthConfig(dockerCLI.ConfigFile(), indexInfo)
55+
return trust.PushTrustedReference(ctx, dockerCLI, repoInfo, ref, authConfig, responseBody, command.UserAgent())
5256
}
5357

5458
// trustedPull handles content trust pulling of an image

0 commit comments

Comments
 (0)