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

Commit 5caedcf

Browse files
jonjohnsonjrthaJeztah
authored andcommitted
Allow username/password in config file
Signed-off-by: Jon Johnson <jonjohnson@google.com> (cherry picked from commit 37e9cabf1158977f2ab3528a31140cc21723ff3a) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: a1c4a0f9e8ccc99b239db35597e507e00148538e Component: cli
1 parent a2f2b95 commit 5caedcf

2 files changed

Lines changed: 33 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: 28 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,33 @@ 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+
cf := ConfigFile{
393+
AuthConfigs: map[string]types.AuthConfig{
394+
"example.com/foo": want,
395+
},
396+
}
397+
398+
b, err := json.Marshal(cf)
399+
assert.NilError(t, err)
400+
401+
err = configFile.LoadFromReader(bytes.NewReader(b))
402+
assert.NilError(t, err)
403+
404+
got, err := configFile.GetAuthConfig("example.com/foo")
405+
assert.NilError(t, err)
406+
407+
assert.Check(t, is.DeepEqual(want.Username, got.Username))
408+
assert.Check(t, is.DeepEqual(want.Password, got.Password))
409+
}
410+
383411
func TestCheckKubernetesConfigurationRaiseAnErrorOnInvalidValue(t *testing.T) {
384412
testCases := []struct {
385413
name string

0 commit comments

Comments
 (0)