tus-node-server icon indicating copy to clipboard operation
tus-node-server copied to clipboard

S3Store: Add other strategies on passing credentials when initializing a S3Store

Open phillip-causing opened this issue 1 year ago • 3 comments

We are planning to use and run this library using AWS Fargate. In AWS there are multiple ways to pass a credentials to aws-sdk https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html Here is what we want 4. Credentials loaded from the ECS credentials provider (if applicable)

But the current implementation of the library is forcing us to provide the accessKeyId and secretAccessKey because of the assertion on the constructor of S3Store class. https://github.com/tus/tus-node-server/blob/master/lib/stores/S3Store.js#L58

assert.ok(options.accessKeyId, '[S3Store] `accessKeyId` must be set');
assert.ok(options.secretAccessKey, '[S3Store] `secretAccessKey` must be set');`

What we want to achieve is to make those properties optional and add another new property credentials So that we can initialize it like this

server.datastore = new tus.S3Store({
  path: '/',
  bucket: 'my-bucket',
  credentials: new AWS.ECSCredentials({
    httpOptions: { timeout: 5000 },
    maxRetries: 10,
    retryDelayOptions: { base: 200 },
  }),
  region: 'use-east-1',
  partSize: 8 * 1024 * 1024,
});

phillip-causing avatar Aug 08 '22 01:08 phillip-causing

Hi, I'm open to this idea. I see this should also automatically work as we pass all options into new aws.S3(). However, we should make sure we create proper TypeScript types that make sure that either credentials or accessKeyId/secretAccessKey are set.

Murderlon avatar Aug 09 '22 13:08 Murderlon

Are you willing to reopen your PR for this with the added types?

Murderlon avatar Aug 09 '22 13:08 Murderlon

Are you willing to reopen your PR for this with the added types?

Here's the new PR

phillip-causing avatar Aug 10 '22 00:08 phillip-causing

Any plan on merging that PR? We're interested in a similar use case (running in EKS cluster). Thanks.

terracota-p avatar Nov 18 '22 16:11 terracota-p

I can merge it and do a 0.x release

Murderlon avatar Nov 18 '22 17:11 Murderlon

Released: https://github.com/tus/tus-node-server/releases/tag/v0.9.0

Murderlon avatar Nov 18 '22 17:11 Murderlon

That was super fast, thank you!

terracota-p avatar Nov 18 '22 17:11 terracota-p