@@ -31,7 +31,7 @@ const (
3131// authConfigKey is the key used to store credentials for Docker Hub. It is
3232// a copy of [registry.IndexServer].
3333//
34- // [registry.IndexServer]: https://pkg.go.dev/github.com/docker/docker/registry#IndexServer
34+ // [registry.IndexServer]: https://pkg.go.dev/github.com/docker/docker@v28.3.3+incompatible /registry#IndexServer
3535const authConfigKey = "https://index.docker.io/v1/"
3636
3737// RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info
@@ -68,6 +68,8 @@ func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInf
6868//
6969// It is similar to [registry.ResolveAuthConfig], but uses the credentials-
7070// store, instead of looking up credentials from a map.
71+ //
72+ // [registry.ResolveAuthConfig]: https://pkg.go.dev/github.com/docker/[email protected] +incompatible/registry#ResolveAuthConfig 7173func ResolveAuthConfig (cfg * configfile.ConfigFile , index * registrytypes.IndexInfo ) registrytypes.AuthConfig {
7274 configKey := index .Name
7375 if index .Official {
@@ -194,37 +196,28 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword
194196 }, nil
195197}
196198
197- // RetrieveAuthTokenFromImage retrieves an encoded auth token given a complete
198- // image. The auth configuration is serialized as a base64url encoded RFC4648,
199- // section 5) JSON string for sending through the X-Registry-Auth header.
199+ // RetrieveAuthTokenFromImage retrieves an encoded auth token given a
200+ // complete image reference. The auth configuration is serialized as a
201+ // base64url encoded ([RFC 4648, Section 5]) JSON string for sending through
202+ // the "X-Registry-Auth" header.
200203//
201- // For details on base64url encoding, see:
202- // - RFC4648, section 5: https://tools.ietf.org/html/rfc4648#section-5
204+ // [RFC 4648, Section 5]: https://tools.ietf.org/html/rfc4648#section-5
203205func RetrieveAuthTokenFromImage (cfg * configfile.ConfigFile , image string ) (string , error ) {
204- // Retrieve encoded auth token from the image reference
205- authConfig , err := resolveAuthConfigFromImage (cfg , image )
206+ registryRef , err := reference .ParseNormalizedNamed (image )
206207 if err != nil {
207208 return "" , err
208209 }
209- encodedAuth , err := registrytypes .EncodeAuthConfig (authConfig )
210+ configKey := getAuthConfigKey (reference .Domain (registryRef ))
211+ authConfig , err := cfg .GetAuthConfig (configKey )
210212 if err != nil {
211213 return "" , err
212214 }
213- return encodedAuth , nil
214- }
215215
216- // resolveAuthConfigFromImage retrieves that AuthConfig using the image string
217- func resolveAuthConfigFromImage (cfg * configfile.ConfigFile , image string ) (registrytypes.AuthConfig , error ) {
218- registryRef , err := reference .ParseNormalizedNamed (image )
216+ encodedAuth , err := registrytypes .EncodeAuthConfig (registrytypes .AuthConfig (authConfig ))
219217 if err != nil {
220- return registrytypes.AuthConfig {}, err
221- }
222- configKey := getAuthConfigKey (reference .Domain (registryRef ))
223- a , err := cfg .GetAuthConfig (configKey )
224- if err != nil {
225- return registrytypes.AuthConfig {}, err
218+ return "" , err
226219 }
227- return registrytypes . AuthConfig ( a ) , nil
220+ return encodedAuth , nil
228221}
229222
230223// getAuthConfigKey special-cases using the full index address of the official
@@ -233,8 +226,8 @@ func resolveAuthConfigFromImage(cfg *configfile.ConfigFile, image string) (regis
233226// It is similar to [registry.GetAuthConfigKey], but does not require on
234227// [registrytypes.IndexInfo] as intermediate.
235228//
236- // [registry.GetAuthConfigKey]: https://pkg.go.dev/github.com/docker/docker/registry#GetAuthConfigKey
237- // [registrytypes.IndexInfo]:https://pkg.go.dev/github.com/docker/docker/api/types/registry#IndexInfo
229+ // [registry.GetAuthConfigKey]: https://pkg.go.dev/github.com/docker/docker@v28.3.3+incompatible /registry#GetAuthConfigKey
230+ // [registrytypes.IndexInfo]: https://pkg.go.dev/github.com/docker/docker@v28.3.3+incompatible /api/types/registry#IndexInfo
238231func getAuthConfigKey (domainName string ) string {
239232 if domainName == "docker.io" || domainName == "index.docker.io" {
240233 return authConfigKey
0 commit comments