-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clients): modular endpoints resolution (#2704)
- Loading branch information
Showing
283 changed files
with
19,225 additions
and
48,054 deletions.
There are no files selected for viewing
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,271 +1,91 @@ | ||
import { RegionInfo, RegionInfoProvider } from "@aws-sdk/types"; | ||
import { PartitionHash, RegionHash, getRegionInfo } from "@aws-sdk/config-resolver"; | ||
import { RegionInfoProvider } from "@aws-sdk/types"; | ||
|
||
// Partition default templates | ||
const AWS_TEMPLATE = "access-analyzer.{region}.amazonaws.com"; | ||
const AWS_CN_TEMPLATE = "access-analyzer.{region}.amazonaws.com.cn"; | ||
const AWS_ISO_TEMPLATE = "access-analyzer.{region}.c2s.ic.gov"; | ||
const AWS_ISO_B_TEMPLATE = "access-analyzer.{region}.sc2s.sgov.gov"; | ||
const AWS_US_GOV_TEMPLATE = "access-analyzer.{region}.amazonaws.com"; | ||
|
||
// Partition regions | ||
const AWS_REGIONS = new Set([ | ||
"af-south-1", | ||
"ap-east-1", | ||
"ap-northeast-1", | ||
"ap-northeast-2", | ||
"ap-northeast-3", | ||
"ap-south-1", | ||
"ap-southeast-1", | ||
"ap-southeast-2", | ||
"ca-central-1", | ||
"eu-central-1", | ||
"eu-north-1", | ||
"eu-south-1", | ||
"eu-west-1", | ||
"eu-west-2", | ||
"eu-west-3", | ||
"me-south-1", | ||
"sa-east-1", | ||
"us-east-1", | ||
"us-east-2", | ||
"us-west-1", | ||
"us-west-2", | ||
]); | ||
const AWS_CN_REGIONS = new Set(["cn-north-1", "cn-northwest-1"]); | ||
const AWS_ISO_REGIONS = new Set(["us-iso-east-1"]); | ||
const AWS_ISO_B_REGIONS = new Set(["us-isob-east-1"]); | ||
const AWS_US_GOV_REGIONS = new Set(["us-gov-east-1", "us-gov-west-1"]); | ||
const regionHash: RegionHash = { | ||
"fips-ca-central-1": { | ||
hostname: "access-analyzer-fips.ca-central-1.amazonaws.com", | ||
signingRegion: "ca-central-1", | ||
}, | ||
"fips-us-east-1": { | ||
hostname: "access-analyzer-fips.us-east-1.amazonaws.com", | ||
signingRegion: "us-east-1", | ||
}, | ||
"fips-us-east-2": { | ||
hostname: "access-analyzer-fips.us-east-2.amazonaws.com", | ||
signingRegion: "us-east-2", | ||
}, | ||
"fips-us-west-1": { | ||
hostname: "access-analyzer-fips.us-west-1.amazonaws.com", | ||
signingRegion: "us-west-1", | ||
}, | ||
"fips-us-west-2": { | ||
hostname: "access-analyzer-fips.us-west-2.amazonaws.com", | ||
signingRegion: "us-west-2", | ||
}, | ||
"us-gov-east-1": { | ||
hostname: "access-analyzer.us-gov-east-1.amazonaws.com", | ||
signingRegion: "us-gov-east-1", | ||
}, | ||
"us-gov-west-1": { | ||
hostname: "access-analyzer.us-gov-west-1.amazonaws.com", | ||
signingRegion: "us-gov-west-1", | ||
}, | ||
}; | ||
|
||
export const defaultRegionInfoProvider: RegionInfoProvider = (region: string, options?: any) => { | ||
let regionInfo: RegionInfo | undefined = undefined; | ||
switch (region) { | ||
// First, try to match exact region names. | ||
case "af-south-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.af-south-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "ap-east-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.ap-east-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "ap-northeast-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.ap-northeast-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "ap-northeast-2": | ||
regionInfo = { | ||
hostname: "access-analyzer.ap-northeast-2.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "ap-northeast-3": | ||
regionInfo = { | ||
hostname: "access-analyzer.ap-northeast-3.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "ap-south-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.ap-south-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "ap-southeast-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.ap-southeast-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "ap-southeast-2": | ||
regionInfo = { | ||
hostname: "access-analyzer.ap-southeast-2.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "ca-central-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.ca-central-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "cn-north-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.cn-north-1.amazonaws.com.cn", | ||
partition: "aws-cn", | ||
}; | ||
break; | ||
case "cn-northwest-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.cn-northwest-1.amazonaws.com.cn", | ||
partition: "aws-cn", | ||
}; | ||
break; | ||
case "eu-central-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.eu-central-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "eu-north-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.eu-north-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "eu-south-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.eu-south-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "eu-west-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.eu-west-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "eu-west-2": | ||
regionInfo = { | ||
hostname: "access-analyzer.eu-west-2.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "eu-west-3": | ||
regionInfo = { | ||
hostname: "access-analyzer.eu-west-3.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "fips-ca-central-1": | ||
regionInfo = { | ||
hostname: "access-analyzer-fips.ca-central-1.amazonaws.com", | ||
partition: "aws", | ||
signingRegion: "ca-central-1", | ||
}; | ||
break; | ||
case "fips-us-east-1": | ||
regionInfo = { | ||
hostname: "access-analyzer-fips.us-east-1.amazonaws.com", | ||
partition: "aws", | ||
signingRegion: "us-east-1", | ||
}; | ||
break; | ||
case "fips-us-east-2": | ||
regionInfo = { | ||
hostname: "access-analyzer-fips.us-east-2.amazonaws.com", | ||
partition: "aws", | ||
signingRegion: "us-east-2", | ||
}; | ||
break; | ||
case "fips-us-west-1": | ||
regionInfo = { | ||
hostname: "access-analyzer-fips.us-west-1.amazonaws.com", | ||
partition: "aws", | ||
signingRegion: "us-west-1", | ||
}; | ||
break; | ||
case "fips-us-west-2": | ||
regionInfo = { | ||
hostname: "access-analyzer-fips.us-west-2.amazonaws.com", | ||
partition: "aws", | ||
signingRegion: "us-west-2", | ||
}; | ||
break; | ||
case "me-south-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.me-south-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "sa-east-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.sa-east-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "us-east-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.us-east-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "us-east-2": | ||
regionInfo = { | ||
hostname: "access-analyzer.us-east-2.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "us-gov-east-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.us-gov-east-1.amazonaws.com", | ||
partition: "aws-us-gov", | ||
signingRegion: "us-gov-east-1", | ||
}; | ||
break; | ||
case "us-gov-west-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.us-gov-west-1.amazonaws.com", | ||
partition: "aws-us-gov", | ||
signingRegion: "us-gov-west-1", | ||
}; | ||
break; | ||
case "us-west-1": | ||
regionInfo = { | ||
hostname: "access-analyzer.us-west-1.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
case "us-west-2": | ||
regionInfo = { | ||
hostname: "access-analyzer.us-west-2.amazonaws.com", | ||
partition: "aws", | ||
}; | ||
break; | ||
// Next, try to match partition endpoints. | ||
default: | ||
if (AWS_REGIONS.has(region)) { | ||
regionInfo = { | ||
hostname: AWS_TEMPLATE.replace("{region}", region), | ||
partition: "aws", | ||
}; | ||
} | ||
if (AWS_CN_REGIONS.has(region)) { | ||
regionInfo = { | ||
hostname: AWS_CN_TEMPLATE.replace("{region}", region), | ||
partition: "aws-cn", | ||
}; | ||
} | ||
if (AWS_ISO_REGIONS.has(region)) { | ||
regionInfo = { | ||
hostname: AWS_ISO_TEMPLATE.replace("{region}", region), | ||
partition: "aws-iso", | ||
}; | ||
} | ||
if (AWS_ISO_B_REGIONS.has(region)) { | ||
regionInfo = { | ||
hostname: AWS_ISO_B_TEMPLATE.replace("{region}", region), | ||
partition: "aws-iso-b", | ||
}; | ||
} | ||
if (AWS_US_GOV_REGIONS.has(region)) { | ||
regionInfo = { | ||
hostname: AWS_US_GOV_TEMPLATE.replace("{region}", region), | ||
partition: "aws-us-gov", | ||
}; | ||
} | ||
// Finally, assume it's an AWS partition endpoint. | ||
if (regionInfo === undefined) { | ||
regionInfo = { | ||
hostname: AWS_TEMPLATE.replace("{region}", region), | ||
partition: "aws", | ||
}; | ||
} | ||
} | ||
return Promise.resolve({ signingService: "access-analyzer", ...regionInfo }); | ||
const partitionHash: PartitionHash = { | ||
aws: { | ||
regions: [ | ||
"af-south-1", | ||
"ap-east-1", | ||
"ap-northeast-1", | ||
"ap-northeast-2", | ||
"ap-northeast-3", | ||
"ap-south-1", | ||
"ap-southeast-1", | ||
"ap-southeast-2", | ||
"ca-central-1", | ||
"eu-central-1", | ||
"eu-north-1", | ||
"eu-south-1", | ||
"eu-west-1", | ||
"eu-west-2", | ||
"eu-west-3", | ||
"fips-ca-central-1", | ||
"fips-us-east-1", | ||
"fips-us-east-2", | ||
"fips-us-west-1", | ||
"fips-us-west-2", | ||
"me-south-1", | ||
"sa-east-1", | ||
"us-east-1", | ||
"us-east-2", | ||
"us-west-1", | ||
"us-west-2", | ||
], | ||
hostname: "access-analyzer.{region}.amazonaws.com", | ||
}, | ||
"aws-cn": { | ||
regions: ["cn-north-1", "cn-northwest-1"], | ||
hostname: "access-analyzer.{region}.amazonaws.com.cn", | ||
}, | ||
"aws-iso": { | ||
regions: ["us-iso-east-1"], | ||
hostname: "access-analyzer.{region}.c2s.ic.gov", | ||
}, | ||
"aws-iso-b": { | ||
regions: ["us-isob-east-1"], | ||
hostname: "access-analyzer.{region}.sc2s.sgov.gov", | ||
}, | ||
"aws-us-gov": { | ||
regions: ["us-gov-east-1", "us-gov-west-1"], | ||
hostname: "access-analyzer.{region}.amazonaws.com", | ||
}, | ||
}; | ||
|
||
export const defaultRegionInfoProvider: RegionInfoProvider = async (region: string, options?: any) => | ||
getRegionInfo(region, { | ||
...options, | ||
signingService: "access-analyzer", | ||
regionHash, | ||
partitionHash, | ||
}); |
Oops, something went wrong.