Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

Commit

Permalink
Assume Azure CLI config dir if env var is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
StiviiK committed Jul 4, 2022
1 parent ef52dbd commit 803a3a1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/azurecli.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"strings"

"github.com/StiviiK/azctx/log"
"github.com/StiviiK/azctx/utils"
"github.com/lithammer/fuzzysearch/fuzzy"
"github.com/spf13/afero"
Expand Down Expand Up @@ -43,12 +44,13 @@ func ReadAzureProfilesConfigFile(fs afero.Fs) (afero.File, error) {
// Verify that the AZURE_CONFIG_DIR environment variable is set
configDir := os.Getenv(AzureCLI_ConfigDirEnv)
if configDir == "" {
return nil, errors.New("AZURE_CONFIG_DIR is not set. Please create it and try again")
log.Warn("AZURE_CONFIG_DIR environment variable is not set. Using default config directory.")
configDir = os.Getenv("HOME") + "/.azure"
}

// Verify that the config dir exists
if !utils.FileExists(configDir) {
return nil, errors.New("AZURE_CONFIG_DIR is not a valid directory. Please run `az configure` and try again")
return nil, fmt.Errorf("AZURE_CONFIG_DIR (%s) is not a valid directory. Please run `az configure` and try again", configDir)
}

// Verify that the azureProfile.json file exists
Expand Down

0 comments on commit 803a3a1

Please sign in to comment.