Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions common/cliutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.")
Expand Down
5 changes: 3 additions & 2 deletions common/cliutils/utils_test.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -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",
Expand Down
Loading