diff --git a/pkg/util/azure/util.go b/pkg/util/azure/util.go index 0b4cfa067..41191d4b7 100644 --- a/pkg/util/azure/util.go +++ b/pkg/util/azure/util.go @@ -62,6 +62,10 @@ func LoadCredentials(config map[string]string) (map[string]string, error) { credFile = config[credentialFile] } + if len(credFile) == 0 { + return map[string]string{}, nil + } + // put the credential file content into a map creds, err := godotenv.Read(credFile) if err != nil { diff --git a/pkg/util/azure/util_test.go b/pkg/util/azure/util_test.go index e5a92f78c..1013ff825 100644 --- a/pkg/util/azure/util_test.go +++ b/pkg/util/azure/util_test.go @@ -28,8 +28,9 @@ import ( func TestLoadCredentials(t *testing.T) { // no credential file - _, err := LoadCredentials(nil) - require.NotNil(t, err) + credentials, err := LoadCredentials(nil) + require.Nil(t, err) + assert.NotNil(t, credentials) // specified credential file in the config name := filepath.Join(os.TempDir(), "credential") @@ -43,7 +44,7 @@ func TestLoadCredentials(t *testing.T) { config := map[string]string{ "credentialsFile": name, } - credentials, err := LoadCredentials(config) + credentials, err = LoadCredentials(config) require.Nil(t, err) assert.Equal(t, "value", credentials["key"])