Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit d60a0ce

Browse files
Merge pull request #2264 from thaJeztah/19.03_backport_passthrough_user_pass
[19.03 backport] Allow username/password in config file Upstream-commit: a3e131b323bba789cc4c48d357cd6338f1829918 Component: cli
2 parents 06f4c68 + 72f8164 commit d60a0ce

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

components/cli/cli/config/configfile/file.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ func (configFile *ConfigFile) LoadFromReader(configData io.Reader) error {
123123
}
124124
var err error
125125
for addr, ac := range configFile.AuthConfigs {
126-
ac.Username, ac.Password, err = decodeAuth(ac.Auth)
127-
if err != nil {
128-
return err
126+
if ac.Auth != "" {
127+
ac.Username, ac.Password, err = decodeAuth(ac.Auth)
128+
if err != nil {
129+
return err
130+
}
129131
}
130132
ac.Auth = ""
131133
ac.ServerAddress = addr

components/cli/cli/config/configfile/file_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package configfile
22

33
import (
44
"bytes"
5+
"encoding/json"
56
"io/ioutil"
67
"os"
78
"testing"
@@ -380,6 +381,41 @@ func TestGetAllCredentialsCredHelperOverridesDefaultStore(t *testing.T) {
380381
assert.Check(t, is.Equal(0, testCredHelper.(*mockNativeStore).GetAllCallCount))
381382
}
382383

384+
func TestLoadFromReaderWithUsernamePassword(t *testing.T) {
385+
configFile := New("test-load")
386+
defer os.Remove("test-load")
387+
388+
want := types.AuthConfig{
389+
Username: "user",
390+
Password: "pass",
391+
}
392+
393+
for _, tc := range []types.AuthConfig{
394+
want,
395+
{
396+
Auth: encodeAuth(&want),
397+
},
398+
} {
399+
cf := ConfigFile{
400+
AuthConfigs: map[string]types.AuthConfig{
401+
"example.com/foo": tc,
402+
},
403+
}
404+
405+
b, err := json.Marshal(cf)
406+
assert.NilError(t, err)
407+
408+
err = configFile.LoadFromReader(bytes.NewReader(b))
409+
assert.NilError(t, err)
410+
411+
got, err := configFile.GetAuthConfig("example.com/foo")
412+
assert.NilError(t, err)
413+
414+
assert.Check(t, is.DeepEqual(want.Username, got.Username))
415+
assert.Check(t, is.DeepEqual(want.Password, got.Password))
416+
}
417+
}
418+
383419
func TestCheckKubernetesConfigurationRaiseAnErrorOnInvalidValue(t *testing.T) {
384420
testCases := []struct {
385421
name string

0 commit comments

Comments
 (0)