Skip to content

Commit

Permalink
issue-1 - Added babel runtime to dependencies in order to return prom…
Browse files Browse the repository at this point in the history
…ises when the nev does not support them. Added ability to decrypt multiple env vars at once using kms
  • Loading branch information
aceew committed Jan 26, 2017
1 parent ccd1285 commit fd6c131
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"presets": [
"es2015"
],
"plugins": [
"transform-runtime"
]
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
},
"author": "Aaron Williams <a@aceew.me>",
"license": "ISC",
"dependencies": {},
"dependencies": {
"babel-runtime": "^6.6.1"
},
"devDependencies": {
"ava": "^0.17.0",
"aws-sdk": "^2.7.22",
Expand Down
25 changes: 25 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,31 @@ export default class LambdaEnvVars {
.then(result => this.setEncryptedVariable(variableName, result));
}

/**
* Decrypts a list of environment variables and returns them in an object where the keys are the
* env variable keys and the names are the decrypted values.
*
* @param {string[]} variableNames
* An array of environment variable keys to decrypt.
*
* @return {Promise}
* A promise that resolves an object containing the decrypted values where the keys are the items
* specified in the params variableNames.
*/
getCustomDecryptedValueList(variableNames = []) {
const decryptedVariablesObject = {};

const decryptedValuePromiseList = variableNames.map(envVar => (
this.getCustomDecryptedValue(envVar)
.then((decryptedValue) => {
decryptedVariablesObject[envVar] = decryptedValue;
})
));

return Promise.all(decryptedValuePromiseList)
.then(() => decryptedVariablesObject);
}

/**
* Sets the environment variable to the decryptedVariable object so it is cached per container.
*
Expand Down
25 changes: 25 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,28 @@ test('Setting a decrypted variable', (t) => {
const result = lambdaEnvVars.setEncryptedVariable(variableKey, value);
t.is(result, value);
});

test('Decrypting list of env vars returns a promise that resolves the values', (t) => {
const keys = ['keyName1', 'keyName2'];
keys.forEach((keyName) => {
lambdaEnvVars.process.env[keyName] = 'Some value';
});

return lambdaEnvVars.getCustomDecryptedValueList(keys)
.then((resultObject) => {
t.is(typeof resultObject, 'object');

keys.forEach((keyName) => {
t.is(resultObject[keyName], decryptedValueStub);
delete lambdaEnvVars.process.env[keyName];
});
});
});

test('Decrypting list of env vars when an empty array is specified, returns empty object', t => (
lambdaEnvVars.getCustomDecryptedValueList()
.then((result) => {
t.is(typeof result, 'object');
t.is(Object.keys(result).length, 0);
})
));
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,13 @@ babel-runtime@^6.0.0, babel-runtime@^6.11.6, babel-runtime@^6.18.0, babel-runtim
core-js "^2.4.0"
regenerator-runtime "^0.10.0"

babel-runtime@^6.6.1:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.22.0.tgz#1cf8b4ac67c77a4ddb0db2ae1f74de52ac4ca611"
dependencies:
core-js "^2.4.0"
regenerator-runtime "^0.10.0"

babel-template@^6.14.0, babel-template@^6.15.0, babel-template@^6.16.0, babel-template@^6.7.0, babel-template@^6.8.0:
version "6.16.0"
resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.16.0.tgz#e149dd1a9f03a35f817ddbc4d0481988e7ebc8ca"
Expand Down

0 comments on commit fd6c131

Please sign in to comment.