2019-07-28 02:49:02 +02:00
|
|
|
import * as S3 from 'aws-sdk/clients/s3';
|
|
|
|
import config from '../../config';
|
|
|
|
import { Meta } from '../../models/entities/meta';
|
2020-03-14 03:33:19 +01:00
|
|
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
2019-07-28 02:49:02 +02:00
|
|
|
import * as agentkeepalive from 'agentkeepalive';
|
|
|
|
|
|
|
|
const httpsAgent = config.proxy
|
2020-03-14 03:33:19 +01:00
|
|
|
? new HttpsProxyAgent(config.proxy)
|
2019-07-28 02:49:02 +02:00
|
|
|
: new agentkeepalive.HttpsAgent({
|
|
|
|
freeSocketTimeout: 30 * 1000
|
|
|
|
});
|
|
|
|
|
|
|
|
export function getS3(meta: Meta) {
|
|
|
|
const conf = {
|
2020-03-14 03:33:19 +01:00
|
|
|
endpoint: meta.objectStorageEndpoint || undefined,
|
2019-07-28 02:49:02 +02:00
|
|
|
accessKeyId: meta.objectStorageAccessKey,
|
|
|
|
secretAccessKey: meta.objectStorageSecretKey,
|
2020-03-14 03:33:19 +01:00
|
|
|
region: meta.objectStorageRegion || undefined,
|
2019-07-28 02:49:02 +02:00
|
|
|
sslEnabled: meta.objectStorageUseSSL,
|
2020-03-14 03:33:19 +01:00
|
|
|
s3ForcePathStyle: !!meta.objectStorageEndpoint,
|
2019-07-28 02:49:02 +02:00
|
|
|
httpOptions: {
|
|
|
|
}
|
|
|
|
} as S3.ClientConfiguration;
|
|
|
|
|
|
|
|
if (meta.objectStorageUseSSL) {
|
|
|
|
conf.httpOptions!.agent = httpsAgent;
|
|
|
|
}
|
|
|
|
|
|
|
|
const s3 = new S3(conf);
|
|
|
|
|
|
|
|
return s3;
|
|
|
|
}
|