Skip to content

Commit 7ec3208

Browse files
Added logic for checking first if JFROG_CLI_ENCRYPTION_KEY is filepat… (#1464)
* Added logic for checking first if JFROG_CLI_ENCRYPTION_KEY is filepath and then key
1 parent 72e2205 commit 7ec3208

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

utils/config/encryption.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import (
55
"crypto/cipher"
66
"crypto/rand"
77
"encoding/base64"
8+
"fmt"
89
"io"
910
"os"
1011
"strconv"
12+
"strings"
1113
"syscall"
1214

1315
ioutils "github.com/jfrog/gofrog/io"
@@ -98,8 +100,22 @@ func handleSecrets(config *Config, handler secretHandler, key string) error {
98100
}
99101

100102
func getEncryptionKey() (string, error) {
101-
if key, exist := os.LookupEnv(coreutils.EncryptionKey); exist {
102-
return key, nil
103+
if keyOrPath, exist := os.LookupEnv(coreutils.EncryptionKey); exist {
104+
if strings.HasSuffix(keyOrPath, ".key") {
105+
fileInfo, err := os.Stat(keyOrPath)
106+
if err != nil {
107+
return "", fmt.Errorf("failed to stat encryption key file '%s': %w", keyOrPath, err)
108+
}
109+
if fileInfo.IsDir() {
110+
return "", fmt.Errorf("encryption key path '%s' is a directory, not a file", keyOrPath)
111+
}
112+
keyBytes, readErr := os.ReadFile(keyOrPath)
113+
if readErr != nil {
114+
return "", fmt.Errorf("failed to read encryption key from file '%s': %w", keyOrPath, readErr)
115+
}
116+
return strings.TrimSpace(string(keyBytes)), nil
117+
}
118+
return keyOrPath, nil
103119
}
104120
return getEncryptionKeyFromSecurityConfFile()
105121
}

0 commit comments

Comments
 (0)