From 4286883b956cfafec25b421aa94ae16cefebe1c8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 19 Aug 2025 23:21:58 +0200 Subject: [PATCH] cli/command: inline resolveAuthConfigFromImage Signed-off-by: Sebastiaan van Stijn --- cli/command/registry.go | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/cli/command/registry.go b/cli/command/registry.go index b4d4ab921..036c53b1b 100644 --- a/cli/command/registry.go +++ b/cli/command/registry.go @@ -203,32 +203,23 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword // // [RFC 4648, Section 5]: https://tools.ietf.org/html/rfc4648#section-5 func RetrieveAuthTokenFromImage(cfg *configfile.ConfigFile, image string) (string, error) { - // Retrieve encoded auth token from the image reference - authConfig, err := resolveAuthConfigFromImage(cfg, image) + registryRef, err := reference.ParseNormalizedNamed(image) if err != nil { return "", err } - encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig) + configKey := getAuthConfigKey(reference.Domain(registryRef)) + authConfig, err := cfg.GetAuthConfig(configKey) + if err != nil { + return "", err + } + + encodedAuth, err := registrytypes.EncodeAuthConfig(registrytypes.AuthConfig(authConfig)) if err != nil { return "", err } return encodedAuth, nil } -// resolveAuthConfigFromImage retrieves that AuthConfig using the image string -func resolveAuthConfigFromImage(cfg *configfile.ConfigFile, image string) (registrytypes.AuthConfig, error) { - registryRef, err := reference.ParseNormalizedNamed(image) - if err != nil { - return registrytypes.AuthConfig{}, err - } - configKey := getAuthConfigKey(reference.Domain(registryRef)) - a, err := cfg.GetAuthConfig(configKey) - if err != nil { - return registrytypes.AuthConfig{}, err - } - return registrytypes.AuthConfig(a), nil -} - // getAuthConfigKey special-cases using the full index address of the official // index as the AuthConfig key, and uses the (host)name[:port] for private indexes. //