Allow setting region outside of endpoint (#16877)

This commit is contained in:
Rijk van Zanten
2022-12-21 17:08:54 -05:00
committed by GitHub
parent d2fae39372
commit 4e3215fb13
2 changed files with 23 additions and 0 deletions

View File

@@ -70,6 +70,7 @@ beforeEach(() => {
serverSideEncryption: randWord(),
root: randDirectoryPath(),
endpoint: randDomainName(),
region: randWord(),
},
path: {
input: randUnique() + randFilePath(),
@@ -203,6 +204,23 @@ describe('#constructor', () => {
});
});
test('Sets region', () => {
new DriverS3({
key: sample.config.key,
secret: sample.config.secret,
bucket: sample.config.bucket,
region: sample.config.region,
});
expect(S3Client).toHaveBeenCalledWith({
region: sample.config.region,
credentials: {
accessKeyId: sample.config.key,
secretAccessKey: sample.config.secret,
},
});
});
test('Normalizes config path when root is given', () => {
const mockRoot = randDirectoryPath();

View File

@@ -28,6 +28,7 @@ export type DriverS3Config = {
acl?: string;
serverSideEncryption?: string;
endpoint?: string;
region?: string;
};
export class DriverS3 implements Driver {
@@ -58,6 +59,10 @@ export class DriverS3 implements Driver {
s3ClientConfig.forcePathStyle = true;
}
if (config.region) {
s3ClientConfig.region = config.region;
}
this.client = new S3Client(s3ClientConfig);
this.bucket = config.bucket;
this.acl = config.acl;