mirror of https://github.com/docker/cli.git
Merge pull request #2122 from jonjohnsonjr/passthrough-user-pass
Allow username/password in config file
This commit is contained in:
commit
a8ff7f8210
|
@ -123,10 +123,12 @@ func (configFile *ConfigFile) LoadFromReader(configData io.Reader) error {
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
for addr, ac := range configFile.AuthConfigs {
|
for addr, ac := range configFile.AuthConfigs {
|
||||||
|
if ac.Auth != "" {
|
||||||
ac.Username, ac.Password, err = decodeAuth(ac.Auth)
|
ac.Username, ac.Password, err = decodeAuth(ac.Auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ac.Auth = ""
|
ac.Auth = ""
|
||||||
ac.ServerAddress = addr
|
ac.ServerAddress = addr
|
||||||
configFile.AuthConfigs[addr] = ac
|
configFile.AuthConfigs[addr] = ac
|
||||||
|
|
|
@ -2,6 +2,7 @@ package configfile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -380,6 +381,41 @@ func TestGetAllCredentialsCredHelperOverridesDefaultStore(t *testing.T) {
|
||||||
assert.Check(t, is.Equal(0, testCredHelper.(*mockNativeStore).GetAllCallCount))
|
assert.Check(t, is.Equal(0, testCredHelper.(*mockNativeStore).GetAllCallCount))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadFromReaderWithUsernamePassword(t *testing.T) {
|
||||||
|
configFile := New("test-load")
|
||||||
|
defer os.Remove("test-load")
|
||||||
|
|
||||||
|
want := types.AuthConfig{
|
||||||
|
Username: "user",
|
||||||
|
Password: "pass",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range []types.AuthConfig{
|
||||||
|
want,
|
||||||
|
{
|
||||||
|
Auth: encodeAuth(&want),
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
cf := ConfigFile{
|
||||||
|
AuthConfigs: map[string]types.AuthConfig{
|
||||||
|
"example.com/foo": tc,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := json.Marshal(cf)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
|
err = configFile.LoadFromReader(bytes.NewReader(b))
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
|
got, err := configFile.GetAuthConfig("example.com/foo")
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
|
assert.Check(t, is.DeepEqual(want.Username, got.Username))
|
||||||
|
assert.Check(t, is.DeepEqual(want.Password, got.Password))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCheckKubernetesConfigurationRaiseAnErrorOnInvalidValue(t *testing.T) {
|
func TestCheckKubernetesConfigurationRaiseAnErrorOnInvalidValue(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
Loading…
Reference in New Issue