Explorar el Código

Add S3 options: httpOptions, maxRetries

Eric Mc Sween hace 6 años
padre
commit
6521837993

+ 2 - 0
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
 

+ 6 - 0
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
   }
 

+ 15 - 0
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