Skip to content
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

feat: get partition of given region #1435

Merged
merged 3 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ final class EndpointGenerator implements Runnable {
private final String endpointPrefix;
private final Map<String, Partition> partitions = new TreeMap<>();
private final Map<String, ObjectNode> endpoints = new TreeMap<>();
private final Map<String, Partition> regionPartitionsMap = new TreeMap<>();

EndpointGenerator(ServiceShape service, TypeScriptWriter writer) {
this.writer = writer;
Expand Down Expand Up @@ -99,6 +100,7 @@ private void loadServiceEndpoints() {
hostName = hostName.replace("{region}", entry.getKey());
config = config.withMember("hostname", hostName);
endpoints.put(entry.getKey(), config);
regionPartitionsMap.put(entry.getKey(), partition);
}
}
}
Expand Down Expand Up @@ -142,7 +144,7 @@ private void writeEndpointProviderFunction() {
writer.write("// First, try to match exact region names.");
for (Map.Entry<String, ObjectNode> entry : endpoints.entrySet()) {
writer.write("case $S:", entry.getKey()).indent();
writeEndpointSpecificResolver(entry.getValue());
writeEndpointSpecificResolver(entry.getKey(), entry.getValue());
writer.write("break;");
writer.dedent();
}
Expand Down Expand Up @@ -170,16 +172,18 @@ private void writePartitionEndpointResolver(Partition partition) {
writer.openBlock("regionInfo = {", "};", () -> {
String template = partition.templateVariableName;
writer.write("hostname: $L.replace(\"{region}\", region),", template);
writer.write("partition: $S,", partition.ID);
writeAdditionalEndpointSettings(partition.getDefaults());
});
}
);
}

private void writeEndpointSpecificResolver(ObjectNode resolved) {
private void writeEndpointSpecificResolver(String region, ObjectNode resolved) {
String hostname = resolved.expectStringMember("hostname").getValue();
writer.openBlock("regionInfo = {", "};", () -> {
writer.write("hostname: $S,", hostname);
writer.write("partition: $S,", regionPartitionsMap.get(region).ID);
writeAdditionalEndpointSettings(resolved);
});
}
Expand All @@ -202,6 +206,7 @@ private final class Partition {
final String templateVariableName;
final String templateValue;
final String dnsSuffix;
final String ID;
private final ObjectNode config;

private Partition(ObjectNode config, String partition) {
Expand All @@ -222,6 +227,7 @@ private Partition(ObjectNode config, String partition) {
regionVariableName = snakePartition + "_REGIONS";

dnsSuffix = config.expectStringMember("dnsSuffix").getValue();
ID = partition;
}

ObjectNode getDefaults() {
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export interface RegionInfo {
path?: string;
signingService?: string;
signingRegion?: string;
partition?: string;
trivikr marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down