15 lines
749 B
JavaScript
15 lines
749 B
JavaScript
export const getEndpointFromRegion = async (input) => {
|
|
const { tls = true } = input;
|
|
const region = await input.region();
|
|
const dnsHostRegex = new RegExp(/^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])$/);
|
|
if (!dnsHostRegex.test(region)) {
|
|
throw new Error("Invalid region in client config");
|
|
}
|
|
const useDualstackEndpoint = await input.useDualstackEndpoint();
|
|
const useFipsEndpoint = await input.useFipsEndpoint();
|
|
const { hostname } = (await input.regionInfoProvider(region, { useDualstackEndpoint, useFipsEndpoint })) ?? {};
|
|
if (!hostname) {
|
|
throw new Error("Cannot resolve hostname from client config");
|
|
}
|
|
return input.urlParser(`${tls ? "https:" : "http:"}//${hostname}`);
|
|
};
|