Skip to content

Commit

Permalink
Merge pull request #6 from darkflare42/features/add-folder
Browse files Browse the repository at this point in the history
  • Loading branch information
orkeren21 authored Jan 3, 2021
2 parents ec7beb7 + e2fce96 commit 2805088
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
12 changes: 8 additions & 4 deletions lib/cryptography.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const log = require('./utils/log')
* --out <file-path> | -o <file-path>
* --algo <algoName> | -a <algoName>
* --decrypt | -d
* --env <environment>
* --folder <folder-where-encrypted-decrypted-files-live> currently in use only with --env. Do not suffix with /
*/

module.exports.decrypt = (options) => {
Expand All @@ -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.`
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2805088

Please sign in to comment.