initial commit
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export const getHostnameFromVariants = (variants = [], { useFipsEndpoint, useDualstackEndpoint }) => variants.find(({ tags }) => useFipsEndpoint === tags.includes("fips") && useDualstackEndpoint === tags.includes("dualstack"))?.hostname;
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import { getHostnameFromVariants } from "./getHostnameFromVariants";
|
||||
import { getResolvedHostname } from "./getResolvedHostname";
|
||||
import { getResolvedPartition } from "./getResolvedPartition";
|
||||
import { getResolvedSigningRegion } from "./getResolvedSigningRegion";
|
||||
export const getRegionInfo = (region, { useFipsEndpoint = false, useDualstackEndpoint = false, signingService, regionHash, partitionHash, }) => {
|
||||
const partition = getResolvedPartition(region, { partitionHash });
|
||||
const resolvedRegion = region in regionHash ? region : partitionHash[partition]?.endpoint ?? region;
|
||||
const hostnameOptions = { useFipsEndpoint, useDualstackEndpoint };
|
||||
const regionHostname = getHostnameFromVariants(regionHash[resolvedRegion]?.variants, hostnameOptions);
|
||||
const partitionHostname = getHostnameFromVariants(partitionHash[partition]?.variants, hostnameOptions);
|
||||
const hostname = getResolvedHostname(resolvedRegion, { regionHostname, partitionHostname });
|
||||
if (hostname === undefined) {
|
||||
throw new Error(`Endpoint resolution failed for: ${{ resolvedRegion, useFipsEndpoint, useDualstackEndpoint }}`);
|
||||
}
|
||||
const signingRegion = getResolvedSigningRegion(hostname, {
|
||||
signingRegion: regionHash[resolvedRegion]?.signingRegion,
|
||||
regionRegex: partitionHash[partition].regionRegex,
|
||||
useFipsEndpoint,
|
||||
});
|
||||
return {
|
||||
partition,
|
||||
signingService,
|
||||
hostname,
|
||||
...(signingRegion && { signingRegion }),
|
||||
...(regionHash[resolvedRegion]?.signingService && {
|
||||
signingService: regionHash[resolvedRegion].signingService,
|
||||
}),
|
||||
};
|
||||
};
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
export const getResolvedHostname = (resolvedRegion, { regionHostname, partitionHostname }) => regionHostname
|
||||
? regionHostname
|
||||
: partitionHostname
|
||||
? partitionHostname.replace("{region}", resolvedRegion)
|
||||
: undefined;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export const getResolvedPartition = (region, { partitionHash }) => Object.keys(partitionHash || {}).find((key) => partitionHash[key].regions.includes(region)) ?? "aws";
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
export const getResolvedSigningRegion = (hostname, { signingRegion, regionRegex, useFipsEndpoint }) => {
|
||||
if (signingRegion) {
|
||||
return signingRegion;
|
||||
}
|
||||
else if (useFipsEndpoint) {
|
||||
const regionRegexJs = regionRegex.replace("\\\\", "\\").replace(/^\^/g, "\\.").replace(/\$$/g, "\\.");
|
||||
const regionRegexmatchArray = hostname.match(regionRegexJs);
|
||||
if (regionRegexmatchArray) {
|
||||
return regionRegexmatchArray[0].slice(1, -1);
|
||||
}
|
||||
}
|
||||
};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export * from "./PartitionHash";
|
||||
export * from "./RegionHash";
|
||||
export * from "./getRegionInfo";
|
||||
Reference in New Issue
Block a user