From f47895d93e287c842324147b3d415cc586667a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Sat, 11 Sep 2021 17:29:23 +0200 Subject: [PATCH] Don't use ref from parserRegistryArgument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can now call GetCredentials with namespaced keys, so simplify. The ref value is still computed, we'll remove that momentarily. Should not change behavior. Signed-off-by: Miloslav Trmač --- pkg/auth/auth.go | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index 1da197ee7..3b619db5b 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -70,9 +70,7 @@ func Login(ctx context.Context, systemContext *types.SystemContext, opts *LoginO systemContext = systemContextWithOptions(systemContext, opts.AuthFile, opts.CertDir) var ( - authConfig types.DockerAuthConfig key, registry string - ref reference.Named err error ) switch len(args) { @@ -87,7 +85,7 @@ func Login(ctx context.Context, systemContext *types.SystemContext, opts *LoginO logrus.Debugf("registry not specified, default to the first registry %q from registries.conf", key) case 1: - key, registry, ref, err = parseRegistryArgument(args[0], opts.AcceptRepositories) + key, registry, _, err = parseRegistryArgument(args[0], opts.AcceptRepositories) if err != nil { return err } @@ -96,16 +94,9 @@ func Login(ctx context.Context, systemContext *types.SystemContext, opts *LoginO return errors.New("login accepts only one registry to login to") } - if ref != nil { - authConfig, err = config.GetCredentialsForRef(systemContext, ref) - if err != nil { - return errors.Wrap(err, "get credentials for repository") - } - } else { - authConfig, err = config.GetCredentials(systemContext, registry) - if err != nil { - return errors.Wrap(err, "get credentials") - } + authConfig, err := config.GetCredentials(systemContext, key) + if err != nil { + return errors.Wrap(err, "get credentials") } if opts.GetLoginSet { @@ -282,7 +273,6 @@ func Logout(systemContext *types.SystemContext, opts *LogoutOptions, args []stri var ( key, registry string - ref reference.Named err error ) switch len(args) { @@ -297,7 +287,7 @@ func Logout(systemContext *types.SystemContext, opts *LogoutOptions, args []stri logrus.Debugf("registry not specified, default to the first registry %q from registries.conf", key) case 1: - key, registry, ref, err = parseRegistryArgument(args[0], opts.AcceptRepositories) + key, registry, _, err = parseRegistryArgument(args[0], opts.AcceptRepositories) if err != nil { return err } @@ -312,17 +302,9 @@ func Logout(systemContext *types.SystemContext, opts *LogoutOptions, args []stri fmt.Fprintf(opts.Stdout, "Removed login credentials for %s\n", key) return nil case config.ErrNotLoggedIn: - var authConfig types.DockerAuthConfig - if ref != nil { - authConfig, err = config.GetCredentialsForRef(systemContext, ref) - if err != nil { - return errors.Wrap(err, "get credentials for repository") - } - } else { - authConfig, err = config.GetCredentials(systemContext, registry) - if err != nil { - return errors.Wrap(err, "get credentials") - } + authConfig, err := config.GetCredentials(systemContext, key) + if err != nil { + return errors.Wrap(err, "get credentials") } authInvalid := docker.CheckAuth(context.Background(), systemContext, authConfig.Username, authConfig.Password, registry)