Skip to content

Commit

Permalink
Merge pull request #7453 from ywk253100/240221_credential
Browse files Browse the repository at this point in the history
[cherry-pick]Don't return error when no credential file found
  • Loading branch information
ywk253100 authored Feb 21, 2024
2 parents 51a90e7 + df08980 commit cb7211d
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 cb7211d

Please sign in to comment.