Skip to content

Commit

Permalink
Merge pull request #1423 from FlowiseAI/bugfix/Credential-Decrypt
Browse files Browse the repository at this point in the history
Bugfix/Credential Decrypt
  • Loading branch information
HenryHengZJ authored Dec 21, 2023
2 parents 1c299af + 44294d0 commit ff74920
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
14 changes: 12 additions & 2 deletions packages/components/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,17 @@ export const getEnvironmentVariable = (name: string): string | undefined => {
* @returns {string}
*/
const getEncryptionKeyFilePath = (): string => {
const checkPaths = [path.join(getUserHome(), '.flowise', 'encryption.key')]
const checkPaths = [
path.join(__dirname, '..', '..', 'encryption.key'),
path.join(__dirname, '..', '..', 'server', 'encryption.key'),
path.join(__dirname, '..', '..', '..', 'encryption.key'),
path.join(__dirname, '..', '..', '..', 'server', 'encryption.key'),
path.join(__dirname, '..', '..', '..', '..', 'encryption.key'),
path.join(__dirname, '..', '..', '..', '..', 'server', 'encryption.key'),
path.join(__dirname, '..', '..', '..', '..', '..', 'encryption.key'),
path.join(__dirname, '..', '..', '..', '..', '..', 'server', 'encryption.key'),
path.join(getUserHome(), '.flowise', 'encryption.key')
]
for (const checkPath of checkPaths) {
if (fs.existsSync(checkPath)) {
return checkPath
Expand All @@ -437,7 +447,7 @@ const getEncryptionKeyFilePath = (): string => {
return ''
}

const getEncryptionKeyPath = (): string => {
export const getEncryptionKeyPath = (): string => {
return process.env.SECRETKEY_PATH ? path.join(process.env.SECRETKEY_PATH, 'encryption.key') : getEncryptionKeyFilePath()
}

Expand Down
14 changes: 3 additions & 11 deletions packages/server/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
convertChatHistoryToText,
getInputVariables,
handleEscapeCharacters,
getEncryptionKeyPath,
ICommonObject,
IDatabaseEntity,
IMessage
Expand Down Expand Up @@ -852,16 +853,6 @@ export const isFlowValidForStream = (reactFlowNodes: IReactFlowNode[], endingNod
return isChatOrLLMsExist && isValidChainOrAgent && !isOutputParserExist
}

/**
* Returns the path of encryption key
* @returns {string}
*/
export const getEncryptionKeyPath = (): string => {
return process.env.SECRETKEY_PATH
? path.join(process.env.SECRETKEY_PATH, 'encryption.key')
: path.join(getUserHome(), '.flowise', 'encryption.key')
}

/**
* Generate an encryption key
* @returns {string}
Expand All @@ -882,7 +873,8 @@ export const getEncryptionKey = async (): Promise<string> => {
return await fs.promises.readFile(getEncryptionKeyPath(), 'utf8')
} catch (error) {
const encryptKey = generateEncryptKey()
await fs.promises.writeFile(getEncryptionKeyPath(), encryptKey)
const defaultLocation = path.join(getUserHome(), '.flowise', 'encryption.key')
await fs.promises.writeFile(defaultLocation, encryptKey)
return encryptKey
}
}
Expand Down

0 comments on commit ff74920

Please sign in to comment.