Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -5,6 +5,7 @@
package software.amazon.smithy.python.aws.codegen;

import static software.amazon.smithy.python.aws.codegen.AwsConfiguration.REGION;
import static software.amazon.smithy.python.aws.codegen.AwsConfiguration.RETRY_STRATEGY;

import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -64,6 +65,7 @@ public List<RuntimeClientPlugin> getClientPlugins(GenerationContext context) {
.nullable(true)
.build())
.addConfigProperty(REGION)
.addConfigProperty(RETRY_STRATEGY)
.addConfigProperty(ConfigProperty.builder()
.name("aws_access_key_id")
.type(Symbol.builder().name("str").build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,45 @@ private AwsConfiguration() {}
.type(Symbol.builder().name("str").build())
.documentation(" The AWS region to connect to. The configured region is used to "
+ "determine the service endpoint.")
.nullable(false)
.useDescriptor(true)
.validator(Symbol.builder()
.name("validate_region")
.namespace("smithy_aws_core.config.validators", ".")
.addDependency(AwsPythonDependency.SMITHY_AWS_CORE)
.build())
.defaultValue("'us-east-1'")
.build();

public static final ConfigProperty RETRY_STRATEGY = ConfigProperty.builder()
.name("retry_strategy")
.type(Symbol.builder()
.name("RetryStrategy | RetryStrategyOptions")
.addReference(Symbol.builder()
.name("RetryStrategy")
.namespace("smithy_core.interfaces.retries", ".")
.addDependency(software.amazon.smithy.python.codegen.SmithyPythonDependency.SMITHY_CORE)
.build())
.addReference(Symbol.builder()
.name("RetryStrategyOptions")
.namespace("smithy_core.retries", ".")
.addDependency(software.amazon.smithy.python.codegen.SmithyPythonDependency.SMITHY_CORE)
.build())
.build())
.documentation(
"The retry strategy or options for configuring retry behavior. Can be either a configured RetryStrategy or RetryStrategyOptions to create one.")
.nullable(false)
.useDescriptor(true)
.validator(Symbol.builder()
.name("validate_retry_strategy")
.namespace("smithy_aws_core.config.validators", ".")
.addDependency(AwsPythonDependency.SMITHY_AWS_CORE)
.build())
.customResolver(Symbol.builder()
.name("resolve_retry_strategy")
.namespace("smithy_aws_core.config.custom_resolvers", ".")
.addDependency(AwsPythonDependency.SMITHY_AWS_CORE)
.build())
.defaultValue("RetryStrategyOptions(retry_mode=\"standard\", max_attempts=3)")
.build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public final class ConfigProperty implements ToSmithyBuilder<ConfigProperty> {
private final boolean nullable;
private final String documentation;
private final Consumer<PythonWriter> initialize;
private final Symbol validator;
private final Symbol customResolver;
private final boolean useDescriptor;
private final String defaultValue;

/**
* Constructor.
Expand All @@ -33,6 +37,10 @@ private ConfigProperty(Builder builder) {
this.nullable = builder.nullable;
this.documentation = Objects.requireNonNull(builder.documentation);
this.initialize = Objects.requireNonNull(builder.initialize);
this.validator = builder.validator;
this.customResolver = builder.customResolver;
this.useDescriptor = builder.useDescriptor;
this.defaultValue = builder.defaultValue;
}

/**
Expand Down Expand Up @@ -63,6 +71,34 @@ public String documentation() {
return documentation;
}

/**
* @return Returns the validator symbol for this property, if any.
*/
public java.util.Optional<Symbol> validator() {
return java.util.Optional.ofNullable(validator);
}

/**
* @return Returns the custom resolver symbol for this property, if any.
*/
public java.util.Optional<Symbol> customResolver() {
return java.util.Optional.ofNullable(customResolver);
}

/**
* @return Returns whether this property uses the ConfigProperty descriptor.
*/
public boolean useDescriptor() {
return useDescriptor;
}

/**
* @return Returns the default value for this property, if any.
*/
public java.util.Optional<String> defaultValue() {
return java.util.Optional.ofNullable(defaultValue);
}

/**
* Initializes the config field on the config object.
*
Expand Down Expand Up @@ -94,7 +130,11 @@ public SmithyBuilder<ConfigProperty> toBuilder() {
.type(type)
.nullable(nullable)
.documentation(documentation)
.initialize(initialize);
.initialize(initialize)
.validator(validator)
.customResolver(customResolver)
.useDescriptor(useDescriptor)
.defaultValue(defaultValue);
}

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

private Symbol validator;
private Symbol customResolver;
private boolean useDescriptor = false;
private String defaultValue;

@Override
public ConfigProperty build() {
return new ConfigProperty(this);
Expand Down Expand Up @@ -182,5 +227,49 @@ public Builder initialize(Consumer<PythonWriter> initialize) {
this.initialize = initialize;
return this;
}

/**
* Sets the validator symbol for the config property.
*
* @param validator The validator function symbol.
* @return Returns the builder.
*/
public Builder validator(Symbol validator) {
this.validator = validator;
return this;
}

/**
* Sets the custom resolver symbol for the config property.
*
* @param customResolver The custom resolver function symbol.
* @return Returns the builder.
*/
public Builder customResolver(Symbol customResolver) {
this.customResolver = customResolver;
return this;
}

/**
* Sets whether the config property uses the ConfigProperty descriptor.
*
* @param useDescriptor Whether to use the descriptor pattern.
* @return Returns the builder.
*/
public Builder useDescriptor(boolean useDescriptor) {
this.useDescriptor = useDescriptor;
return this;
}

/**
* Sets the default value for the config property.
*
* @param defaultValue The default value as a Python expression string.
* @return Returns the builder.
*/
public Builder defaultValue(String defaultValue) {
this.defaultValue = defaultValue;
return this;
}
}
}
Loading
Loading