Skip to content

Commit e1426dd

Browse files
author
Chase Coalwell
committed
feat: remove $ input options
1 parent 604b7d5 commit e1426dd

File tree

3 files changed

+16
-128
lines changed

3 files changed

+16
-128
lines changed

packages/middleware-bucket-endpoint/src/bucketEndpointMiddleware.spec.ts

Lines changed: 6 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -54,39 +54,6 @@ describe("bucketEndpointMiddleware", () => {
5454
expect(path).toBe("/bucket");
5555
});
5656

57-
it("should not convert the request provided into one directed to a virtual hosted-style endpoint if so directed on the input", async () => {
58-
const request = new HttpRequest(requestInput);
59-
const handler = bucketEndpointMiddleware(resolveBucketEndpointConfig({}))(
60-
next,
61-
{} as any
62-
);
63-
await handler({ input: { ...input, $forcePathStyle: true }, request });
64-
65-
const {
66-
request: { hostname, path }
67-
} = next.mock.calls[0][0];
68-
69-
expect(hostname).toBe("s3.us-west-2.amazonaws.com");
70-
expect(path).toBe("/bucket");
71-
});
72-
73-
it("should convert the request provided into one directed to a virtual hosted-style endpoint if path-style is disabled on the input", async () => {
74-
const request = new HttpRequest(requestInput);
75-
const handler = bucketEndpointMiddleware(
76-
resolveBucketEndpointConfig({
77-
forcePathStyle: true
78-
})
79-
)(next, {} as any);
80-
await handler({ input: { ...input, $forcePathStyle: false }, request });
81-
82-
const {
83-
request: { hostname, path }
84-
} = next.mock.calls[0][0];
85-
86-
expect(hostname).toBe("bucket.s3.us-west-2.amazonaws.com");
87-
expect(path).toBe("/");
88-
});
89-
9057
it("should not convert the request provided into one without the bucket in the path if so configured", async () => {
9158
const request = new HttpRequest(requestInput);
9259
const handler = bucketEndpointMiddleware(
@@ -111,12 +78,13 @@ describe("bucketEndpointMiddleware", () => {
11178

11279
it("should use the bucket name as a virtual hosted-style endpoint if so configured", async () => {
11380
const request = new HttpRequest(requestInput);
114-
const handler = bucketEndpointMiddleware(resolveBucketEndpointConfig({}))(
115-
next,
116-
{} as any
117-
);
81+
const handler = bucketEndpointMiddleware(
82+
resolveBucketEndpointConfig({
83+
bucketEndpoint: true
84+
})
85+
)(next, {} as any);
11886
await handler({
119-
input: { Bucket: "files.domain.com", $bucketEndpoint: true },
87+
input: { Bucket: "files.domain.com" },
12088
request: { ...request, path: "/files.domain.com/path/to/key.ext" }
12189
});
12290

@@ -147,45 +115,6 @@ describe("bucketEndpointMiddleware", () => {
147115
expect(path).toBe("/");
148116
});
149117

150-
it("should use a transfer acceleration endpoint if so directed on the input", async () => {
151-
const request = new HttpRequest(requestInput);
152-
const handler = bucketEndpointMiddleware(resolveBucketEndpointConfig({}))(
153-
next,
154-
{} as any
155-
);
156-
await handler({
157-
input: { ...input, $useAccelerateEndpoint: true },
158-
request
159-
});
160-
161-
const {
162-
request: { hostname, path }
163-
} = next.mock.calls[0][0];
164-
165-
expect(hostname).toBe("bucket.s3-accelerate.amazonaws.com");
166-
expect(path).toBe("/");
167-
});
168-
169-
it("should not use a transfer acceleration endpoint if disabled on the input", async () => {
170-
const request = new HttpRequest(requestInput);
171-
const handler = bucketEndpointMiddleware(
172-
resolveBucketEndpointConfig({
173-
useAccelerateEndpoint: true
174-
})
175-
)(next, {} as any);
176-
await handler({
177-
input: { ...input, $useAccelerateEndpoint: false },
178-
request
179-
});
180-
181-
const {
182-
request: { hostname, path }
183-
} = next.mock.calls[0][0];
184-
185-
expect(hostname).toBe("bucket.s3.us-west-2.amazonaws.com");
186-
expect(path).toBe("/");
187-
});
188-
189118
it("should use a dualstack endpoint if so configured", async () => {
190119
const request = new HttpRequest(requestInput);
191120
const handler = bucketEndpointMiddleware(
@@ -205,45 +134,6 @@ describe("bucketEndpointMiddleware", () => {
205134
expect(path).toBe("/");
206135
});
207136

208-
it("should use a dualstack endpoint if so directed on the input", async () => {
209-
const request = new HttpRequest(requestInput);
210-
const handler = bucketEndpointMiddleware(resolveBucketEndpointConfig({}))(
211-
next,
212-
{} as any
213-
);
214-
await handler({
215-
input: { ...input, $useDualstackEndpoint: true },
216-
request
217-
});
218-
219-
const {
220-
request: { hostname, path }
221-
} = next.mock.calls[0][0];
222-
223-
expect(hostname).toBe("bucket.s3.dualstack.us-west-2.amazonaws.com");
224-
expect(path).toBe("/");
225-
});
226-
227-
it("should not use a dualstack endpoint if disabled on the input", async () => {
228-
const request = new HttpRequest(requestInput);
229-
const handler = bucketEndpointMiddleware(
230-
resolveBucketEndpointConfig({
231-
useDualstackEndpoint: true
232-
})
233-
)(next, {} as any);
234-
await handler({
235-
input: { ...input, $useDualstackEndpoint: false },
236-
request
237-
});
238-
239-
const {
240-
request: { hostname, path }
241-
} = next.mock.calls[0][0];
242-
243-
expect(hostname).toBe("bucket.s3.us-west-2.amazonaws.com");
244-
expect(path).toBe("/");
245-
});
246-
247137
it("should use an accelerate dualstack endpoint if configured", async () => {
248138
const request = new HttpRequest(requestInput);
249139
const handler = bucketEndpointMiddleware(

packages/middleware-bucket-endpoint/src/bucketEndpointMiddleware.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,20 @@ export function bucketEndpointMiddleware(
1919
): BuildHandler<any, Output> => async (
2020
args: BuildHandlerArguments<any>
2121
): Promise<BuildHandlerOutput<Output>> => {
22-
const {
23-
Bucket: bucketName,
24-
$bucketEndpoint,
25-
$forcePathStyle = options.forcePathStyle,
26-
$useAccelerateEndpoint = options.useAccelerateEndpoint,
27-
$useDualstackEndpoint = options.useDualstackEndpoint
28-
} = args.input;
22+
const { Bucket: bucketName } = args.input;
2923
let replaceBucketInPath =
30-
options.preformedBucketEndpoint || $bucketEndpoint;
24+
options.preformedBucketEndpoint || options.bucketEndpoint;
3125
let request = args.request;
3226
if (HttpRequest.isInstance(request)) {
33-
if ($bucketEndpoint) {
27+
if (options.bucketEndpoint) {
3428
request.hostname = bucketName;
3529
} else if (!options.preformedBucketEndpoint) {
3630
const { hostname, bucketEndpoint } = bucketHostname({
3731
bucketName,
3832
baseHostname: request.hostname,
39-
accelerateEndpoint: $useAccelerateEndpoint,
40-
dualstackEndpoint: $useDualstackEndpoint,
41-
pathStyleEndpoint: $forcePathStyle,
33+
accelerateEndpoint: options.useAccelerateEndpoint,
34+
dualstackEndpoint: options.useDualstackEndpoint,
35+
pathStyleEndpoint: options.forcePathStyle,
4236
sslCompatible: request.protocol === "https:"
4337
});
4438

packages/middleware-bucket-endpoint/src/configurations.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
export interface BucketEndpointInputConfig {
2+
bucketEndpoint?: boolean;
23
forcePathStyle?: boolean;
34
preformedBucketEndpoint?: boolean;
45
useAccelerateEndpoint?: boolean;
56
useDualstackEndpoint?: boolean;
67
}
78

89
export interface BucketEndpointResolvedConfig {
10+
bucketEndpoint: boolean;
911
forcePathStyle: boolean;
1012
preformedBucketEndpoint: boolean;
1113
useAccelerateEndpoint: boolean;
@@ -15,6 +17,7 @@ export interface BucketEndpointResolvedConfig {
1517
export function resolveBucketEndpointConfig<T>(
1618
input: T & BucketEndpointInputConfig
1719
): T & BucketEndpointResolvedConfig {
20+
const bucketEndpoint = input.bucketEndpoint ? input.bucketEndpoint : false;
1821
const forcePathStyle = input.forcePathStyle ? input.forcePathStyle : false;
1922
const preformedBucketEndpoint = input.preformedBucketEndpoint
2023
? input.preformedBucketEndpoint
@@ -27,6 +30,7 @@ export function resolveBucketEndpointConfig<T>(
2730
: false;
2831
return {
2932
...input,
33+
bucketEndpoint,
3034
forcePathStyle,
3135
preformedBucketEndpoint,
3236
useAccelerateEndpoint,

0 commit comments

Comments
 (0)