1 | import { getHostnameFromVariants } from "./getHostnameFromVariants";
|
2 | import { getResolvedHostname } from "./getResolvedHostname";
|
3 | import { getResolvedPartition } from "./getResolvedPartition";
|
4 | import { getResolvedSigningRegion } from "./getResolvedSigningRegion";
|
5 | export const getRegionInfo = (region, { useFipsEndpoint = false, useDualstackEndpoint = false, signingService, regionHash, partitionHash, }) => {
|
6 | const partition = getResolvedPartition(region, { partitionHash });
|
7 | const resolvedRegion = region in regionHash ? region : partitionHash[partition]?.endpoint ?? region;
|
8 | const hostnameOptions = { useFipsEndpoint, useDualstackEndpoint };
|
9 | const regionHostname = getHostnameFromVariants(regionHash[resolvedRegion]?.variants, hostnameOptions);
|
10 | const partitionHostname = getHostnameFromVariants(partitionHash[partition]?.variants, hostnameOptions);
|
11 | const hostname = getResolvedHostname(resolvedRegion, { regionHostname, partitionHostname });
|
12 | if (hostname === undefined) {
|
13 | throw new Error(`Endpoint resolution failed for: ${{ resolvedRegion, useFipsEndpoint, useDualstackEndpoint }}`);
|
14 | }
|
15 | const signingRegion = getResolvedSigningRegion(hostname, {
|
16 | signingRegion: regionHash[resolvedRegion]?.signingRegion,
|
17 | regionRegex: partitionHash[partition].regionRegex,
|
18 | useFipsEndpoint,
|
19 | });
|
20 | return {
|
21 | partition,
|
22 | signingService,
|
23 | hostname,
|
24 | ...(signingRegion && { signingRegion }),
|
25 | ...(regionHash[resolvedRegion]?.signingService && {
|
26 | signingService: regionHash[resolvedRegion].signingService,
|
27 | }),
|
28 | };
|
29 | };
|