Skip to content

Commit 73d1f1f

Browse files
authored
Merge pull request FlowiseAI#1423 from FlowiseAI/bugfix/Credential-Decrypt
Bugfix/Credential Decrypt
2 parents 74ae361 + fe41b3e commit 73d1f1f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

packages/components/src/utils.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,17 @@ export const getEnvironmentVariable = (name: string): string | undefined => {
428428
* @returns {string}
429429
*/
430430
const getEncryptionKeyFilePath = (): string => {
431-
const checkPaths = [path.join(getUserHome(), '.flowise', 'encryption.key')]
431+
const checkPaths = [
432+
path.join(__dirname, '..', '..', 'encryption.key'),
433+
path.join(__dirname, '..', '..', 'server', 'encryption.key'),
434+
path.join(__dirname, '..', '..', '..', 'encryption.key'),
435+
path.join(__dirname, '..', '..', '..', 'server', 'encryption.key'),
436+
path.join(__dirname, '..', '..', '..', '..', 'encryption.key'),
437+
path.join(__dirname, '..', '..', '..', '..', 'server', 'encryption.key'),
438+
path.join(__dirname, '..', '..', '..', '..', '..', 'encryption.key'),
439+
path.join(__dirname, '..', '..', '..', '..', '..', 'server', 'encryption.key'),
440+
path.join(getUserHome(), '.flowise', 'encryption.key')
441+
]
432442
for (const checkPath of checkPaths) {
433443
if (fs.existsSync(checkPath)) {
434444
return checkPath
@@ -437,7 +447,7 @@ const getEncryptionKeyFilePath = (): string => {
437447
return ''
438448
}
439449

440-
const getEncryptionKeyPath = (): string => {
450+
export const getEncryptionKeyPath = (): string => {
441451
return process.env.SECRETKEY_PATH ? path.join(process.env.SECRETKEY_PATH, 'encryption.key') : getEncryptionKeyFilePath()
442452
}
443453

packages/server/src/utils/index.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
convertChatHistoryToText,
2424
getInputVariables,
2525
handleEscapeCharacters,
26+
getEncryptionKeyPath,
2627
ICommonObject,
2728
IDatabaseEntity,
2829
IMessage
@@ -852,16 +853,6 @@ export const isFlowValidForStream = (reactFlowNodes: IReactFlowNode[], endingNod
852853
return isChatOrLLMsExist && isValidChainOrAgent && !isOutputParserExist
853854
}
854855

855-
/**
856-
* Returns the path of encryption key
857-
* @returns {string}
858-
*/
859-
export const getEncryptionKeyPath = (): string => {
860-
return process.env.SECRETKEY_PATH
861-
? path.join(process.env.SECRETKEY_PATH, 'encryption.key')
862-
: path.join(getUserHome(), '.flowise', 'encryption.key')
863-
}
864-
865856
/**
866857
* Generate an encryption key
867858
* @returns {string}
@@ -882,7 +873,8 @@ export const getEncryptionKey = async (): Promise<string> => {
882873
return await fs.promises.readFile(getEncryptionKeyPath(), 'utf8')
883874
} catch (error) {
884875
const encryptKey = generateEncryptKey()
885-
await fs.promises.writeFile(getEncryptionKeyPath(), encryptKey)
876+
const defaultLocation = path.join(getUserHome(), '.flowise', 'encryption.key')
877+
await fs.promises.writeFile(defaultLocation, encryptKey)
886878
return encryptKey
887879
}
888880
}

0 commit comments

Comments
 (0)