Skip to content

Commit 3cbe664

Browse files
authored
Update the codegen files that generate config.py to support config resolution. (#646)
* Update the codegen files that generate config.py to support config resolution.
1 parent eb22199 commit 3cbe664

8 files changed

Lines changed: 369 additions & 42 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package software.amazon.smithy.python.aws.codegen;
66

77
import static software.amazon.smithy.python.aws.codegen.AwsConfiguration.REGION;
8+
import static software.amazon.smithy.python.aws.codegen.AwsConfiguration.RETRY_STRATEGY;
89

910
import java.util.List;
1011
import java.util.Set;
@@ -64,6 +65,7 @@ public List<RuntimeClientPlugin> getClientPlugins(GenerationContext context) {
6465
.nullable(true)
6566
.build())
6667
.addConfigProperty(REGION)
68+
.addConfigProperty(RETRY_STRATEGY)
6769
.addConfigProperty(ConfigProperty.builder()
6870
.name("aws_access_key_id")
6971
.type(Symbol.builder().name("str").build())

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,47 @@ private AwsConfiguration() {}
1717

1818
public static final ConfigProperty REGION = ConfigProperty.builder()
1919
.name("region")
20-
.type(Symbol.builder().name("str").build())
20+
.type(Symbol.builder().name("str | None").build())
2121
.documentation(" The AWS region to connect to. The configured region is used to "
2222
+ "determine the service endpoint.")
23+
.nullable(false)
24+
.useDescriptor(true)
25+
.validator(Symbol.builder()
26+
.name("validate_region")
27+
.namespace("smithy_aws_core.config.validators", ".")
28+
.addDependency(AwsPythonDependency.SMITHY_AWS_CORE)
29+
.build())
30+
.build();
31+
32+
public static final ConfigProperty RETRY_STRATEGY = ConfigProperty.builder()
33+
.name("retry_strategy")
34+
.type(Symbol.builder()
35+
.name("RetryStrategy | RetryStrategyOptions | None")
36+
.addReference(Symbol.builder()
37+
.name("RetryStrategy")
38+
.namespace("smithy_core.interfaces.retries", ".")
39+
.addDependency(software.amazon.smithy.python.codegen.SmithyPythonDependency.SMITHY_CORE)
40+
.build())
41+
.addReference(Symbol.builder()
42+
.name("RetryStrategyOptions")
43+
.namespace("smithy_core.retries", ".")
44+
.addDependency(software.amazon.smithy.python.codegen.SmithyPythonDependency.SMITHY_CORE)
45+
.build())
46+
.build())
47+
.documentation(
48+
"The retry strategy or options for configuring retry behavior. Can be either a configured RetryStrategy or RetryStrategyOptions to create one.")
49+
.nullable(false)
50+
.useDescriptor(true)
51+
.validator(Symbol.builder()
52+
.name("validate_retry_strategy")
53+
.namespace("smithy_aws_core.config.validators", ".")
54+
.addDependency(AwsPythonDependency.SMITHY_AWS_CORE)
55+
.build())
56+
.customResolver(Symbol.builder()
57+
.name("resolve_retry_strategy")
58+
.namespace("smithy_aws_core.config.custom_resolvers", ".")
59+
.addDependency(AwsPythonDependency.SMITHY_AWS_CORE)
60+
.build())
61+
.defaultValue("RetryStrategyOptions(retry_mode=\"standard\")")
2362
.build();
2463
}

codegen/core/src/main/java/software/amazon/smithy/python/codegen/ConfigProperty.java

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public final class ConfigProperty implements ToSmithyBuilder<ConfigProperty> {
2323
private final boolean nullable;
2424
private final String documentation;
2525
private final Consumer<PythonWriter> initialize;
26+
private final Symbol validator;
27+
private final Symbol customResolver;
28+
private final boolean useDescriptor;
29+
private final String defaultValue;
2630

2731
/**
2832
* Constructor.
@@ -33,6 +37,10 @@ private ConfigProperty(Builder builder) {
3337
this.nullable = builder.nullable;
3438
this.documentation = Objects.requireNonNull(builder.documentation);
3539
this.initialize = Objects.requireNonNull(builder.initialize);
40+
this.validator = builder.validator;
41+
this.customResolver = builder.customResolver;
42+
this.useDescriptor = builder.useDescriptor;
43+
this.defaultValue = builder.defaultValue;
3644
}
3745

3846
/**
@@ -63,6 +71,34 @@ public String documentation() {
6371
return documentation;
6472
}
6573

74+
/**
75+
* @return Returns the validator symbol for this property, if any.
76+
*/
77+
public java.util.Optional<Symbol> validator() {
78+
return java.util.Optional.ofNullable(validator);
79+
}
80+
81+
/**
82+
* @return Returns the custom resolver symbol for this property, if any.
83+
*/
84+
public java.util.Optional<Symbol> customResolver() {
85+
return java.util.Optional.ofNullable(customResolver);
86+
}
87+
88+
/**
89+
* @return Returns whether this property uses the ConfigProperty descriptor.
90+
*/
91+
public boolean useDescriptor() {
92+
return useDescriptor;
93+
}
94+
95+
/**
96+
* @return Returns the default value for this property, if any.
97+
*/
98+
public java.util.Optional<String> defaultValue() {
99+
return java.util.Optional.ofNullable(defaultValue);
100+
}
101+
66102
/**
67103
* Initializes the config field on the config object.
68104
*
@@ -94,7 +130,11 @@ public SmithyBuilder<ConfigProperty> toBuilder() {
94130
.type(type)
95131
.nullable(nullable)
96132
.documentation(documentation)
97-
.initialize(initialize);
133+
.initialize(initialize)
134+
.validator(validator)
135+
.customResolver(customResolver)
136+
.useDescriptor(useDescriptor)
137+
.defaultValue(defaultValue);
98138
}
99139

100140
/**
@@ -107,6 +147,11 @@ public static final class Builder implements SmithyBuilder<ConfigProperty> {
107147
private String documentation;
108148
private Consumer<PythonWriter> initialize = writer -> writer.write("self.$1L = $1L", name);
109149

150+
private Symbol validator;
151+
private Symbol customResolver;
152+
private boolean useDescriptor = false;
153+
private String defaultValue;
154+
110155
@Override
111156
public ConfigProperty build() {
112157
return new ConfigProperty(this);
@@ -182,5 +227,49 @@ public Builder initialize(Consumer<PythonWriter> initialize) {
182227
this.initialize = initialize;
183228
return this;
184229
}
230+
231+
/**
232+
* Sets the validator symbol for the config property.
233+
*
234+
* @param validator The validator function symbol.
235+
* @return Returns the builder.
236+
*/
237+
public Builder validator(Symbol validator) {
238+
this.validator = validator;
239+
return this;
240+
}
241+
242+
/**
243+
* Sets the custom resolver symbol for the config property.
244+
*
245+
* @param customResolver The custom resolver function symbol.
246+
* @return Returns the builder.
247+
*/
248+
public Builder customResolver(Symbol customResolver) {
249+
this.customResolver = customResolver;
250+
return this;
251+
}
252+
253+
/**
254+
* Sets whether the config property uses the ConfigProperty descriptor.
255+
*
256+
* @param useDescriptor Whether to use the descriptor pattern.
257+
* @return Returns the builder.
258+
*/
259+
public Builder useDescriptor(boolean useDescriptor) {
260+
this.useDescriptor = useDescriptor;
261+
return this;
262+
}
263+
264+
/**
265+
* Sets the default value for the config property.
266+
*
267+
* @param defaultValue The default value as a Python expression string.
268+
* @return Returns the builder.
269+
*/
270+
public Builder defaultValue(String defaultValue) {
271+
this.defaultValue = defaultValue;
272+
return this;
273+
}
185274
}
186275
}

0 commit comments

Comments
 (0)