1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.secretsEncrypt = 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 secretsEncrypt(pattern, encKey, algorithm, del) {
|
14 | const patterns = [
|
15 | ...pattern,
|
16 | `!**/*.enc`,
|
17 | ];
|
18 | const filenames = globby.sync(patterns);
|
19 | filenames.forEach(filename => {
|
20 | const plain = fs.readFileSync(filename);
|
21 | const enc = crypto_util_1.encryptRandomIVBuffer(plain, encKey, algorithm);
|
22 | const encFilename = `${filename}.enc`;
|
23 | fs.writeFileSync(encFilename, enc);
|
24 | if (del) {
|
25 | fs.unlinkSync(filename);
|
26 | }
|
27 | console.log(` ${path.basename(filename)} > ${path.basename(encFilename)}`);
|
28 | });
|
29 | console.log(`encrypted ${colors_1.yellow(filenames.length)} files in (${colors_1.dimGrey(pattern.join(' '))})`);
|
30 | }
|
31 | exports.secretsEncrypt = secretsEncrypt;
|