-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: start endpoint resolver generation (#472)
- Loading branch information
Showing
24 changed files
with
6,296 additions
and
88 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
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
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,78 @@ | ||
import { RegionInfo, RegionInfoProvider } from "@aws-sdk/types"; | ||
|
||
// Partition default templates | ||
const AWS_TEMPLATE = "rds-data.{region}.amazonaws.com"; | ||
const AWS_CN_TEMPLATE = "rds-data.{region}.amazonaws.com.cn"; | ||
const AWS_ISO_TEMPLATE = "rds-data.{region}.c2s.ic.gov"; | ||
const AWS_ISO_B_TEMPLATE = "rds-data.{region}.sc2s.sgov.gov"; | ||
const AWS_US_GOV_TEMPLATE = "rds-data.{region}.amazonaws.com"; | ||
|
||
// Partition regions | ||
const AWS_REGIONS = new Set([ | ||
"ap-south-1", | ||
"eu-north-1", | ||
"eu-west-3", | ||
"eu-west-2", | ||
"eu-west-1", | ||
"ap-northeast-2", | ||
"ap-northeast-1", | ||
"me-south-1", | ||
"ca-central-1", | ||
"sa-east-1", | ||
"ap-east-1", | ||
"ap-southeast-1", | ||
"ap-southeast-2", | ||
"eu-central-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-west-1", "us-gov-east-1"]); | ||
|
||
export const defaultRegionInfoProvider: RegionInfoProvider = ( | ||
region: string, | ||
options?: any | ||
) => { | ||
let regionInfo: RegionInfo | undefined = undefined; | ||
switch (region) { | ||
// First, try to match exact region names. | ||
// Next, try to match partition endpoints. | ||
default: | ||
if (AWS_REGIONS.has(region)) { | ||
regionInfo = { | ||
hostname: AWS_TEMPLATE.replace("{region}", region) | ||
}; | ||
} | ||
if (AWS_CN_REGIONS.has(region)) { | ||
regionInfo = { | ||
hostname: AWS_CN_TEMPLATE.replace("{region}", region) | ||
}; | ||
} | ||
if (AWS_ISO_REGIONS.has(region)) { | ||
regionInfo = { | ||
hostname: AWS_ISO_TEMPLATE.replace("{region}", region) | ||
}; | ||
} | ||
if (AWS_ISO_B_REGIONS.has(region)) { | ||
regionInfo = { | ||
hostname: AWS_ISO_B_TEMPLATE.replace("{region}", region) | ||
}; | ||
} | ||
if (AWS_US_GOV_REGIONS.has(region)) { | ||
regionInfo = { | ||
hostname: AWS_US_GOV_TEMPLATE.replace("{region}", region) | ||
}; | ||
} | ||
// Finally, assume it's an AWS partition endpoint. | ||
if (regionInfo === undefined) { | ||
regionInfo = { | ||
hostname: AWS_TEMPLATE.replace("{region}", region) | ||
}; | ||
} | ||
} | ||
return Promise.resolve(regionInfo); | ||
}; |
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
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,4 +1,6 @@ | ||
import { defaultRegionInfoProvider } from "./endpoints"; | ||
export const ClientSharedValues = { | ||
apiVersion: "2018-08-01", | ||
signingName: "rds-data", | ||
regionInfoProvider: defaultRegionInfoProvider | ||
}; |
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
73 changes: 73 additions & 0 deletions
73
...n/java/software/amazon/smithy/aws/typescript/codegen/AwsEndpointGeneratorIntegration.java
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,73 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.aws.typescript.codegen; | ||
|
||
import java.util.function.BiConsumer; | ||
import java.util.function.Consumer; | ||
import software.amazon.smithy.codegen.core.SymbolProvider; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.typescript.codegen.LanguageTarget; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptDependency; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptSettings; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptWriter; | ||
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; | ||
|
||
/** | ||
* Generates an endpoint resolver from endpoints.json. | ||
*/ | ||
public final class AwsEndpointGeneratorIntegration implements TypeScriptIntegration { | ||
@Override | ||
public void writeAdditionalFiles( | ||
TypeScriptSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
BiConsumer<String, Consumer<TypeScriptWriter>> writerFactory | ||
) { | ||
writerFactory.accept("endpoints.ts", writer -> { | ||
new EndpointGenerator(settings.getService(model), writer).run(); | ||
}); | ||
} | ||
|
||
@Override | ||
public void addConfigInterfaceFields( | ||
TypeScriptSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
TypeScriptWriter writer | ||
) { | ||
writer.addImport("RegionInfoProvider", "RegionInfoProvider", TypeScriptDependency.AWS_SDK_TYPES.packageName); | ||
writer.writeDocs("Fetch related hostname, signing name or signing region with given region."); | ||
writer.write("regionInfoProvider?: RegionInfoProvider;"); | ||
} | ||
|
||
@Override | ||
public void addRuntimeConfigValues( | ||
TypeScriptSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
TypeScriptWriter writer, | ||
LanguageTarget target | ||
) { | ||
switch (target) { | ||
case SHARED: | ||
writer.addImport("defaultRegionInfoProvider", "defaultRegionInfoProvider", "./endpoints"); | ||
writer.write("regionInfoProvider: defaultRegionInfoProvider"); | ||
break; | ||
default: | ||
//do nothing | ||
} | ||
} | ||
} |
Oops, something went wrong.