Skip to content

Commit 851e12b

Browse files
committed
chore: store endpointDiscoveryId in an optional param instead of function
1 parent 1b16c26 commit 851e12b

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

packages/middleware-endpoint-discovery/src/getCacheKey.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ import { AwsAuthResolvedConfig } from "@aws-sdk/middleware-signing";
77
export const getCacheKey = async (
88
commandName: string,
99
config: AwsAuthResolvedConfig & RegionResolvedConfig,
10-
getEndpointDiscoveryId: () => string | undefined
10+
options: {
11+
endpointDiscoveryId?: string;
12+
}
1113
) => {
1214
const region = await config.region();
1315
const { accessKeyId } = await config.credentials();
14-
const identifiers = getEndpointDiscoveryId ? getEndpointDiscoveryId() : undefined;
16+
const { endpointDiscoveryId } = options;
1517
return {
1618
commandName,
1719
...(region && { region }),
1820
...(accessKeyId && { accessKeyId }),
19-
...(identifiers && { identifiers }),
21+
...(endpointDiscoveryId && { endpointDiscoveryId }),
2022
}.toString();
2123
};

packages/middleware-endpoint-discovery/src/getEndpointDiscoveryCommandPlugin.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const endpointDiscoveryMiddlewareOptions: FinalizeRequestHandlerOptions =
2323

2424
export type EndpointDiscoveryMiddlewareConfig = {
2525
isDiscoveredEndpointRequired: boolean;
26-
getEndpointDiscoveryId: () => string | undefined;
26+
endpointDiscoveryId?: string;
2727
};
2828

2929
export const endpointDiscoveryMiddleware = (
@@ -37,7 +37,7 @@ export const endpointDiscoveryMiddleware = (
3737
): Promise<FinalizeHandlerOutput<Output>> => {
3838
const { client } = config;
3939
const { endpointDiscoveryCommandCtor } = client?.config;
40-
const { isDiscoveredEndpointRequired, getEndpointDiscoveryId } = middlewareConfig;
40+
const { isDiscoveredEndpointRequired, endpointDiscoveryId } = middlewareConfig;
4141
const { commandName } = context;
4242

4343
if (isDiscoveredEndpointRequired === true) {
@@ -46,20 +46,20 @@ export const endpointDiscoveryMiddleware = (
4646
await updateDiscoveredEndpointInCache(config, {
4747
commandName,
4848
endpointDiscoveryCommandCtor,
49-
getEndpointDiscoveryId,
49+
endpointDiscoveryId,
5050
});
5151
} else if (isDiscoveredEndpointRequired === false) {
5252
// Do not call await await on Endpoint Discovery API utility so that function
5353
// does not block, the command will use discovered endpoint, if available.
5454
updateDiscoveredEndpointInCache(config, {
5555
commandName,
5656
endpointDiscoveryCommandCtor,
57-
getEndpointDiscoveryId,
57+
endpointDiscoveryId,
5858
});
5959
}
6060

6161
const { request } = args;
62-
const cacheKey = await getCacheKey(commandName, client?.config, getEndpointDiscoveryId);
62+
const cacheKey = await getCacheKey(commandName, client?.config, { endpointDiscoveryId });
6363
if (cacheKey && HttpRequest.isInstance(request)) {
6464
const endpoints = client?.config.endpointCache.get(cacheKey);
6565
if (endpoints && endpoints.length > 0) {

packages/middleware-endpoint-discovery/src/updateDiscoveredEndpointInCache.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { EndpointDiscoveryClientResolvedConfig } from "./resolveEndpointDiscover
66
export type updateDiscoveredEndpointInCacheOptions = {
77
commandName: string;
88
endpointDiscoveryCommandCtor: new (comandConfig: any) => Command<any, any, any, any, any>;
9-
getEndpointDiscoveryId: () => string | undefined;
9+
endpointDiscoveryId?: string;
1010
};
1111

1212
export const updateDiscoveredEndpointInCache = async (
@@ -16,8 +16,8 @@ export const updateDiscoveredEndpointInCache = async (
1616
const { client } = config;
1717
const { endpointCache } = client?.config;
1818

19-
const { commandName, getEndpointDiscoveryId } = options;
20-
const cacheKey = await getCacheKey(commandName, client?.config, getEndpointDiscoveryId);
19+
const { commandName, endpointDiscoveryId } = options;
20+
const cacheKey = await getCacheKey(commandName, client?.config, { endpointDiscoveryId });
2121

2222
const endpoints = endpointCache.get(cacheKey);
2323
if (endpoints && endpoints.length === 1 && endpoints[0].Address === "") {
@@ -40,7 +40,7 @@ export const updateDiscoveredEndpointInCache = async (
4040
try {
4141
const command = new options.endpointDiscoveryCommandCtor({
4242
Operation: commandName.substr(0, commandName.length - 7), // strip "Command"
43-
Identifiers: getEndpointDiscoveryId ? getEndpointDiscoveryId() : undefined,
43+
Identifiers: endpointDiscoveryId,
4444
});
4545
const { Endpoints } = await client?.send(command);
4646
endpointCache.set(cacheKey, Endpoints);

0 commit comments

Comments
 (0)