Trimmed whitespace for AWS S3 credentials

If you input a name/key to a bucket with a trailing whitespace, it will
respect that trailing whitespace but will then fail to find the bucket.

To resolve this, added a util function to check if it's a string. If so
it will apply the `trim()` function to remove any unwanted whitespace,
else it will return `undefined`.
This commit is contained in:
Oliver de Sousa 2019-06-26 10:38:39 +01:00
parent 6159fd0d56
commit c3a989fcd3

View File

@ -10,6 +10,8 @@
const _ = require('lodash');
const AWS = require('aws-sdk');
const trimParam = str => typeof str === "string" ? str.trim() : undefined
module.exports = {
provider: 'aws-s3',
name: 'Amazon Web Service S3',
@ -55,15 +57,15 @@ module.exports = {
init: (config) => {
// configure AWS S3 bucket connection
AWS.config.update({
accessKeyId: config.public,
secretAccessKey: config.private,
accessKeyId: trimParam(config.public),
secretAccessKey: trimParam(config.private),
region: config.region
});
const S3 = new AWS.S3({
apiVersion: '2006-03-01',
params: {
Bucket: config.bucket
Bucket: trimParam(config.bucket)
}
});