From 6521837993412c2f96b98ac3d33689e5a828765e Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Thu, 9 Jul 2020 14:01:13 -0400 Subject: [PATCH] Add S3 options: httpOptions, maxRetries --- libraries/object-persistor/README.md | 2 ++ libraries/object-persistor/src/S3Persistor.js | 6 ++++++ .../test/unit/S3PersistorTests.js | 15 +++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/libraries/object-persistor/README.md b/libraries/object-persistor/README.md index 1d854e3fec..3e33686fb0 100644 --- a/libraries/object-persistor/README.md +++ b/libraries/object-persistor/README.md @@ -264,6 +264,8 @@ For the `FS` persistor, the `bucketName` should be the full path to the folder o - `s3.key` (required): The AWS access key ID - `s3.secret` (required): The AWS secret access key - `s3.partSize`: The part size for S3 uploads. Defaults to 100 megabytes. +- `s3.httpOptions`: HTTP options passed directly to the [S3 constructor](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property). +- `s3.maxRetries`: The number of times the S3 client will retry in case of an error - `s3.endpoint`: For testing - overrides the S3 endpoint to use a different service (e.g. a fake S3 server) - `s3.pathStyle`: For testing - use old path-style URLs, for services that do not support subdomain-based access diff --git a/libraries/object-persistor/src/S3Persistor.js b/libraries/object-persistor/src/S3Persistor.js index 75619bd22a..d3477d0bf5 100644 --- a/libraries/object-persistor/src/S3Persistor.js +++ b/libraries/object-persistor/src/S3Persistor.js @@ -361,6 +361,12 @@ module.exports = class S3Persistor extends AbstractPersistor { options.s3ForcePathStyle = true } + for (const opt of ['httpOptions', 'maxRetries']) { + if (this.settings[opt]) { + options[opt] = this.settings[opt] + } + } + return options } diff --git a/libraries/object-persistor/test/unit/S3PersistorTests.js b/libraries/object-persistor/test/unit/S3PersistorTests.js index a71282a56e..a3f8ff4316 100644 --- a/libraries/object-persistor/test/unit/S3PersistorTests.js +++ b/libraries/object-persistor/test/unit/S3PersistorTests.js @@ -265,6 +265,21 @@ describe('S3PersistorTests', function () { }) }) + describe('when given S3 options', function () { + const httpOptions = { timeout: 2000 } + const maxRetries = 2 + + beforeEach(async function () { + settings.httpOptions = httpOptions + settings.maxRetries = maxRetries + await S3Persistor.getObjectStream(bucket, key) + }) + + it('configures the S3 client appropriately', function () { + expect(S3).to.have.been.calledWithMatch({ httpOptions, maxRetries }) + }) + }) + describe("when the file doesn't exist", function () { let error, stream