Skip to content

Commit df957fe

Browse files
mtdowlingsrchase
authored andcommitted
feat: start endpoint resolver generation (#472)
1 parent 20d6ea6 commit df957fe

File tree

4 files changed

+69
-62
lines changed

4 files changed

+69
-62
lines changed

packages/config-resolver/src/EndpointsConfig.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Provider, UrlParser, Endpoint } from "@aws-sdk/types";
1+
import {
2+
Provider,
3+
UrlParser,
4+
Endpoint,
5+
RegionInfoProvider,
6+
RegionInfo
7+
} from "@aws-sdk/types";
28

39
export function normalizeEndpoint(
410
endpoint?: string | Endpoint | Provider<Endpoint>,
@@ -20,20 +26,15 @@ export interface EndpointsInputConfig {
2026
*/
2127
endpoint?: string | Endpoint | Provider<Endpoint>;
2228

23-
/**
24-
* The endpoint provider to call if no endpoint is provided
25-
*/
26-
endpointProvider?: any;
27-
2829
/**
2930
* Whether TLS is enabled for requests.
3031
*/
3132
tls?: boolean;
3233
}
3334
interface PreviouslyResolved {
35+
regionInfoProvider: RegionInfoProvider;
3436
urlParser: UrlParser;
3537
region: Provider<string>;
36-
service: string;
3738
}
3839
export interface EndpointsResolvedConfig
3940
extends Required<EndpointsInputConfig> {
@@ -43,18 +44,21 @@ export function resolveEndpointsConfig<T>(
4344
input: T & EndpointsInputConfig & PreviouslyResolved
4445
): T & EndpointsResolvedConfig {
4546
const tls = input.tls || true;
46-
const defaultProvider = (tls: boolean, region: string) => ({
47-
protocol: tls ? "https:" : "http:",
48-
path: "/",
49-
hostname: `${input.service}.${region}.amazonaws.com`
50-
});
51-
const endpointProvider = input.endpointProvider || defaultProvider;
5247
const endpoint: Provider<Endpoint> = input.endpoint
5348
? normalizeEndpoint(input.endpoint, input.urlParser)
54-
: () => input.region().then(region => endpointProvider(tls, region));
49+
: () =>
50+
input.region().then(async region => {
51+
const hostname = (
52+
(await input.regionInfoProvider(region)) || ({} as RegionInfo)
53+
).hostname;
54+
if (!hostname)
55+
throw new Error("Cannot resolve hostname from client config");
56+
const endpoint = input.urlParser(hostname);
57+
endpoint.protocol = tls ? "https:" : "http:";
58+
return endpoint;
59+
});
5560
return {
5661
...input,
57-
endpointProvider,
5862
endpoint,
5963
tls
6064
};

packages/signature-v4/scripts/buildSuiteFixture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {HttpRequest} from '@aws-sdk/types';
2525
2626
export interface TestCase {
2727
name: string;
28-
request: HttpRequest<string>;
28+
request: HttpRequest;
2929
authorization: string;
3030
}
3131

0 commit comments

Comments
 (0)