UNPKG

1.82 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3Object.defineProperty(exports, "__esModule", { value: true });
4const yargs = require("yargs");
5const colors_1 = require("../colors");
6const script_1 = require("../script");
7const secrets_decrypt_util_1 = require("../secret/secrets-decrypt.util");
8script_1.runScript(() => {
9 const { dir, encKey, algorithm, del } = getDecryptCLIOptions();
10 secrets_decrypt_util_1.secretsDecrypt(dir, encKey, algorithm, del);
11});
12function getDecryptCLIOptions() {
13 require('dotenv').config();
14 let { dir, encKey, encKeyVar, algorithm, del } = yargs.options({
15 dir: {
16 type: 'array',
17 desc: 'Directory with secrets. Can be many',
18 // demandOption: true,
19 default: './secret',
20 },
21 encKey: {
22 type: 'string',
23 desc: 'Encryption key',
24 // demandOption: true,
25 // default: process.env.SECRET_ENCRYPTION_KEY!,
26 },
27 encKeyVar: {
28 type: 'string',
29 desc: 'Env variable name to get `encKey` from.',
30 default: 'SECRET_ENCRYPTION_KEY',
31 },
32 algorithm: {
33 type: 'string',
34 default: 'aes-256-cbc',
35 },
36 del: {
37 type: 'boolean',
38 desc: 'Delete source files after encryption/decryption. Be careful!',
39 },
40 }).argv;
41 if (!encKey) {
42 encKey = process.env[encKeyVar];
43 if (encKey) {
44 console.log(`using encKey from env.${colors_1.dimGrey(encKeyVar)}`);
45 }
46 else {
47 throw new Error(`encKey is required. Can be provided as --encKey or env.SECRET_ENCRYPTION_KEY (see readme.md)`);
48 }
49 }
50 // `as any` because @types/yargs can't handle string[] type properly
51 return { dir: dir, encKey, algorithm, del };
52}