diff --git a/lib/cli.js b/lib/cli.js index ecdcdf6..6020092 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -15,9 +15,10 @@ const inputFile = argv._[0] const secret = argv.secret || argv.s const encryptionAlgo = argv.algo || argv.a const environment = argv.env || argv.e +const folder = argv.folder const cryptography = require('./cryptography') -if (argv.decrypt || argv.d) log(cryptography.decrypt({secret, inputFile, outputFile, encryptionAlgo, environment}),'info') - else cryptography.encrypt({ secret, inputFile, outputFile, encryptionAlgo, environment }); +if (argv.decrypt || argv.d) log(cryptography.decrypt({ secret, inputFile, outputFile, encryptionAlgo, environment, folder }),'info') + else cryptography.encrypt({ secret, inputFile, outputFile, encryptionAlgo, environment, folder }); diff --git a/lib/cryptography.js b/lib/cryptography.js index c5cefdc..00fc7d1 100755 --- a/lib/cryptography.js +++ b/lib/cryptography.js @@ -9,6 +9,8 @@ const log = require('./utils/log') * --out | -o * --algo | -a * --decrypt | -d + * --env + * --folder currently in use only with --env. Do not suffix with / */ module.exports.decrypt = (options) => { @@ -17,12 +19,13 @@ module.exports.decrypt = (options) => { const decryptionAlgo = options.decryptionAlgo || 'aes256' const ivLength = options.ivLength || 16 const environment = options.environment; + const folder = options.folder ? `${options.folder}/` : ''; let outputFile = options.outputFile let inputFile = options.inputFile || '.env.enc' if(environment){ - outputFile = `.env.${environment}` - inputFile = `.env.${environment}.enc` + outputFile = `${folder}.env.${environment}` + inputFile = `${folder}.env.${environment}.enc` } if (!fs.existsSync(inputFile)) throw `${inputFile} does not exist.` @@ -58,12 +61,13 @@ module.exports.encrypt = (options) => { const secret = options.secret || 'mySecret' const encryptionAlgo = options.encryptionAlgo || 'aes256' const ivLength = options.ivLength || 16 + const folder = options.folder ? `${options.folder}/` : ''; let inputFile = options.inputFile || '.env' let outputFilePath = options.outputFile || `${inputFile}.enc` if(environment){ - inputFile = `.env.${environment}` - outputFilePath = `.env.${environment}.enc` + inputFile = `${folder}.env.${environment}` + outputFilePath = `${folder}.env.${environment}.enc` } // presumably createCipheriv() should work for all the algo in ./openssl_list-cipher-algorithms.csv with the right key/iv length