From df08980618319d65f20d47bceb5879369103a613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wenkai=20Yin=28=E5=B0=B9=E6=96=87=E5=BC=80=29?= Date: Mon, 19 Feb 2024 17:02:30 +0800 Subject: [PATCH] Don't return error when no credential file found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't return error when no credential file found Fixes #7395 Signed-off-by: Wenkai Yin(尹文开) --- pkg/util/azure/util.go | 4 ++++ pkg/util/azure/util_test.go | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/util/azure/util.go b/pkg/util/azure/util.go index 0b4cfa067a..41191d4b77 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 e5a92f78cf..1013ff825e 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"])