Make forcePathStyle configurable (#17081)

* Make forcePathStyle configurable

Defaulting to true when an endpoint was provided caused issues.

* Fix test setup
This commit is contained in:
Rijk van Zanten
2023-01-10 17:40:48 -05:00
committed by GitHub
parent bc41307f00
commit 874dda8078
2 changed files with 24 additions and 4 deletions

View File

@@ -12,6 +12,7 @@ import { normalizePath } from '@directus/utils';
import { isReadableStream } from '@directus/utils/node';
import {
randAlphaNumeric,
randBoolean,
randDirectoryPath,
randDomainName,
randFilePath,
@@ -71,6 +72,7 @@ beforeEach(() => {
root: randDirectoryPath(),
endpoint: randDomainName(),
region: randWord(),
forcePathStyle: randBoolean(),
},
path: {
input: randUnique() + randFilePath(),
@@ -192,7 +194,6 @@ describe('#constructor', () => {
});
expect(S3Client).toHaveBeenCalledWith({
forcePathStyle: true,
endpoint: {
hostname: sampleDomain,
protocol: 'http:',
@@ -217,7 +218,6 @@ describe('#constructor', () => {
});
expect(S3Client).toHaveBeenCalledWith({
forcePathStyle: true,
endpoint: {
hostname: sampleDomain,
protocol: 'https:',
@@ -247,6 +247,23 @@ describe('#constructor', () => {
});
});
test('Sets force path style', () => {
new DriverS3({
key: sample.config.key,
secret: sample.config.secret,
bucket: sample.config.bucket,
forcePathStyle: sample.config.forcePathStyle,
});
expect(S3Client).toHaveBeenCalledWith({
forcePathStyle: sample.config.forcePathStyle,
credentials: {
accessKeyId: sample.config.key,
secretAccessKey: sample.config.secret,
},
});
});
test('Normalizes config path when root is given', () => {
const mockRoot = randDirectoryPath();

View File

@@ -29,6 +29,7 @@ export type DriverS3Config = {
serverSideEncryption?: string;
endpoint?: string;
region?: string;
forcePathStyle?: boolean;
};
export class DriverS3 implements Driver {
@@ -61,14 +62,16 @@ export class DriverS3 implements Driver {
protocol,
path: '/',
};
s3ClientConfig.forcePathStyle = true;
}
if (config.region) {
s3ClientConfig.region = config.region;
}
if (config.forcePathStyle !== undefined) {
s3ClientConfig.forcePathStyle = config.forcePathStyle;
}
this.client = new S3Client(s3ClientConfig);
this.bucket = config.bucket;
this.acl = config.acl;