Skip to content

Commit a14cae7

Browse files
Allow credentials instead of key/secret for the S3 store (#282)
1 parent d89ed78 commit a14cae7

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ $ npm install tus-node-server
3030
```
3131

3232
- **Amazon S3**
33+
34+
using Key/Secret
3335
```js
3436
3537
server.datastore = new tus.S3Store({
@@ -41,6 +43,23 @@ $ npm install tus-node-server
4143
});
4244
```
4345

46+
using [credentials](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Credentials.html#constructor-property) to fetch credentials inside a AWS container, such as an ECS container, which will inject the required environment variables. The `credentials` config is directly passed into the AWS SDK so you can refer to the AWS docs for the supported values for `credentials`.
47+
48+
For example, with `ECSCredentials`:
49+
50+
```js
51+
server.datastore = new tus.S3Store({
52+
path: '/files',
53+
bucket: 'bucket-name',
54+
credentials: new AWS.ECSCredentials({
55+
httpOptions: { timeout: 5000 },
56+
maxRetries: 10,
57+
}),
58+
region: 'eu-west-1',
59+
partSize: 8 * 1024 * 1024, // each uploaded part will have ~8MB,
60+
tmpDirPrefix: 'tus-s3-store',
61+
});
62+
```
4463
## Quick Start
4564

4665
#### Use the [tus-node-deploy](https://hub.docker.com/r/bhstahl/tus-node-deploy/) Docker image

index.d.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { EventEmitter } from "events";
22
import * as http from "http";
3+
import { RemoteCredentials } from 'aws-sdk'
4+
35

46
declare interface Configstore {
57
get(key: string) : Promise<IFile | undefined> | IFile | undefined;
@@ -10,7 +12,7 @@ declare interface Configstore {
1012
declare interface ServerOptions {
1113
path: string;
1214
relativeLocation?: boolean;
13-
namingFunction?: () => string;
15+
namingFunction?: (req: http.IncomingMessage) => string;
1416
}
1517

1618
/**
@@ -30,10 +32,9 @@ declare interface GCStoreOptions extends DataStoreOptions {
3032
}
3133

3234
declare interface S3StoreOptions extends DataStoreOptions {
33-
accessKeyId: string;
34-
secretAccessKey: string;
3535
bucket: string;
3636
region?: string;
37+
tmpDirPrefix?: string;
3738
partSize: number;
3839
}
3940

@@ -97,7 +98,9 @@ export declare class GCSDataStore extends DataStore {
9798
* file store in AWS S3
9899
*/
99100
export declare class S3Store extends DataStore {
100-
constructor(options: S3StoreOptions);
101+
constructor(options: S3StoreOptions & { accessKeyId: string, secretAccessKey: string });
102+
constructor(options: S3StoreOptions & { credentials: RemoteCredentials });
103+
getOffset(file_id: string, with_parts?: boolean): Promise<any>;
101104
}
102105

103106
/**

lib/stores/S3Store.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ class S3Store extends DataStore {
5353

5454
this.extensions = ['creation', 'creation-with-upload', 'creation-defer-length'];
5555

56-
assert.ok(options.accessKeyId, '[S3Store] `accessKeyId` must be set');
57-
assert.ok(options.secretAccessKey, '[S3Store] `secretAccessKey` must be set');
56+
57+
if (options.accessKeyId || options.secretAccessKey) {
58+
assert.ok(options.accessKeyId, '[S3Store] `accessKeyId` must be set');
59+
assert.ok(options.secretAccessKey, '[S3Store] `secretAccessKey` must be set');
60+
}
61+
else {
62+
assert.ok(options.credentials, '[S3Store] `credentials` must be set');
63+
}
64+
5865
assert.ok(options.bucket, '[S3Store] `bucket` must be set');
5966

6067
this.bucket_name = options.bucket;

0 commit comments

Comments
 (0)