From d83c8bfae9994c89a5ae8450c5e6349d9ca95ea3 Mon Sep 17 00:00:00 2001 From: bradleyfowler123 Date: Fri, 13 Sep 2019 17:19:09 +0100 Subject: [PATCH] Resolves #35 (#36) --- index.js | 52 +++++++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/index.js b/index.js index 74b37b7..068c912 100644 --- a/index.js +++ b/index.js @@ -7,18 +7,19 @@ var s3 = require('s3'); function S3Zipper(awsConfig) { var self = this - AWS.config.getCredentials(function (err) { - if (err) { - assert.ok(awsConfig, 'AWS S3 options must be defined.'); - assert.notEqual(awsConfig.accessKeyId, undefined, 'Requires S3 AWS Key.'); - assert.notEqual(awsConfig.secretAccessKey, undefined, 'Requires S3 AWS Secret'); - assert.notEqual(awsConfig.region, undefined, 'Requires AWS S3 region.'); - assert.notEqual(awsConfig.bucket, undefined, 'Requires AWS S3 bucket.'); - self.init(awsConfig); - } else { - self.init(awsConfig) - } - }) + assert.ok(awsConfig, 'AWS S3 options must be defined.'); + assert.notEqual(awsConfig.accessKeyId, undefined, 'Requires S3 AWS Key.'); + assert.notEqual(awsConfig.secretAccessKey, undefined, 'Requires S3 AWS Secret'); + assert.notEqual(awsConfig.region, undefined, 'Requires AWS S3 region.'); + assert.notEqual(awsConfig.bucket, undefined, 'Requires AWS S3 bucket.'); + + AWS.config.update({ + accessKeyId: awsConfig.accessKeyId, + secretAccessKey: awsConfig.secretAccessKey, + region: awsConfig.region + }); + + self.init(awsConfig); } @@ -31,30 +32,11 @@ S3Zipper.prototype = { init: function (awsConfig) { this.awsConfig = awsConfig; var self = this - AWS.config.getCredentials(function (err) { - - if (err) { - AWS.config.update({ - accessKeyId: awsConfig.accessKeyId, - secretAccessKey: awsConfig.secretAccessKey, - region: awsConfig.region - }); - } - - if (awsConfig.endpoint) { - AWS.config.update({ - endpoint: awsConfig.endpoint - }); + self.s3bucket = new AWS.S3({ + params: { + Bucket: self.awsConfig.bucket } - - self.s3bucket = new AWS.S3({ - params: { - Bucket: self.awsConfig.bucket - } - }); - - }) - + }); } , filterOutFiles: function (fileObj) { return fileObj;