Skip to content

Commit b1c3752

Browse files
authored
De-duplicate Region Config (#424)
1 parent b042aaa commit b1c3752

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

codegen/aws/core/src/main/java/software/amazon/smithy/python/aws/codegen/AwsAuthIntegration.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import software.amazon.smithy.codegen.core.Symbol;
1111
import software.amazon.smithy.model.shapes.ShapeId;
1212
import software.amazon.smithy.model.traits.HttpApiKeyAuthTrait;
13+
import static software.amazon.smithy.python.aws.codegen.AwsConfiguration.REGION;
1314
import software.amazon.smithy.python.codegen.ApplicationProtocol;
1415
import software.amazon.smithy.python.codegen.CodegenUtils;
1516
import software.amazon.smithy.python.codegen.ConfigProperty;
@@ -30,13 +31,6 @@ public class AwsAuthIntegration implements PythonIntegration {
3031

3132
@Override
3233
public List<RuntimeClientPlugin> getClientPlugins(GenerationContext context) {
33-
var regionConfig = ConfigProperty.builder()
34-
.name("region")
35-
.type(Symbol.builder().name("str").build())
36-
.documentation(" The AWS region to connect to. The configured region is used to "
37-
+ "determine the service endpoint.")
38-
.build();
39-
4034
return List.of(
4135
RuntimeClientPlugin.builder()
4236
.servicePredicate((model, service) -> service.hasTrait(SigV4Trait.class))
@@ -65,7 +59,7 @@ public List<RuntimeClientPlugin> getClientPlugins(GenerationContext context) {
6559
// TODO: Initialize with the provider chain?
6660
.nullable(true)
6761
.build())
68-
.addConfigProperty(regionConfig)
62+
.addConfigProperty(REGION)
6963
.authScheme(new Sigv4AuthScheme())
7064
.build()
7165
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package software.amazon.smithy.python.aws.codegen;
6+
7+
import software.amazon.smithy.codegen.core.Symbol;
8+
import software.amazon.smithy.python.codegen.ConfigProperty;
9+
import software.amazon.smithy.utils.SmithyUnstableApi;
10+
11+
/**
12+
* Common configuration for AWS Clients.
13+
*/
14+
@SmithyUnstableApi
15+
public final class AwsConfiguration {
16+
private AwsConfiguration() {
17+
}
18+
19+
public static final ConfigProperty REGION = ConfigProperty.builder()
20+
.name("region")
21+
.type(Symbol.builder().name("str").build())
22+
.documentation(" The AWS region to connect to. The configured region is used to "
23+
+ "determine the service endpoint.")
24+
.build();
25+
}

codegen/aws/core/src/main/java/software/amazon/smithy/python/aws/codegen/AwsPythonDependency.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
*/
1313
@SmithyUnstableApi
1414
public class AwsPythonDependency {
15+
16+
private AwsPythonDependency() {
17+
}
18+
1519
/**
1620
* The core aws smithy runtime python package.
1721
*

codegen/aws/core/src/main/java/software/amazon/smithy/python/aws/codegen/AwsStandardRegionalEndpointsIntegration.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.List;
88
import software.amazon.smithy.aws.traits.ServiceTrait;
99
import software.amazon.smithy.codegen.core.Symbol;
10+
import static software.amazon.smithy.python.aws.codegen.AwsConfiguration.REGION;
1011
import software.amazon.smithy.python.codegen.CodegenUtils;
1112
import software.amazon.smithy.python.codegen.ConfigProperty;
1213
import software.amazon.smithy.python.codegen.GenerationContext;
@@ -23,15 +24,9 @@ public class AwsStandardRegionalEndpointsIntegration implements PythonIntegratio
2324
@Override
2425
public List<RuntimeClientPlugin> getClientPlugins(GenerationContext context) {
2526
if (context.applicationProtocol().isHttpProtocol()) {
26-
var region = ConfigProperty.builder()
27-
.name("region")
28-
.type(Symbol.builder().name("str").build())
29-
.documentation(" The AWS region to connect to. The configured region is used to "
30-
+ "determine the service endpoint.")
31-
.build();
3227
return List.of(
3328
RuntimeClientPlugin.builder()
34-
.addConfigProperty(region)
29+
.addConfigProperty(REGION)
3530
.build());
3631
} else {
3732
return List.of();

codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/ConfigGenerator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import java.util.ArrayList;
88
import java.util.Arrays;
99
import java.util.Collection;
10+
import java.util.Comparator;
1011
import java.util.LinkedHashMap;
1112
import java.util.List;
1213
import java.util.Locale;
14+
import java.util.TreeSet;
1315
import software.amazon.smithy.codegen.core.Symbol;
1416
import software.amazon.smithy.model.knowledge.EventStreamIndex;
1517
import software.amazon.smithy.model.knowledge.ServiceIndex;
@@ -288,9 +290,9 @@ private void writeInterceptorsType(PythonWriter writer) {
288290
private void generateConfig(GenerationContext context, PythonWriter writer) {
289291
var configSymbol = CodegenUtils.getConfigSymbol(context.settings());
290292

291-
// Initialize the list of config properties with our base properties. Here a new
292-
// list is constructed because that base list is immutable.
293-
var properties = new ArrayList<>(BASE_PROPERTIES);
293+
// Initialize a set of config properties with our base properties.
294+
var properties = new TreeSet<>(Comparator.comparing(ConfigProperty::name));
295+
properties.addAll(BASE_PROPERTIES);
294296

295297
// Smithy is transport agnostic, so we don't add http-related properties by default.
296298
// Nevertheless, HTTP is the most common use case so we standardize those settings

0 commit comments

Comments
 (0)