-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
decryption specific file and create file #20
Conversation
@@ -14,7 +14,8 @@ const log = require('./utils/log') | |||
module.exports.decrypt = (options) => { | |||
try { | |||
const secret = options.secret || 'mySecret' | |||
const inputFile = options.file || '.env.enc' | |||
const inputFile = options.inputFile || '.env.enc' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would break https://github.com/kunalpanchal/secure-env/blob/master/lib/index.js#L18
Can we also update it there to send it as inputFile
instead of file
if (fs.existsSync(outputFilePath)) { | ||
fs.copyFileSync(outputFilePath, `${outputFilePath}.bak`) | ||
} | ||
fs.writeFileSync(outputFilePath, decrypted) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that this same function is used in https://github.com/kunalpanchal/secure-env/blob/master/lib/index.js
so we should not create or write any file if its used within the code.
All of this should only happen if the outputFilePath exists. Otherwise just log it the screen. If -o option is not sent via the CLI
@@ -14,7 +14,8 @@ const log = require('./utils/log') | |||
module.exports.decrypt = (options) => { | |||
try { | |||
const secret = options.secret || 'mySecret' | |||
const inputFile = options.file || '.env.enc' | |||
const inputFile = options.inputFile || '.env.enc' | |||
const outputFilePath = options.outputFile || inputFile.replace('.enc', '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const outputFilePath = options.outputFile || inputFile.replace('.enc', '') | |
const outputFilePath = options.outputFile |
Use the path only if specified explicitly lets not do the replace thing
@@ -28,7 +29,12 @@ module.exports.decrypt = (options) => { | |||
const decipher = crypto.createDecipheriv(decryptionAlgo, key, iv) | |||
let decrypted = decipher.update(ciphertext, 'hex', 'utf8') | |||
decrypted += decipher.final('utf8') | |||
return decrypted | |||
if (fs.existsSync(outputFilePath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not create a backup file in case the file exist instead throw an error and return.
} | ||
fs.writeFileSync(outputFilePath, decrypted) | ||
log(`The Environment file "${inputFile}" has been decrypted to "${outputFilePath}".`, 'info') | ||
log(`And then backup file "${inputFile}".bak.`, 'info') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not have the backup file option.
|
||
if (argv.decrypt || argv.d) log(cryptography.decrypt({secret, outputFile, encryptionAlgo}),'info') | ||
else cryptography.encrypt({ secret, inputFile, outputFile, encryptionAlgo }); | ||
if (argv.decrypt || argv.d) cryptography.decrypt({ secret, inputFile, outputFile, encryptionAlgo }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let the log be here, please do not remove it from here since we need the log to be happening only in case of cli. Not in the decrypt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the logging for decrypt should happen in this file and not in lib/cryptography.js
unless its an error.
Hey @sarawee thank you for this PR to address the issue regarding decryption using CLI. Appreciate the efforts. I have just added a few comments which needs to be addressed after which I will merge this PR and release a new version. |
No updates here |
I can't decryption by specific file with cli.
I was try
npx secure-env myEnvironment.enc -s mySecretPassword -d
found error "ERROR OCCURED .env.enc does not exist"Closes #12 #18 #19