Skip to content

Commit

Permalink
Don't return error when no credential file found
Browse files Browse the repository at this point in the history
Don't return error when no credential file found

Fixes vmware-tanzu#7395

Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
  • Loading branch information
ywk253100 committed Feb 21, 2024
1 parent 51a90e7 commit df08980
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/util/azure/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions pkg/util/azure/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"])

Expand Down

0 comments on commit df08980

Please sign in to comment.