Allow username/password in config file

Signed-off-by: Jon Johnson <jonjohnson@google.com>
(cherry picked from commit 37e9cabf11)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Jon Johnson 2019-10-02 12:41:50 -07:00 committed by Sebastiaan van Stijn
parent ab4a5cc0f7
commit a1c4a0f9e8
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 33 additions and 3 deletions

View File

@ -123,9 +123,11 @@ 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 {
ac.Username, ac.Password, err = decodeAuth(ac.Auth) if ac.Auth != "" {
if err != nil { ac.Username, ac.Password, err = decodeAuth(ac.Auth)
return err if err != nil {
return err
}
} }
ac.Auth = "" ac.Auth = ""
ac.ServerAddress = addr ac.ServerAddress = addr

View File

@ -2,6 +2,7 @@ package configfile
import ( import (
"bytes" "bytes"
"encoding/json"
"io/ioutil" "io/ioutil"
"os" "os"
"testing" "testing"
@ -380,6 +381,33 @@ 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",
}
cf := ConfigFile{
AuthConfigs: map[string]types.AuthConfig{
"example.com/foo": want,
},
}
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