Skip to content

Commit 390990b

Browse files
committed
Fix handling of missing data in GetAllCredentials
- Don't check for credentials.IsErrCredentialsNotFoundMessage, which is handled by GetCredentials and is not reachable here - Do check for an empty struct, which is the outcome of that handling. Don't add that empty struct, meaning "nothing found", to the returned data. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
1 parent 05bf651 commit 390990b

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

pkg/docker/config/config.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,12 @@ func GetAllCredentials(sys *types.SystemContext) (map[string]types.DockerAuthCon
190190
for key := range allKeys {
191191
authConf, err := GetCredentials(sys, key)
192192
if err != nil {
193-
if credentials.IsErrCredentialsNotFoundMessage(err.Error()) {
194-
// Ignore if the credentials could not be found (anymore).
195-
continue
196-
}
197193
// Note: we rely on the logging in `GetCredentials`.
198194
return nil, err
199195
}
200-
authConfigs[key] = authConf
196+
if authConf != (types.DockerAuthConfig{}) {
197+
authConfigs[key] = authConf
198+
}
201199
}
202200

203201
return authConfigs, nil

pkg/docker/config/config_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,7 @@ func TestGetAllCredentials(t *testing.T) {
551551
os.Setenv("DOCKER_CONFIG", filepath.Join(path, "testdata"))
552552
authConfigs, err := GetAllCredentials(nil)
553553
require.NoError(t, err)
554-
require.Len(t, authConfigs, 1)
555-
require.Equal(t, authConfigs["registry-no-creds.com"], types.DockerAuthConfig{})
554+
require.Empty(t, authConfigs)
556555
os.Unsetenv("DOCKER_CONFIG")
557556

558557
for _, data := range [][]struct {

0 commit comments

Comments
 (0)