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 | script_1.runScript(() => {
|
9 | const { pattern, encKey, algorithm, del } = getEncryptCLIOptions();
|
10 | secrets_encrypt_util_1.secretsEncrypt(pattern, encKey, algorithm, del);
|
11 | });
|
12 | function getEncryptCLIOptions() {
|
13 | require('dotenv').config();
|
14 | let { pattern, encKey, encKeyVar, algorithm, del } = 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 | encKey: {
|
23 | type: 'string',
|
24 | desc: 'Encryption key',
|
25 |
|
26 |
|
27 | },
|
28 | encKeyVar: {
|
29 | type: 'string',
|
30 | desc: 'Env variable name to get `encKey` from.',
|
31 | default: 'SECRET_ENCRYPTION_KEY',
|
32 | },
|
33 | algorithm: {
|
34 | type: 'string',
|
35 | default: 'aes-256-cbc',
|
36 | },
|
37 | del: {
|
38 | type: 'boolean',
|
39 | desc: 'Delete source files after encryption/decryption. Be careful!',
|
40 | },
|
41 | }).argv;
|
42 | if (!encKey) {
|
43 | encKey = process.env[encKeyVar];
|
44 | if (encKey) {
|
45 | console.log(`using encKey from process.env.${colors_1.dimGrey(encKeyVar)}`);
|
46 | }
|
47 | else {
|
48 | throw new Error(`encKey is required. Can be provided as --encKey or env.SECRET_ENCRYPTION_KEY (see readme.md)`);
|
49 | }
|
50 | }
|
51 |
|
52 | return { pattern: pattern, encKey, algorithm, del };
|
53 | }
|