Skip to content

Commit d0f9250

Browse files
mtdowlingtrivikr
authored andcommitted
feat: start endpoint resolver generation (#472)
1 parent 3aca84f commit d0f9250

File tree

24 files changed

+6296
-88
lines changed

24 files changed

+6296
-88
lines changed

Diff for: buildspec.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ phases:
1111
- echo Building...
1212
- yarn
1313
- echo Executing unit tests
14-
- yarn test
14+
- yarn build:smithy-client #TODO: change to `yarn test:all` after clients are ready
15+
- echo Executing functional test
16+
- yarn test:functional
1517
post_build:
1618
commands:
1719
- ./node_modules/.bin/codecov -f coverage/*.json

Diff for: clients/client-rds-data/RDSDataClient.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ import {
5454
HttpHandlerOptions as __HttpHandlerOptions,
5555
Provider as __Provider,
5656
StreamCollector as __StreamCollector,
57-
UrlParser as __UrlParser
57+
UrlParser as __UrlParser,
58+
RegionInfoProvider
5859
} from "@aws-sdk/types";
5960

6061
export type ServiceInputTypes =
@@ -140,6 +141,11 @@ export interface ClientDefaults
140141
* Provider function that return promise of a region string
141142
*/
142143
regionDefaultProvider?: (input: any) => __Provider<string>;
144+
145+
/**
146+
* Fetch hostname, signing name or signing region of given region
147+
*/
148+
regionInfoProvider?: RegionInfoProvider;
143149
}
144150

145151
export type RDSDataClientConfig = Partial<
@@ -184,7 +190,6 @@ export class RDSDataClient extends __Client<
184190

185191
constructor(configuration: RDSDataClientConfig) {
186192
let _config_0 = {
187-
service: "rds-data", //TODO: remove this
188193
...__ClientDefaultValues,
189194
...configuration
190195
};

Diff for: clients/client-rds-data/endpoints.ts

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { RegionInfo, RegionInfoProvider } from "@aws-sdk/types";
2+
3+
// Partition default templates
4+
const AWS_TEMPLATE = "rds-data.{region}.amazonaws.com";
5+
const AWS_CN_TEMPLATE = "rds-data.{region}.amazonaws.com.cn";
6+
const AWS_ISO_TEMPLATE = "rds-data.{region}.c2s.ic.gov";
7+
const AWS_ISO_B_TEMPLATE = "rds-data.{region}.sc2s.sgov.gov";
8+
const AWS_US_GOV_TEMPLATE = "rds-data.{region}.amazonaws.com";
9+
10+
// Partition regions
11+
const AWS_REGIONS = new Set([
12+
"ap-south-1",
13+
"eu-north-1",
14+
"eu-west-3",
15+
"eu-west-2",
16+
"eu-west-1",
17+
"ap-northeast-2",
18+
"ap-northeast-1",
19+
"me-south-1",
20+
"ca-central-1",
21+
"sa-east-1",
22+
"ap-east-1",
23+
"ap-southeast-1",
24+
"ap-southeast-2",
25+
"eu-central-1",
26+
"us-east-1",
27+
"us-east-2",
28+
"us-west-1",
29+
"us-west-2"
30+
]);
31+
const AWS_CN_REGIONS = new Set(["cn-north-1", "cn-northwest-1"]);
32+
const AWS_ISO_REGIONS = new Set(["us-iso-east-1"]);
33+
const AWS_ISO_B_REGIONS = new Set(["us-isob-east-1"]);
34+
const AWS_US_GOV_REGIONS = new Set(["us-gov-west-1", "us-gov-east-1"]);
35+
36+
export const defaultRegionInfoProvider: RegionInfoProvider = (
37+
region: string,
38+
options?: any
39+
) => {
40+
let regionInfo: RegionInfo | undefined = undefined;
41+
switch (region) {
42+
// First, try to match exact region names.
43+
// Next, try to match partition endpoints.
44+
default:
45+
if (AWS_REGIONS.has(region)) {
46+
regionInfo = {
47+
hostname: AWS_TEMPLATE.replace("{region}", region)
48+
};
49+
}
50+
if (AWS_CN_REGIONS.has(region)) {
51+
regionInfo = {
52+
hostname: AWS_CN_TEMPLATE.replace("{region}", region)
53+
};
54+
}
55+
if (AWS_ISO_REGIONS.has(region)) {
56+
regionInfo = {
57+
hostname: AWS_ISO_TEMPLATE.replace("{region}", region)
58+
};
59+
}
60+
if (AWS_ISO_B_REGIONS.has(region)) {
61+
regionInfo = {
62+
hostname: AWS_ISO_B_TEMPLATE.replace("{region}", region)
63+
};
64+
}
65+
if (AWS_US_GOV_REGIONS.has(region)) {
66+
regionInfo = {
67+
hostname: AWS_US_GOV_TEMPLATE.replace("{region}", region)
68+
};
69+
}
70+
// Finally, assume it's an AWS partition endpoint.
71+
if (regionInfo === undefined) {
72+
regionInfo = {
73+
hostname: AWS_TEMPLATE.replace("{region}", region)
74+
};
75+
}
76+
}
77+
return Promise.resolve(regionInfo);
78+
};

Diff for: clients/client-rds-data/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
"clean": "npm run remove-definitions && npm run remove-dist && npm run remove-js && npm run remove-maps",
77
"build-documentation": "npm run clean && typedoc ./",
88
"prepublishOnly": "yarn build",
9-
"pretest": "tsc",
9+
"pretest": "yarn build",
1010
"remove-definitions": "rimraf ./types",
1111
"remove-dist": "rimraf ./dist",
1212
"remove-documentation": "rimraf ./docs",
1313
"remove-js": "rimraf *.js && rimraf ./commands/*.js && rimraf ./lib/*.js && rimraf ./models/*.js && rimraf ./protocols/*.js",
1414
"remove-maps": "rimraf *.js.map && rimraf ./commands/*.js.map && rimraf ./lib/*.js.map && rimraf ./models/*.js.map && rimraf ./protocols/*.js.map",
1515
"test": "exit 0",
1616
"smoke-test": "npm run pretest && node ./test/smoke/index.spec.js",
17+
"build:cjs": "tsc -p tsconfig.json",
1718
"build:es": "tsc -p tsconfig.es.json",
18-
"build": "yarn pretest && yarn build:es"
19+
"build": "yarn build:cjs && yarn build:es"
1920
},
2021
"main": "./dist/cjs/index.js",
2122
"types": "./types/index.d.ts",

