@@ -2,13 +2,13 @@ package command
22
33import (
44 "bufio"
5- "context"
65 "fmt"
76 "io"
87 "os"
98 "runtime"
109 "strings"
1110
11+ "github.com/docker/cli/cli/config/configfile"
1212 configtypes "github.com/docker/cli/cli/config/types"
1313 "github.com/docker/cli/cli/streams"
1414 "github.com/docker/distribution/reference"
@@ -26,7 +26,7 @@ func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInf
2626 fmt .Fprintf (cli .Out (), "\n Please login prior to %s:\n " , cmdName )
2727 indexServer := registry .GetAuthConfigKey (index )
2828 isDefaultRegistry := indexServer == registry .IndexServer
29- authConfig , err := GetDefaultAuthConfig (cli , true , indexServer , isDefaultRegistry )
29+ authConfig , err := GetDefaultAuthConfig (cli . ConfigFile () , true , indexServer , isDefaultRegistry )
3030 if err != nil {
3131 fmt .Fprintf (cli .Err (), "Unable to retrieve stored credentials for %s, error: %s.\n " , indexServer , err )
3232 }
@@ -44,26 +44,26 @@ func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInf
4444//
4545// It is similar to [registry.ResolveAuthConfig], but uses the credentials-
4646// store, instead of looking up credentials from a map.
47- func ResolveAuthConfig (_ context. Context , cli Cli , index * registrytypes.IndexInfo ) registrytypes.AuthConfig {
47+ func ResolveAuthConfig (cfg * configfile. ConfigFile , index * registrytypes.IndexInfo ) registrytypes.AuthConfig {
4848 configKey := index .Name
4949 if index .Official {
5050 configKey = registry .IndexServer
5151 }
5252
53- a , _ := cli . ConfigFile () .GetAuthConfig (configKey )
53+ a , _ := cfg .GetAuthConfig (configKey )
5454 return registrytypes .AuthConfig (a )
5555}
5656
5757// GetDefaultAuthConfig gets the default auth config given a serverAddress
5858// If credentials for given serverAddress exists in the credential store, the configuration will be populated with values in it
59- func GetDefaultAuthConfig (cli Cli , checkCredStore bool , serverAddress string , isDefaultRegistry bool ) (registrytypes.AuthConfig , error ) {
59+ func GetDefaultAuthConfig (cfg * configfile. ConfigFile , checkCredStore bool , serverAddress string , isDefaultRegistry bool ) (registrytypes.AuthConfig , error ) {
6060 if ! isDefaultRegistry {
6161 serverAddress = registry .ConvertToHostname (serverAddress )
6262 }
6363 authconfig := configtypes.AuthConfig {}
6464 var err error
6565 if checkCredStore {
66- authconfig , err = cli . ConfigFile () .GetAuthConfig (serverAddress )
66+ authconfig , err = cfg .GetAuthConfig (serverAddress )
6767 if err != nil {
6868 return registrytypes.AuthConfig {
6969 ServerAddress : serverAddress ,
@@ -72,8 +72,7 @@ func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, is
7272 }
7373 authconfig .ServerAddress = serverAddress
7474 authconfig .IdentityToken = ""
75- res := registrytypes .AuthConfig (authconfig )
76- return res , nil
75+ return registrytypes .AuthConfig (authconfig ), nil
7776}
7877
7978// ConfigureAuth handles prompting of user's username and password if needed
@@ -172,9 +171,9 @@ func promptWithDefault(out io.Writer, prompt string, configDefault string) {
172171//
173172// For details on base64url encoding, see:
174173// - RFC4648, section 5: https://tools.ietf.org/html/rfc4648#section-5
175- func RetrieveAuthTokenFromImage (ctx context. Context , cli Cli , image string ) (string , error ) {
174+ func RetrieveAuthTokenFromImage (cfg * configfile. ConfigFile , image string ) (string , error ) {
176175 // Retrieve encoded auth token from the image reference
177- authConfig , err := resolveAuthConfigFromImage (ctx , cli , image )
176+ authConfig , err := resolveAuthConfigFromImage (cfg , image )
178177 if err != nil {
179178 return "" , err
180179 }
@@ -186,7 +185,7 @@ func RetrieveAuthTokenFromImage(ctx context.Context, cli Cli, image string) (str
186185}
187186
188187// resolveAuthConfigFromImage retrieves that AuthConfig using the image string
189- func resolveAuthConfigFromImage (ctx context. Context , cli Cli , image string ) (registrytypes.AuthConfig , error ) {
188+ func resolveAuthConfigFromImage (cfg * configfile. ConfigFile , image string ) (registrytypes.AuthConfig , error ) {
190189 registryRef , err := reference .ParseNormalizedNamed (image )
191190 if err != nil {
192191 return registrytypes.AuthConfig {}, err
@@ -195,5 +194,5 @@ func resolveAuthConfigFromImage(ctx context.Context, cli Cli, image string) (reg
195194 if err != nil {
196195 return registrytypes.AuthConfig {}, err
197196 }
198- return ResolveAuthConfig (ctx , cli , repoInfo .Index ), nil
197+ return ResolveAuthConfig (cfg , repoInfo .Index ), nil
199198}
0 commit comments