Skip to content

Commit aaed38f

Browse files
authored
Merge pull request #6507 from thaJeztah/split_trust_auth
cli/command/image: pushTrustedReference: internalize constructing indexInfo
2 parents fdf9b43 + 9a6313e commit aaed38f

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

cli/command/image/push.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import (
1818
"github.com/docker/cli/cli/streams"
1919
"github.com/docker/cli/cli/trust"
2020
"github.com/docker/cli/internal/jsonstream"
21-
"github.com/docker/cli/internal/registry"
2221
"github.com/docker/cli/internal/tui"
23-
"github.com/moby/moby/api/pkg/authconfig"
2422
"github.com/moby/moby/api/types/auxprogress"
2523
"github.com/moby/moby/client"
2624
"github.com/morikuni/aec"
@@ -108,12 +106,8 @@ To push the complete multi-platform image, remove the --platform flag.
108106
}
109107
}
110108

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

138132
if !opts.untrusted {
139-
return pushTrustedReference(ctx, dockerCli, indexInfo, ref, authConfig, responseBody)
133+
return pushTrustedReference(ctx, dockerCli, ref, responseBody)
140134
}
141135

142136
if opts.quiet {

cli/command/image/trust.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/docker/cli/cli/streams"
1414
"github.com/docker/cli/cli/trust"
1515
"github.com/docker/cli/internal/jsonstream"
16+
"github.com/docker/cli/internal/registry"
1617
"github.com/moby/moby/api/pkg/authconfig"
1718
registrytypes "github.com/moby/moby/api/types/registry"
1819
"github.com/moby/moby/client"
@@ -43,12 +44,18 @@ 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, and create an
49+
// IndexInfo. Docker Content Trust uses the IndexInfo.Official field to
50+
// select the right domain for Docker Hub's Notary server;
51+
// https://github.com/docker/cli/blob/v28.4.0/cli/trust/trust.go#L65-L79
52+
indexInfo := registry.NewIndexInfo(ref)
4753
repoInfo := &trust.RepositoryInfo{
4854
Name: reference.TrimNamed(ref),
4955
Index: indexInfo,
5056
}
51-
return trust.PushTrustedReference(ctx, ioStreams, repoInfo, ref, authConfig, in, command.UserAgent())
57+
authConfig := command.ResolveAuthConfig(dockerCLI.ConfigFile(), indexInfo)
58+
return trust.PushTrustedReference(ctx, dockerCLI, repoInfo, ref, authConfig, responseBody, command.UserAgent())
5259
}
5360

5461
// trustedPull handles content trust pulling of an image

cli/trust/trust.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ func GetImageReferencesAndAuth(ctx context.Context,
348348
return ImageRefAndAuth{}, err
349349
}
350350

351-
// Resolve the Repository name from fqn to RepositoryInfo
351+
// Resolve the Repository name from fqn to RepositoryInfo, and create an
352+
// IndexInfo. Docker Content Trust uses the IndexInfo.Official field to
353+
// select the right domain for Docker Hub's Notary server;
354+
// https://github.com/docker/cli/blob/v28.4.0/cli/trust/trust.go#L65-L79
352355
indexInfo := registry.NewIndexInfo(ref)
353356
authConfig := authResolver(ctx, indexInfo)
354357
return ImageRefAndAuth{

0 commit comments

Comments
 (0)