1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.secretsDecrypt = void 0;
|
4 | const fs = require("fs-extra");
|
5 | const globby = require("globby");
|
6 | const path = require("path");
|
7 | const colors_1 = require("../colors");
|
8 | const crypto_util_1 = require("../security/crypto.util");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function secretsDecrypt(dir, encKey, algorithm, del) {
|
14 | const patterns = dir.map(d => `${d}/**/*.enc`);
|
15 | const filenames = globby.sync(patterns);
|
16 | filenames.forEach(filename => {
|
17 | const enc = fs.readFileSync(filename);
|
18 | const plain = crypto_util_1.decryptRandomIVBuffer(enc, encKey, algorithm);
|
19 | const plainFilename = filename.slice(0, filename.length - '.enc'.length);
|
20 | fs.writeFileSync(plainFilename, plain);
|
21 | if (del) {
|
22 | fs.unlinkSync(filename);
|
23 | }
|
24 | console.log(` ${path.basename(filename)} > ${path.basename(plainFilename)}`);
|
25 | });
|
26 | console.log(`decrypted ${colors_1.yellow(filenames.length)} files in ${colors_1.dimGrey(dir.join(' '))}`);
|
27 | }
|
28 | exports.secretsDecrypt = secretsDecrypt;
|