Update module github.com/containers/common to v0.51.1

Signed-off-by: Renovate Bot <bot@renovateapp.com>
This commit is contained in:
renovate[bot]
2023-03-22 15:11:42 +00:00
committed by GitHub
parent cfd6f20fbd
commit aa9862a718
5 changed files with 35 additions and 14 deletions

View File

@@ -19,6 +19,23 @@ import (
terminal "golang.org/x/term"
)
// ErrNewCredentialsInvalid means that the new user-provided credentials are
// not accepted by the registry.
type ErrNewCredentialsInvalid struct {
underlyingError error
message string
}
// Error returns the error message as a string.
func (e ErrNewCredentialsInvalid) Error() string {
return e.message
}
// Unwrap returns the underlying error.
func (e ErrNewCredentialsInvalid) Unwrap() error {
return e.underlyingError
}
// GetDefaultAuthFile returns env value REGISTRY_AUTH_FILE as default
// --authfile path used in multiple --authfile flag definitions
// Will fail over to DOCKER_CONFIG if REGISTRY_AUTH_FILE environment is not set
@@ -143,22 +160,25 @@ func Login(ctx context.Context, systemContext *types.SystemContext, opts *LoginO
}
if err = docker.CheckAuth(ctx, systemContext, username, password, registry); err == nil {
// Write the new credentials to the authfile
desc, err := config.SetCredentials(systemContext, key, username, password)
if err != nil {
return err
if !opts.NoWriteBack {
// Write the new credentials to the authfile
desc, err := config.SetCredentials(systemContext, key, username, password)
if err != nil {
return err
}
if opts.Verbose {
fmt.Fprintln(opts.Stdout, "Used: ", desc)
}
}
if opts.Verbose {
fmt.Fprintln(opts.Stdout, "Used: ", desc)
}
}
if err == nil {
fmt.Fprintln(opts.Stdout, "Login Succeeded!")
return nil
}
if unauthorized, ok := err.(docker.ErrUnauthorizedForCredentials); ok {
logrus.Debugf("error logging into %q: %v", key, unauthorized)
return fmt.Errorf("logging into %q: invalid username/password", key)
return ErrNewCredentialsInvalid{
underlyingError: err,
message: fmt.Sprintf("logging into %q: invalid username/password", key),
}
}
return fmt.Errorf("authenticating creds for %q: %w", key, err)
}

View File

@@ -26,6 +26,7 @@ type LoginOptions struct {
Stdin io.Reader // set to os.Stdin
Stdout io.Writer // set to os.Stdout
AcceptUnspecifiedRegistry bool // set to true if allows login with unspecified registry
NoWriteBack bool // set to true to not write the credentials to the authfile/cred helpers
}
// LogoutOptions represents the results for flags in logout