Skip to content

Commit

Permalink
iss-5 - Removed references to region
Browse files Browse the repository at this point in the history
  • Loading branch information
aceew committed Mar 19, 2017
1 parent c457de7 commit 364eaf5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 39 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ import LambdaEnvVars from 'lambda-env-vars';
const lambdaEnvVars = new LambdaEnvVars({
location: 's3',
s3Config: {
region: 'eu-west-2',
bucketName: 'my-env-var-bucket',
fileName: 'my-env-var-filename.json',
},
Expand Down Expand Up @@ -107,7 +106,6 @@ Optionally the source of environment variables can be a JSON file within an S3 b
location: 's3',
s3Config: {
bucketName: 'name-of-bucket',
bucketRegion 'eu-west-2',
fileName: 'filename.json', // Name of the JSON file containing the env vars
},
}
Expand All @@ -120,7 +118,6 @@ The available attributes of the params object are as follows:
| location | string | 'lambdaConfig' | Can be 'lambdaConfig' or 's3'. The location the environment variables are stored.
| s3Config | object | {} | Required when location is equal to 's3'. Fields that specify the location of the env var JSON file |
| s3Config.bucketName | string | | The name of the bucket containing the env var file. |
| s3Config.bucketRegion | string | | The region of the bucket. |
| s3Config.fileName | string | | The file name of the env var JSON file. |


Expand Down
10 changes: 3 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default class LambdaEnvVars {
* Config used to get the an env var file from S3.
*
* @param {string} params.s3Config.bucketName
* @param {string} params.s3Config.bucketRegion
* @param {string} params.s3Config.fileName
*
* @return {Object}
Expand Down Expand Up @@ -72,7 +71,6 @@ export default class LambdaEnvVars {
* Config used to get the an env var file from S3.
*
* @param {string} params.s3Config.bucketName
* @param {string} params.s3Config.bucketRegion
* @param {string} params.s3Config.fileName
*
* @return {Promise}
Expand All @@ -83,7 +81,7 @@ export default class LambdaEnvVars {
return this.buildParams(params)
.then((builtParams) => {
if (builtParams.location === 's3') {
return this.getVarFromS3File(variableName, params.s3Config);
return this.getVarFromS3File(variableName, builtParams.s3Config);
}

if (this.decryptedVariables[variableName]) {
Expand Down Expand Up @@ -112,14 +110,13 @@ export default class LambdaEnvVars {
* Promise that resolves the variable name
*/
getVarFromS3File(variableName, s3Config) {
const fileKey = s3Config.bucketRegion + s3Config.bucketName + s3Config.fileName;
const fileKey = s3Config.bucketName + s3Config.fileName;

if (this.s3Vars[fileKey]) {
return Promise.resolve(this.s3Vars[fileKey][variableName]);
}

const s3Params = {
region: s3Config.bucketRegion,
Key: s3Config.fileName,
Bucket: s3Config.bucketName,
};
Expand Down Expand Up @@ -163,11 +160,10 @@ export default class LambdaEnvVars {
(
!params.s3Config ||
!params.s3Config.bucketName ||
!params.s3Config.bucketRegion ||
!params.s3Config.fileName
)
) {
const errorMessage = 's3Config.bucketName, s3Config.bucketRegion, s3Config.fileName are required when location is \'s3\'';
const errorMessage = 's3Config.bucketName and s3Config.fileName are required when location is \'s3\'';
return Promise.reject(new Error(errorMessage));
}

Expand Down
32 changes: 3 additions & 29 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,12 @@ test('Getting custom vars, uses s3 when the location is specified', (t) => {
const params = {
location: 's3',
s3Config: {
bucketRegion: 'eu-west-1',
bucketName: 'bucketName',
fileName: 'file-name-4.json',
},
};

const storedVarKey = params.s3Config.bucketRegion + params.s3Config.bucketName +
params.s3Config.fileName;
const storedVarKey = params.s3Config.bucketName + params.s3Config.fileName;

lambdaEnvVars.s3Vars[storedVarKey] = { variableName: 'value' };

Expand Down Expand Up @@ -186,22 +184,6 @@ test('Building request params: Rejects when s3Config is missing bucketName', (t)
const params = {
location: 's3',
s3Config: {
bucketRegion: 'bucketRegion',
fileName: 'fileName',
},
};

return lambdaEnvVars.buildParams(params)
.catch((error) => {
t.is(typeof error.message, 'string');
});
});

test('Building request params: Rejects when s3Config is missing bucketRegion', (t) => {
const params = {
location: 's3',
s3Config: {
bucketName: 'bucketName',
fileName: 'fileName',
},
};
Expand All @@ -217,7 +199,6 @@ test('Building request params: Rejects when s3Config is missing fileName', (t) =
location: 's3',
s3Config: {
bucketName: 'bucketName',
bucketRegion: 'bucketRegion',
},
};

Expand All @@ -232,7 +213,6 @@ test('Building request params: Resolves the params object', (t) => {
location: 's3',
s3Config: {
bucketName: 'bucketName',
bucketRegion: 'bucketRegion',
fileName: 'fileName',
},
};
Expand All @@ -255,13 +235,11 @@ test(
'Getting var from s3 file: Resolves undefined when the file is stored but variable is undefined',
(t) => {
const defaultS3Config = {
bucketRegion: 'eu-west-1',
fileName: 'file-name-1.json',
bucketName: 'bucketName',
};

const storedVarKey = defaultS3Config.bucketRegion + defaultS3Config.bucketName +
defaultS3Config.fileName;
const storedVarKey = defaultS3Config.bucketName + defaultS3Config.fileName;

lambdaEnvVars.s3Vars[storedVarKey] = {};

Expand All @@ -274,13 +252,11 @@ test(

test('Getting var from s3 file: Resolves var when the file is stored', (t) => {
const defaultS3Config = {
bucketRegion: 'eu-west-1',
bucketName: 'bucketName',
fileName: 'file-name-2.json',
};

const storedVarKey = defaultS3Config.bucketRegion + defaultS3Config.bucketName +
defaultS3Config.fileName;
const storedVarKey = defaultS3Config.bucketName + defaultS3Config.fileName;

lambdaEnvVars.s3Vars[storedVarKey] = { variableName: 'value' };

Expand All @@ -292,7 +268,6 @@ test('Getting var from s3 file: Resolves var when the file is stored', (t) => {

test('Getting var from s3 file: Rejects when the s3 file is not valid json', (t) => {
const defaultS3Config = {
bucketRegion: 'eu-west-1',
fileName: 'invalid-json.json',
bucketName: 'bucketName',
};
Expand All @@ -305,7 +280,6 @@ test('Getting var from s3 file: Rejects when the s3 file is not valid json', (t)

test('Getting var from s3 file: Resolves the file once fetched from S3', (t) => {
const defaultS3Config = {
bucketRegion: 'eu-west-1',
fileName: 'file-name-3.json',
bucketName: 'bucketName',
};
Expand Down

0 comments on commit 364eaf5

Please sign in to comment.