-
Notifications
You must be signed in to change notification settings - Fork 615
feat: start endpoint resolver generation #472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cfb3342
feat: start endpoint resolver generation
mtdowling 08e578c
feat: integrate clients with endpoint.ts
AllanZhengYP b9b7301
feat: add codegen for region info provider
AllanZhengYP 983b512
chore: add functional test for hostname generator
AllanZhengYP f6659e7
chore: update workspace and clients npm scripts
AllanZhengYP 7e3eaf3
fix: fix building failure
AllanZhengYP 0daf9ad
chore: update codebuild buildspec
AllanZhengYP 396418a
feat: make regionInfoProvider returns a promise
AllanZhengYP cf0c0a3
fix: address feedbacks
AllanZhengYP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
79 changes: 79 additions & 0 deletions
79
...n/java/software/amazon/smithy/aws/typescript/codegen/AwsEndpointGeneratorIntegration.java
This file contains hidden or 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,79 @@ | ||
/* | ||
* 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 BROWSER: | ||
break; | ||
case NODE: | ||
break; | ||
case SHARED: | ||
writer.addImport("defaultRegionInfoProvider", "defaultRegionInfoProvider", "./endpoints"); | ||
writer.write("regionInfoProvider: defaultRegionInfoProvider"); | ||
break; | ||
default: | ||
//do nothing | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: extra newlines |
||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: You could omit the BROWSER and NODE entries in the switch.