Skip to content

Commit 96c1b99

Browse files
authored
feat: add S3 and S3Control customizations for custom endpoints (#1993)
1 parent db87eef commit 96c1b99

14 files changed

+460
-263
lines changed

Diff for: packages/middleware-bucket-endpoint/src/bucketEndpointMiddleware.spec.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { bucketEndpointMiddleware } from "./bucketEndpointMiddleware";
1818

1919
describe("bucketEndpointMiddleware", () => {
2020
const input = { Bucket: "bucket" };
21+
const mockRegion = "us-foo-1";
2122
const requestInput = {
2223
method: "GET",
2324
headers: {},
@@ -27,10 +28,11 @@ describe("bucketEndpointMiddleware", () => {
2728
};
2829
const next = jest.fn();
2930
const previouslyResolvedConfig = {
30-
region: jest.fn().mockResolvedValue("us-foo-1"),
31+
isCustomEndpoint: false,
32+
region: jest.fn().mockResolvedValue(mockRegion),
3133
regionInfoProvider: jest
3234
.fn()
33-
.mockResolvedValue({ hostname: "foo.us-foo-2.amazonaws.com", partition: "aws-foo", signingRegion: "us-foo-1" }),
35+
.mockResolvedValue({ hostname: "foo.us-foo-2.amazonaws.com", partition: "aws-foo", signingRegion: mockRegion }),
3436
useArnRegion: jest.fn().mockResolvedValue(false),
3537
};
3638

@@ -61,10 +63,12 @@ describe("bucketEndpointMiddleware", () => {
6163
expect(param).toEqual({
6264
bucketName: input.Bucket,
6365
baseHostname: requestInput.hostname,
66+
clientRegion: mockRegion,
6467
accelerateEndpoint: false,
6568
dualstackEndpoint: false,
6669
pathStyleEndpoint: false,
6770
tlsCompatible: true,
71+
isCustomEndpoint: false,
6872
});
6973
});
7074

@@ -77,6 +81,7 @@ describe("bucketEndpointMiddleware", () => {
7781
useAccelerateEndpoint: true,
7882
useDualstackEndpoint: true,
7983
forcePathStyle: true,
84+
isCustomEndpoint: true,
8085
})
8186
)(next, {} as any);
8287
await handler({ input, request });
@@ -85,10 +90,12 @@ describe("bucketEndpointMiddleware", () => {
8590
expect(param).toEqual({
8691
bucketName: input.Bucket,
8792
baseHostname: requestInput.hostname,
93+
clientRegion: mockRegion,
8894
accelerateEndpoint: true,
8995
dualstackEndpoint: true,
9096
pathStyleEndpoint: true,
9197
tlsCompatible: false,
98+
isCustomEndpoint: true,
9299
});
93100
});
94101
});
@@ -118,13 +125,15 @@ describe("bucketEndpointMiddleware", () => {
118125
expect(param).toEqual({
119126
bucketName: mockBucketArn,
120127
baseHostname: requestInput.hostname,
128+
clientRegion: mockRegion,
121129
accelerateEndpoint: false,
122130
dualstackEndpoint: false,
123131
pathStyleEndpoint: false,
124132
tlsCompatible: true,
125133
clientPartition: "aws-foo",
126-
clientSigningRegion: "us-foo-1",
134+
clientSigningRegion: mockRegion,
127135
useArnRegion: false,
136+
isCustomEndpoint: false,
128137
});
129138
expect(previouslyResolvedConfig.region).toBeCalled();
130139
expect(previouslyResolvedConfig.regionInfoProvider).toBeCalled();
@@ -144,7 +153,7 @@ describe("bucketEndpointMiddleware", () => {
144153
request,
145154
});
146155
expect(previouslyResolvedConfig.regionInfoProvider).toBeCalled();
147-
expect(previouslyResolvedConfig.regionInfoProvider.mock.calls[0][0]).toBe("us-foo-1");
156+
expect(previouslyResolvedConfig.regionInfoProvider.mock.calls[0][0]).toBe(mockRegion);
148157
});
149158

150159
it("should supply bucketHostname in ARN object if bucket name string is a valid ARN", async () => {

Diff for: packages/middleware-bucket-endpoint/src/bucketEndpointMiddleware.ts

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export const bucketEndpointMiddleware = (options: BucketEndpointResolvedConfig):
4242
useArnRegion,
4343
clientPartition: partition,
4444
clientSigningRegion: signingRegion,
45+
clientRegion: clientRegion,
46+
isCustomEndpoint: options.isCustomEndpoint,
4547
});
4648

4749
// If the request needs to use a region or service name inferred from ARN that different from client region, we
@@ -56,13 +58,16 @@ export const bucketEndpointMiddleware = (options: BucketEndpointResolvedConfig):
5658
request.hostname = hostname;
5759
replaceBucketInPath = bucketEndpoint;
5860
} else {
61+
const clientRegion = getPseudoRegion(await options.region());
5962
const { hostname, bucketEndpoint } = bucketHostname({
6063
bucketName,
64+
clientRegion,
6165
baseHostname: request.hostname,
6266
accelerateEndpoint: options.useAccelerateEndpoint,
6367
dualstackEndpoint: options.useDualstackEndpoint,
6468
pathStyleEndpoint: options.forcePathStyle,
6569
tlsCompatible: request.protocol === "https:",
70+
isCustomEndpoint: options.isCustomEndpoint,
6671
});
6772

6873
request.hostname = hostname;

0 commit comments

Comments
 (0)