Skip to content

Commit ea3badf

Browse files
feat: fix decrypt (#1922)
Co-authored-by: ElderMatt <[email protected]>
1 parent bada051 commit ea3badf

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/common/crypt.ts

+20-16
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,28 @@ const processFileChunk = async (crypt: CR, files: string[]): Promise<(ProcessOut
6060
const commands = files.map(async (file) => {
6161
if (!crypt.condition || (await crypt.condition(file))) {
6262
d.debug(`${crypt.cmd} ${file}`)
63-
const result = $`${crypt.cmd.split(' ')} ${file}`.quiet()
64-
return result
65-
.then(async (res) => {
66-
if (crypt.cmd === CryptType.DECRYPT) {
67-
const outputFile = `${file}.dec`
68-
await $`echo ${res.stdout} > ${outputFile}`
69-
}
63+
try {
64+
d.info(`${crypt.cmd} ${file}`)
65+
const result = await $`${[...crypt.cmd.split(' '), file]}`.quiet()
66+
67+
if (crypt.cmd === CryptType.DECRYPT) {
68+
const outputFile = `${file}.dec`
69+
await writeFile(outputFile, result.stdout)
70+
}
71+
72+
if (crypt.post) {
73+
await crypt.post(file)
74+
}
75+
76+
return result
77+
} catch (error) {
78+
if (error.message.includes('Already encrypted') && (await pathExists(`${file}.dec`))) {
79+
const res = await $`helm secrets encrypt ${file}.dec`
80+
await writeFile(file, res.stdout)
7081
if (crypt.post) await crypt.post(file)
7182
return res
72-
})
73-
.catch(async (error) => {
74-
if (error.message.includes('Already encrypted') && (await pathExists(`${file}.dec`))) {
75-
const res = await $`helm secrets encrypt ${file}.dec`
76-
await $`echo ${res.stdout} > ${file}`
77-
if (crypt.post) await crypt.post(file)
78-
return res
79-
}
80-
})
83+
}
84+
}
8185
}
8286
return undefined
8387
})

0 commit comments

Comments
 (0)