Skip to content

Commit 624b659

Browse files
authored
APP-1684 - Change the fallback order of the configuration for application key (jfrog#1517)
1 parent 87fc727 commit 624b659

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

common/cliutils/utils.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package cliutils
33
import (
44
"errors"
55
"fmt"
6-
"github.com/jfrog/jfrog-cli-core/v2/common/project"
76
"io"
87
"os"
98
"path/filepath"
109
"strconv"
1110
"strings"
1211

12+
"github.com/jfrog/jfrog-cli-core/v2/common/project"
13+
1314
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
1415
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
1516
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
@@ -261,17 +262,17 @@ func FixWinPathsForFileSystemSourcedCmds(uploadSpec *spec.SpecFiles, specFlag, e
261262
}
262263
}
263264

264-
// Retrieves the application key from the .jfrog/config file or the environment variable.
265+
// Retrieves the application key from the environment variable or the .jfrog/config file (in that order).
265266
// If the application key is not found in either, returns an empty string.
266267
func ReadJFrogApplicationKeyFromConfigOrEnv() (applicationKeyValue string) {
267-
applicationKeyValue = getApplicationKeyFromConfig()
268+
applicationKeyValue = os.Getenv(coreutils.ApplicationKey)
268269
if applicationKeyValue != "" {
269-
log.Debug("Found application key in config file:", applicationKeyValue)
270+
log.Debug("Found application key in environment variable:", applicationKeyValue)
270271
return
271272
}
272-
applicationKeyValue = os.Getenv(coreutils.ApplicationKey)
273+
applicationKeyValue = getApplicationKeyFromConfig()
273274
if applicationKeyValue != "" {
274-
log.Debug("Found application key in environment variable:", applicationKeyValue)
275+
log.Debug("Found application key in config file:", applicationKeyValue)
275276
return
276277
}
277278
log.Debug("Application key is not found in the config file or environment variable.")

common/cliutils/utils_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package cliutils
22

33
import (
4-
testUtils "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
54
"os"
65
"path/filepath"
76
"testing"
87

8+
testUtils "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
9+
910
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
1011
"github.com/stretchr/testify/assert"
1112
)
@@ -36,7 +37,7 @@ func TestReadJFrogApplicationKeyFromConfigOrEnv(t *testing.T) {
3637
name: "Application key in both config file and environment variable",
3738
configContent: "application:\n key: configKey",
3839
envValue: "envKey",
39-
expectedResult: "configKey",
40+
expectedResult: "envKey",
4041
},
4142
{
4243
name: "No application key in config file or environment variable",

0 commit comments

Comments
 (0)