mirror of
https://github.com/directus/directus.git
synced 2026-01-27 02:37:56 -05:00
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:
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user