Skip to content

Commit 079c2f3

Browse files
committed
feat(endpoint): address PR style comments
1 parent 2d89568 commit 079c2f3

File tree

8 files changed

+40
-35
lines changed

8 files changed

+40
-35
lines changed

lib/lib-storage/src/Upload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
Tag,
1414
UploadPartCommand,
1515
} from "@aws-sdk/client-s3";
16-
import { EndpointResolvedConfig, getEndpointFromInstructions, toEndpointV1 } from "@aws-sdk/middleware-endpoint";
16+
import { getEndpointFromInstructions, toEndpointV1 } from "@aws-sdk/middleware-endpoint";
1717
import { HttpRequest } from "@aws-sdk/protocol-http";
1818
import { extendedEncodeURIComponent } from "@aws-sdk/smithy-client";
1919
import { Endpoint } from "@aws-sdk/types";

packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.ts renamed to packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@ import { EndpointResolvedConfig } from "../resolveEndpointConfig";
44
import { EndpointParameterInstructions } from "../types";
55

66
/**
7-
*
87
* This step in the endpoint resolution process is exposed as a function
98
* to allow certain packages such as s3 signer, lib-upload to get
109
* the V2 Endpoint associated to an instance of some (operation) command.
1110
*
1211
* @private
13-
*
1412
*/
1513
export const getEndpointFromInstructions = async (
1614
commandInput: any,
1715
instructionsSupplier: Partial<{
18-
instructions(): EndpointParameterInstructions;
16+
getEndpointParameterInstructions(): EndpointParameterInstructions;
1917
}>,
2018
clientConfig: Partial<EndpointResolvedConfig>,
2119
context?: HandlerExecutionContext
2220
): Promise<EndpointV2> => {
2321
const endpointParams: EndpointParameters = {};
24-
const instructions: EndpointParameterInstructions = (instructionsSupplier.instructions || (() => null))() || {};
22+
const instructions: EndpointParameterInstructions =
23+
(instructionsSupplier.getEndpointParameterInstructions || (() => null))() || {};
2524

2625
if (typeof clientConfig.endpointProvider !== "function") {
2726
throw new Error("config.endpointProvider is not set.");
@@ -52,7 +51,7 @@ export const getEndpointFromInstructions = async (
5251
* @private
5352
*/
5453
const createConfigProvider = (configKey: string, config: EndpointResolvedConfig & any) => {
55-
return async function configProvider() {
54+
const configProvider = async () => {
5655
if (!(configKey in config)) {
5756
throw new Error(`The config key ${configKey} was not found in the config object.`);
5857
}
@@ -62,4 +61,5 @@ const createConfigProvider = (configKey: string, config: EndpointResolvedConfig
6261
}
6362
return configValue;
6463
};
64+
return configProvider;
6565
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./getEndpointFromInstructions";
2+
export * from "./toEndpointV1";

packages/middleware-endpoint/src/endpointMiddleware.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
SerializeMiddleware,
1111
} from "@aws-sdk/types";
1212

13-
import { getEndpointFromInstructions } from "./adaptors/getEndpointFromConfig";
13+
import { getEndpointFromInstructions } from "./adaptors/getEndpointFromInstructions";
1414
import { EndpointResolvedConfig } from "./resolveEndpointConfig";
1515
import { EndpointParameterInstructions } from "./types";
1616

@@ -29,24 +29,29 @@ export const endpointMiddleware = ({
2929
context: HandlerExecutionContext
3030
): SerializeHandler<any, Output> =>
3131
async (args: SerializeHandlerArguments<any>): Promise<SerializeHandlerOutput<Output>> => {
32-
if (HttpRequest.isInstance(args.request)) {
33-
const { request } = args;
32+
if (!HttpRequest.isInstance(args.request)) {
33+
return next(args);
34+
}
35+
const { request } = args;
3436

35-
const endpoint: EndpointV2 = await getEndpointFromInstructions(args.input, instructions, config, context);
37+
const endpoint: EndpointV2 = await getEndpointFromInstructions(args.input, instructions, config, context);
3638

37-
context.endpointV2 = endpoint;
38-
context.authSchemes = endpoint.properties?.authSchemes;
39+
context.endpointV2 = endpoint;
40+
context.authSchemes = endpoint.properties?.authSchemes;
41+
42+
request.headers = Object.entries(endpoint.headers || {}).reduce(
43+
(headers, [name, values]) => ({
44+
...headers,
45+
[name]: values.join(","),
46+
}),
47+
{} as Record<string, string>
48+
);
49+
request.hostname = endpoint.url.hostname;
50+
request.path = endpoint.url.pathname;
51+
request.port = parseInt(endpoint.url.port);
52+
request.protocol = endpoint.url.protocol;
53+
request.query = parseQueryString(endpoint.url.search);
3954

40-
request.headers = Object.entries(endpoint.headers || {}).reduce((headers, [name, values]) => {
41-
headers[name] = values.join(",");
42-
return headers;
43-
}, {} as Record<string, string>);
44-
request.hostname = endpoint.url.hostname;
45-
request.path = endpoint.url.pathname;
46-
request.port = parseInt(endpoint.url.port);
47-
request.protocol = endpoint.url.protocol;
48-
request.query = parseQueryString(endpoint.url.search);
49-
}
5055
return next({
5156
...args,
5257
});

packages/middleware-endpoint/src/getEndpointPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { EndpointParameterInstructions } from "./types";
77
export const endpointMiddlewareOptions: SerializeHandlerOptions = {
88
step: "serialize",
99
tags: ["ENDPOINT_PARAMETERS", "ENDPOINT_V2", "ENDPOINT"],
10-
name: "endpointsV2Middleware",
10+
name: "endpointV2Middleware",
1111
override: true,
1212
};
1313

packages/middleware-endpoint/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
export * from "./adaptors/getEndpointFromConfig";
2-
export * from "./adaptors/toEndpointV1";
1+
export * from "./adaptors";
32
export * from "./endpointMiddleware";
43
export * from "./getEndpointPlugin";
54
export * from "./resolveEndpointConfig";

packages/middleware-endpoint/src/resolveEndpointConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { normalizeProvider } from "@aws-sdk/util-middleware";
44
import { toEndpointV1 } from "./adaptors/toEndpointV1";
55

66
/**
7-
* Endpoint config interfaces and resolver for Endpoints v2. They live in separate package to allow per-service onboarding.
8-
* When all services onboard the Endpoints v2, the resolver in config-resolver package can be removed.
7+
* Endpoint config interfaces and resolver for Endpoint v2. They live in separate package to allow per-service onboarding.
8+
* When all services onboard Endpoint v2, the resolver in config-resolver package can be removed.
99
* This interface includes all the endpoint parameters with built-in bindings of "AWS::*" and "SDK::*"
1010
*/
1111
export interface EndpointInputConfig<T extends EndpointParameters = EndpointParameters> {

packages/middleware-sdk-s3/src/configuration.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
*/
44
export interface S3InputConfig {
55
/**
6-
* Whether to force path style URLs for S3 objects (e.g., https://s3.amazonaws.com/<bucketName>/<key> instead of https://<bucketName>.s3.amazonaws.com/<key>
6+
* Whether to force path style URLs for S3 objects
7+
* (e.g., https://s3.amazonaws.com/<bucketName>/<key> instead of https://<bucketName>.s3.amazonaws.com/<key>
78
*/
89
forcePathStyle?: boolean;
910
/**
@@ -17,10 +18,8 @@ export interface S3ResolvedConfig {
1718
useAccelerateEndpoint: boolean;
1819
}
1920

20-
export function resolveS3Config<T>(input: T & S3InputConfig): T & S3ResolvedConfig {
21-
return {
22-
...input,
23-
forcePathStyle: input.forcePathStyle ?? false,
24-
useAccelerateEndpoint: input.useAccelerateEndpoint ?? false,
25-
};
26-
}
21+
export const resolveS3Config = <T>(input: T & S3InputConfig): T & S3ResolvedConfig => ({
22+
...input,
23+
forcePathStyle: input.forcePathStyle ?? false,
24+
useAccelerateEndpoint: input.useAccelerateEndpoint ?? false,
25+
});

0 commit comments

Comments
 (0)