1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | const yargs = require("yargs");
|
5 | const colors_1 = require("../colors");
|
6 | const script_1 = require("../script");
|
7 | const secrets_encrypt_util_1 = require("../secret/secrets-encrypt.util");
|
8 | (0, script_1.runScript)(() => {
|
9 | const { pattern, file, encKey, del, jsonMode } = getEncryptCLIOptions();
|
10 | (0, secrets_encrypt_util_1.secretsEncrypt)(pattern, file, encKey, del, jsonMode);
|
11 | });
|
12 | function getEncryptCLIOptions() {
|
13 | require('dotenv').config();
|
14 | let { pattern, file, encKey, encKeyVar, del, jsonMode } = yargs.options({
|
15 | pattern: {
|
16 | type: 'string',
|
17 | array: true,
|
18 | desc: 'Globby pattern for secrets. Can be many.',
|
19 |
|
20 | default: './secret/**',
|
21 | },
|
22 | file: {
|
23 | type: 'string',
|
24 | desc: 'Single file to decrypt. Useful in jsonMode',
|
25 | },
|
26 | encKey: {
|
27 | type: 'string',
|
28 | desc: 'Encryption key',
|
29 |
|
30 |
|
31 | },
|
32 | encKeyVar: {
|
33 | type: 'string',
|
34 | desc: 'Env variable name to get `encKey` from.',
|
35 | default: 'SECRET_ENCRYPTION_KEY',
|
36 | },
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | del: {
|
42 | type: 'boolean',
|
43 | desc: 'Delete source files after encryption/decryption. Be careful!',
|
44 | default: false,
|
45 | },
|
46 | jsonMode: {
|
47 | type: 'boolean',
|
48 | desc: 'JSON mode. Encrypts only json values, not the whole file',
|
49 | default: false,
|
50 | },
|
51 | }).argv;
|
52 | if (!encKey) {
|
53 | encKey = process.env[encKeyVar];
|
54 | if (encKey) {
|
55 | console.log(`using encKey from process.env.${(0, colors_1.dimGrey)(encKeyVar)}`);
|
56 | }
|
57 | else {
|
58 | throw new Error(`encKey is required. Can be provided as --encKey or env.SECRET_ENCRYPTION_KEY (see readme.md)`);
|
59 | }
|
60 | }
|
61 |
|
62 | return { pattern: pattern, file, encKey, del, jsonMode };
|
63 | }
|