UNPKG

@rikishi/secure-env

Version:
37 lines (31 loc) 1.04 kB
'use strict'; var cryptography = require('./cryptography'); var log = require('./utils/log'); var parser = require('./parser'); /* * Options Expected * secret - Specify the secret Key which was used during encryption of raw file.Having a salt-hashed secret key is recommended. * path - You can specify a custom path if your file containing environment variables is named or located differently. * enc_algo - You may specify the encryption algorithm for your file containing environment variables using this option. */ module.exports = function (options) { try { var decryptedContent = cryptography.decrypt({ secret: options.secret, file: options.path, decryptionAlgo: options.enc_algo }); if (decryptedContent) { var env = {}; var parsedObj = parser(decryptedContent); Object.keys(parsedObj).forEach(function (key) { if (!env.hasOwnProperty(key)) { env[key] = parsedObj[key]; } }); return env; } } catch (e) { log(e, 'error'); } };