diff --git a/common/cliutils/utils.go b/common/cliutils/utils.go index 75b9ba5ea..ef221ba4a 100644 --- a/common/cliutils/utils.go +++ b/common/cliutils/utils.go @@ -3,13 +3,14 @@ package cliutils import ( "errors" "fmt" - "github.com/jfrog/jfrog-cli-core/v2/common/project" "io" "os" "path/filepath" "strconv" "strings" + "github.com/jfrog/jfrog-cli-core/v2/common/project" + "github.com/jfrog/jfrog-cli-core/v2/common/commands" "github.com/jfrog/jfrog-cli-core/v2/common/spec" "github.com/jfrog/jfrog-cli-core/v2/utils/config" @@ -261,17 +262,17 @@ func FixWinPathsForFileSystemSourcedCmds(uploadSpec *spec.SpecFiles, specFlag, e } } -// Retrieves the application key from the .jfrog/config file or the environment variable. +// Retrieves the application key from the environment variable or the .jfrog/config file (in that order). // If the application key is not found in either, returns an empty string. func ReadJFrogApplicationKeyFromConfigOrEnv() (applicationKeyValue string) { - applicationKeyValue = getApplicationKeyFromConfig() + applicationKeyValue = os.Getenv(coreutils.ApplicationKey) if applicationKeyValue != "" { - log.Debug("Found application key in config file:", applicationKeyValue) + log.Debug("Found application key in environment variable:", applicationKeyValue) return } - applicationKeyValue = os.Getenv(coreutils.ApplicationKey) + applicationKeyValue = getApplicationKeyFromConfig() if applicationKeyValue != "" { - log.Debug("Found application key in environment variable:", applicationKeyValue) + log.Debug("Found application key in config file:", applicationKeyValue) return } log.Debug("Application key is not found in the config file or environment variable.") diff --git a/common/cliutils/utils_test.go b/common/cliutils/utils_test.go index ddac409e5..8a1ee317f 100644 --- a/common/cliutils/utils_test.go +++ b/common/cliutils/utils_test.go @@ -1,11 +1,12 @@ package cliutils import ( - testUtils "github.com/jfrog/jfrog-cli-core/v2/utils/tests" "os" "path/filepath" "testing" + testUtils "github.com/jfrog/jfrog-cli-core/v2/utils/tests" + "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" "github.com/stretchr/testify/assert" ) @@ -36,7 +37,7 @@ func TestReadJFrogApplicationKeyFromConfigOrEnv(t *testing.T) { name: "Application key in both config file and environment variable", configContent: "application:\n key: configKey", envValue: "envKey", - expectedResult: "configKey", + expectedResult: "envKey", }, { name: "No application key in config file or environment variable",