mirror of
https://github.com/containers/skopeo.git
synced 2025-09-03 07:35:02 +00:00
Update to github.com/containers/common v0.49.0
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
43
vendor/github.com/containers/common/pkg/auth/auth.go
generated
vendored
43
vendor/github.com/containers/common/pkg/auth/auth.go
generated
vendored
@@ -3,6 +3,7 @@ package auth
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -14,7 +15,6 @@ import (
|
||||
"github.com/containers/image/v5/pkg/docker/config"
|
||||
"github.com/containers/image/v5/pkg/sysregistriesv2"
|
||||
"github.com/containers/image/v5/types"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
terminal "golang.org/x/term"
|
||||
)
|
||||
@@ -26,8 +26,8 @@ func GetDefaultAuthFile() string {
|
||||
if authfile := os.Getenv("REGISTRY_AUTH_FILE"); authfile != "" {
|
||||
return authfile
|
||||
}
|
||||
if auth_env := os.Getenv("DOCKER_CONFIG"); auth_env != "" {
|
||||
return filepath.Join(auth_env, "config.json")
|
||||
if authEnv := os.Getenv("DOCKER_CONFIG"); authEnv != "" {
|
||||
return filepath.Join(authEnv, "config.json")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func CheckAuthFile(authfile string) error {
|
||||
return nil
|
||||
}
|
||||
if _, err := os.Stat(authfile); err != nil {
|
||||
return errors.Wrap(err, "checking authfile")
|
||||
return fmt.Errorf("checking authfile: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -97,12 +97,12 @@ func Login(ctx context.Context, systemContext *types.SystemContext, opts *LoginO
|
||||
|
||||
authConfig, err := config.GetCredentials(systemContext, key)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get credentials")
|
||||
return fmt.Errorf("get credentials: %w", err)
|
||||
}
|
||||
|
||||
if opts.GetLoginSet {
|
||||
if authConfig.Username == "" {
|
||||
return errors.Errorf("not logged into %s", key)
|
||||
return fmt.Errorf("not logged into %s", key)
|
||||
}
|
||||
fmt.Fprintf(opts.Stdout, "%s\n", authConfig.Username)
|
||||
return nil
|
||||
@@ -139,7 +139,7 @@ func Login(ctx context.Context, systemContext *types.SystemContext, opts *LoginO
|
||||
|
||||
username, password, err := getUserAndPass(opts, password, authConfig.Username)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting username and password")
|
||||
return fmt.Errorf("getting username and password: %w", err)
|
||||
}
|
||||
|
||||
if err = docker.CheckAuth(ctx, systemContext, username, password, registry); err == nil {
|
||||
@@ -158,9 +158,9 @@ func Login(ctx context.Context, systemContext *types.SystemContext, opts *LoginO
|
||||
}
|
||||
if unauthorized, ok := err.(docker.ErrUnauthorizedForCredentials); ok {
|
||||
logrus.Debugf("error logging into %q: %v", key, unauthorized)
|
||||
return errors.Errorf("error logging into %q: invalid username/password", key)
|
||||
return fmt.Errorf("error logging into %q: invalid username/password", key)
|
||||
}
|
||||
return errors.Wrapf(err, "authenticating creds for %q", key)
|
||||
return fmt.Errorf("authenticating creds for %q: %w", key, err)
|
||||
}
|
||||
|
||||
// parseCredentialsKey turns the provided argument into a valid credential key
|
||||
@@ -191,10 +191,10 @@ func parseCredentialsKey(arg string, acceptRepositories bool) (key, registry str
|
||||
// Ideally c/image should provide dedicated validation functionality.
|
||||
ref, err := reference.ParseNormalizedNamed(key)
|
||||
if err != nil {
|
||||
return "", "", errors.Wrapf(err, "parse reference from %q", key)
|
||||
return "", "", fmt.Errorf("parse reference from %q: %w", key, err)
|
||||
}
|
||||
if !reference.IsNameOnly(ref) {
|
||||
return "", "", errors.Errorf("reference %q contains tag or digest", ref.String())
|
||||
return "", "", fmt.Errorf("reference %q contains tag or digest", ref.String())
|
||||
}
|
||||
refRegistry := reference.Domain(ref)
|
||||
if refRegistry != registry { // This should never happen, check just to make sure
|
||||
@@ -232,7 +232,7 @@ func getUserAndPass(opts *LoginOptions, password, userFromAuthFile string) (user
|
||||
}
|
||||
username, err = reader.ReadString('\n')
|
||||
if err != nil {
|
||||
return "", "", errors.Wrap(err, "reading username")
|
||||
return "", "", fmt.Errorf("reading username: %w", err)
|
||||
}
|
||||
// If the user just hit enter, use the displayed user from the
|
||||
// the authentication file. This allows to do a lazy
|
||||
@@ -246,7 +246,7 @@ func getUserAndPass(opts *LoginOptions, password, userFromAuthFile string) (user
|
||||
fmt.Fprint(opts.Stdout, "Password: ")
|
||||
pass, err := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||
if err != nil {
|
||||
return "", "", errors.Wrap(err, "reading password")
|
||||
return "", "", fmt.Errorf("reading password: %w", err)
|
||||
}
|
||||
password = string(pass)
|
||||
fmt.Fprintln(opts.Stdout)
|
||||
@@ -298,14 +298,15 @@ func Logout(systemContext *types.SystemContext, opts *LogoutOptions, args []stri
|
||||
}
|
||||
|
||||
err = config.RemoveAuthentication(systemContext, key)
|
||||
switch errors.Cause(err) {
|
||||
case nil:
|
||||
if err == nil {
|
||||
fmt.Fprintf(opts.Stdout, "Removed login credentials for %s\n", key)
|
||||
return nil
|
||||
case config.ErrNotLoggedIn:
|
||||
}
|
||||
|
||||
if errors.Is(err, config.ErrNotLoggedIn) {
|
||||
authConfig, err := config.GetCredentials(systemContext, key)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get credentials")
|
||||
return fmt.Errorf("get credentials: %w", err)
|
||||
}
|
||||
|
||||
authInvalid := docker.CheckAuth(context.Background(), systemContext, authConfig.Username, authConfig.Password, registry)
|
||||
@@ -313,10 +314,10 @@ func Logout(systemContext *types.SystemContext, opts *LogoutOptions, args []stri
|
||||
fmt.Printf("Not logged into %s with current tool. Existing credentials were established via docker login. Please use docker logout instead.\n", key)
|
||||
return nil
|
||||
}
|
||||
return errors.Errorf("Not logged into %s\n", key)
|
||||
default:
|
||||
return errors.Wrapf(err, "logging out of %q", key)
|
||||
return fmt.Errorf("not logged into %s", key)
|
||||
}
|
||||
|
||||
return fmt.Errorf("logging out of %q: %w", key, err)
|
||||
}
|
||||
|
||||
// defaultRegistryWhenUnspecified returns first registry from search list of registry.conf
|
||||
@@ -324,7 +325,7 @@ func Logout(systemContext *types.SystemContext, opts *LogoutOptions, args []stri
|
||||
func defaultRegistryWhenUnspecified(systemContext *types.SystemContext) (string, error) {
|
||||
registriesFromFile, err := sysregistriesv2.UnqualifiedSearchRegistries(systemContext)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "getting registry from registry.conf, please specify a registry")
|
||||
return "", fmt.Errorf("getting registry from registry.conf, please specify a registry: %w", err)
|
||||
}
|
||||
if len(registriesFromFile) == 0 {
|
||||
return "", errors.New("no registries found in registries.conf, a registry must be provided")
|
||||
|
Reference in New Issue
Block a user