forked from aws/aws-sdk-js-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config-resolver): add getRegionInfo helper functions
Refs: aws#2696
- Loading branch information
Showing
6 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/config-resolver/src/getRegionInfo/getRegionInfo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { getResolvedHostName } from "./getResolvedHostname"; | ||
import { getResolvedPartition } from "./getResolvedPartition"; | ||
import { RegionInfoOptions } from "./types"; | ||
|
||
export const getRegionInfo = (region: string, { regionHash, partitionHash }: RegionInfoOptions) => ({ | ||
signingService: "s3", | ||
hostname: getResolvedHostName(region, { regionHash, partitionHash }), | ||
partition: getResolvedPartition(region, { partitionHash }), | ||
...(regionHash[region]?.signingRegion && { | ||
signingRegion: regionHash[region].signingRegion, | ||
}), | ||
...(regionHash[region]?.signingService && { | ||
signingService: regionHash[region].signingService, | ||
}), | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/config-resolver/src/getRegionInfo/getResolvedHostname.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { getResolvedPartition } from "./getResolvedPartition"; | ||
import { RegionInfoOptions } from "./types"; | ||
|
||
export const getResolvedHostName = (region: string, { regionHash, partitionHash }: RegionInfoOptions) => | ||
regionHash[region]?.hostname ?? | ||
partitionHash[getResolvedPartition(region, { partitionHash })].hostname.replace("{region}", region); |
4 changes: 4 additions & 0 deletions
4
packages/config-resolver/src/getRegionInfo/getResolvedPartition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { RegionInfoOptions } from "./types"; | ||
|
||
export const getResolvedPartition = (region: string, { partitionHash }: Omit<RegionInfoOptions, "regionHash">) => | ||
Object.keys(partitionHash).find((key) => partitionHash[key].regions.includes(region)) ?? "aws"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./types"; | ||
export * from "./getRegionInfo"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { RegionInfo } from "@aws-sdk/types"; | ||
|
||
export type RegionHash = { [key: string]: Partial<Omit<RegionInfo, "partition" | "path">> }; | ||
export type PartitionHash = { [key: string]: { regions: string[]; hostname: string } }; | ||
|
||
export interface RegionInfoOptions { | ||
/** | ||
* The hash of region with the information specific to that region. | ||
* The information can include hostname, signingService and signingRegion. | ||
*/ | ||
regionHash: RegionHash; | ||
|
||
/** | ||
* The hash of partition with the information specific to that partition. | ||
* The information includes the list of regions belonging to that partition, | ||
* and the hostname to be used for the partition. | ||
*/ | ||
partitionHash: PartitionHash; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./CustomEndpointsConfig"; | ||
export * from "./EndpointsConfig"; | ||
export * from "./RegionConfig"; | ||
export * from "./getRegionInfo"; |