mirror of
https://github.com/mudler/luet.git
synced 2025-09-01 23:37:07 +00:00
Update vendor
This commit is contained in:
74
vendor/github.com/fsouza/go-dockerclient/auth.go
generated
vendored
74
vendor/github.com/fsouza/go-dockerclient/auth.go
generated
vendored
@@ -9,16 +9,16 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ErrCannotParseDockercfg is the error returned by NewAuthConfigurations when the dockercfg cannot be parsed.
|
||||
var ErrCannotParseDockercfg = errors.New("Failed to read authentication from dockercfg")
|
||||
var ErrCannotParseDockercfg = errors.New("failed to read authentication from dockercfg")
|
||||
|
||||
// AuthConfiguration represents authentication options to use in the PushImage
|
||||
// method. It represents the authentication in the Docker index server.
|
||||
@@ -29,7 +29,7 @@ type AuthConfiguration struct {
|
||||
ServerAddress string `json:"serveraddress,omitempty"`
|
||||
|
||||
// IdentityToken can be supplied with the identitytoken response of the AuthCheck call
|
||||
// see https://godoc.org/github.com/docker/docker/api/types#AuthConfig
|
||||
// see https://pkg.go.dev/github.com/docker/docker/api/types?tab=doc#AuthConfig
|
||||
// It can be used in place of password not in conjunction with it
|
||||
IdentityToken string `json:"identitytoken,omitempty"`
|
||||
|
||||
@@ -55,10 +55,23 @@ func (c AuthConfigurations) isEmpty() bool {
|
||||
return len(c.Configs) == 0
|
||||
}
|
||||
|
||||
func (c AuthConfigurations) headerKey() string {
|
||||
func (AuthConfigurations) headerKey() string {
|
||||
return "X-Registry-Config"
|
||||
}
|
||||
|
||||
// merge updates the configuration. If a key is defined in both maps, the one
|
||||
// in c.Configs takes precedence.
|
||||
func (c *AuthConfigurations) merge(other AuthConfigurations) {
|
||||
for k, v := range other.Configs {
|
||||
if c.Configs == nil {
|
||||
c.Configs = make(map[string]AuthConfiguration)
|
||||
}
|
||||
if _, ok := c.Configs[k]; !ok {
|
||||
c.Configs[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AuthConfigurations119 is used to serialize a set of AuthConfigurations
|
||||
// for Docker API >= 1.19.
|
||||
type AuthConfigurations119 map[string]AuthConfiguration
|
||||
@@ -91,15 +104,20 @@ func NewAuthConfigurationsFromFile(path string) (*AuthConfigurations, error) {
|
||||
}
|
||||
|
||||
func cfgPaths(dockerConfigEnv string, homeEnv string) []string {
|
||||
var paths []string
|
||||
if dockerConfigEnv != "" {
|
||||
paths = append(paths, path.Join(dockerConfigEnv, "config.json"))
|
||||
return []string{
|
||||
path.Join(dockerConfigEnv, "plaintext-passwords.json"),
|
||||
path.Join(dockerConfigEnv, "config.json"),
|
||||
}
|
||||
}
|
||||
if homeEnv != "" {
|
||||
paths = append(paths, path.Join(homeEnv, ".docker", "config.json"))
|
||||
paths = append(paths, path.Join(homeEnv, ".dockercfg"))
|
||||
return []string{
|
||||
path.Join(homeEnv, ".docker", "plaintext-passwords.json"),
|
||||
path.Join(homeEnv, ".docker", "config.json"),
|
||||
path.Join(homeEnv, ".dockercfg"),
|
||||
}
|
||||
}
|
||||
return paths
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewAuthConfigurationsFromDockerCfg returns AuthConfigurations from
|
||||
@@ -108,17 +126,34 @@ func cfgPaths(dockerConfigEnv string, homeEnv string) []string {
|
||||
// - $HOME/.docker/config.json
|
||||
// - $HOME/.dockercfg
|
||||
func NewAuthConfigurationsFromDockerCfg() (*AuthConfigurations, error) {
|
||||
err := fmt.Errorf("No docker configuration found")
|
||||
var auths *AuthConfigurations
|
||||
|
||||
pathsToTry := cfgPaths(os.Getenv("DOCKER_CONFIG"), os.Getenv("HOME"))
|
||||
if len(pathsToTry) < 1 {
|
||||
return nil, errors.New("no docker configuration found")
|
||||
}
|
||||
return newAuthConfigurationsFromDockerCfg(pathsToTry)
|
||||
}
|
||||
|
||||
func newAuthConfigurationsFromDockerCfg(pathsToTry []string) (*AuthConfigurations, error) {
|
||||
var result *AuthConfigurations
|
||||
var auths *AuthConfigurations
|
||||
var err error
|
||||
for _, path := range pathsToTry {
|
||||
auths, err = NewAuthConfigurationsFromFile(path)
|
||||
if err == nil {
|
||||
return auths, nil
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if result == nil {
|
||||
result = auths
|
||||
} else {
|
||||
result.merge(*auths)
|
||||
}
|
||||
}
|
||||
return auths, err
|
||||
|
||||
if result != nil {
|
||||
return result, nil
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
// NewAuthConfigurations returns AuthConfigurations from a JSON encoded string in the
|
||||
@@ -167,9 +202,14 @@ func authConfigs(confs map[string]dockerConfig) (*AuthConfigurations, error) {
|
||||
if conf.Auth == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// support both padded and unpadded encoding
|
||||
data, err := base64.StdEncoding.DecodeString(conf.Auth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
data, err = base64.StdEncoding.WithPadding(base64.NoPadding).DecodeString(conf.Auth)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.New("error decoding plaintext credentials")
|
||||
}
|
||||
|
||||
userpass := strings.SplitN(string(data), ":", 2)
|
||||
@@ -217,7 +257,7 @@ func (c *Client) AuthCheck(conf *AuthConfiguration) (AuthStatus, error) {
|
||||
if conf == nil {
|
||||
return authStatus, errors.New("conf is nil")
|
||||
}
|
||||
resp, err := c.do("POST", "/auth", doOptions{data: conf})
|
||||
resp, err := c.do(http.MethodPost, "/auth", doOptions{data: conf})
|
||||
if err != nil {
|
||||
return authStatus, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user