Diff for: clients/client-rds-data/runtimeConfig.shared.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { defaultRegionInfoProvider } from "./endpoints";
12
export const ClientSharedValues = {
23
apiVersion: "2018-08-01",
34
signingName: "rds-data",
5+
regionInfoProvider: defaultRegionInfoProvider
46
};

Diff for: codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public List<RuntimeClientPlugin> getClientPlugins() {
5858
.withConventions(TypeScriptDependency.CONFIG_RESOLVER.dependency, "Region", HAS_CONFIG)
5959
.build(),
6060
RuntimeClientPlugin.builder()
61-
.withConventions(AwsDependency.MIDDLEWARE_SIGNING.dependency, "AwsAuth")
61+
.withConventions(TypeScriptDependency.CONFIG_RESOLVER.dependency, "Endpoints", HAS_CONFIG)
6262
.build(),
6363
RuntimeClientPlugin.builder()
64-
.withConventions(TypeScriptDependency.CONFIG_RESOLVER.dependency, "Endpoints", HAS_CONFIG)
64+
.withConventions(AwsDependency.MIDDLEWARE_SIGNING.dependency, "AwsAuth")
6565
.build(),
6666
RuntimeClientPlugin.builder()
6767
.withConventions(TypeScriptDependency.MIDDLEWARE_RETRY.dependency, "Retry")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.smithy.aws.typescript.codegen;
17+
18+
import java.util.function.BiConsumer;
19+
import java.util.function.Consumer;
20+
import software.amazon.smithy.codegen.core.SymbolProvider;
21+
import software.amazon.smithy.model.Model;
22+
import software.amazon.smithy.typescript.codegen.LanguageTarget;
23+
import software.amazon.smithy.typescript.codegen.TypeScriptDependency;
24+
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
25+
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
26+
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
27+
28+
/**
29+
* Generates an endpoint resolver from endpoints.json.
30+
*/
31+
public final class AwsEndpointGeneratorIntegration implements TypeScriptIntegration {
32+
@Override
33+
public void writeAdditionalFiles(
34+
TypeScriptSettings settings,
35+
Model model,
36+
SymbolProvider symbolProvider,
37+
BiConsumer<String, Consumer<TypeScriptWriter>> writerFactory
38+
) {
39+
writerFactory.accept("endpoints.ts", writer -> {
40+
new EndpointGenerator(settings.getService(model), writer).run();
41+
});
42+
}
43+
44+
@Override
45+
public void addConfigInterfaceFields(
46+
TypeScriptSettings settings,
47+
Model model,
48+
SymbolProvider symbolProvider,
49+
TypeScriptWriter writer
50+
) {
51+
writer.addImport("RegionInfoProvider", "RegionInfoProvider", TypeScriptDependency.AWS_SDK_TYPES.packageName);
52+
writer.writeDocs("Fetch related hostname, signing name or signing region with given region.");
53+
writer.write("regionInfoProvider?: RegionInfoProvider;");
54+
}
55+
56+
@Override
57+
public void addRuntimeConfigValues(
58+
TypeScriptSettings settings,
59+
Model model,
60+
SymbolProvider symbolProvider,
61+
TypeScriptWriter writer,
62+
LanguageTarget target
63+
) {
64+
switch (target) {
65+
case SHARED:
66+
writer.addImport("defaultRegionInfoProvider", "defaultRegionInfoProvider", "./endpoints");
67+
writer.write("regionInfoProvider: defaultRegionInfoProvider");
68+
break;
69+
default:
70+
//do nothing
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)