Skip to content
Merged
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 @@ -10,6 +10,7 @@
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.HttpApiKeyAuthTrait;
import static software.amazon.smithy.python.aws.codegen.AwsConfiguration.REGION;
import software.amazon.smithy.python.codegen.ApplicationProtocol;
import software.amazon.smithy.python.codegen.CodegenUtils;
import software.amazon.smithy.python.codegen.ConfigProperty;
Expand All @@ -30,13 +31,6 @@ public class AwsAuthIntegration implements PythonIntegration {

@Override
public List<RuntimeClientPlugin> getClientPlugins(GenerationContext context) {
var regionConfig = ConfigProperty.builder()
.name("region")
.type(Symbol.builder().name("str").build())
.documentation(" The AWS region to connect to. The configured region is used to "
+ "determine the service endpoint.")
.build();

return List.of(
RuntimeClientPlugin.builder()
.servicePredicate((model, service) -> service.hasTrait(SigV4Trait.class))
Expand Down Expand Up @@ -65,7 +59,7 @@ public List<RuntimeClientPlugin> getClientPlugins(GenerationContext context) {
// TODO: Initialize with the provider chain?
.nullable(true)
.build())
.addConfigProperty(regionConfig)
.addConfigProperty(REGION)
.authScheme(new Sigv4AuthScheme())
.build()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package software.amazon.smithy.python.aws.codegen;

import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.python.codegen.ConfigProperty;
import software.amazon.smithy.utils.SmithyUnstableApi;

/**
* Common configuration for AWS Clients.
*/
@SmithyUnstableApi
public final class AwsConfiguration {
private AwsConfiguration() {
}

public static final ConfigProperty REGION = ConfigProperty.builder()
.name("region")
.type(Symbol.builder().name("str").build())
.documentation(" The AWS region to connect to. The configured region is used to "
+ "determine the service endpoint.")
.build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
*/
@SmithyUnstableApi
public class AwsPythonDependency {

private AwsPythonDependency() {
}

/**
* The core aws smithy runtime python package.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;
import software.amazon.smithy.aws.traits.ServiceTrait;
import software.amazon.smithy.codegen.core.Symbol;
import static software.amazon.smithy.python.aws.codegen.AwsConfiguration.REGION;
import software.amazon.smithy.python.codegen.CodegenUtils;
import software.amazon.smithy.python.codegen.ConfigProperty;
import software.amazon.smithy.python.codegen.GenerationContext;
Expand All @@ -23,15 +24,9 @@ public class AwsStandardRegionalEndpointsIntegration implements PythonIntegratio
@Override
public List<RuntimeClientPlugin> getClientPlugins(GenerationContext context) {
if (context.applicationProtocol().isHttpProtocol()) {
var region = ConfigProperty.builder()
.name("region")
.type(Symbol.builder().name("str").build())
.documentation(" The AWS region to connect to. The configured region is used to "
+ "determine the service endpoint.")
.build();
return List.of(
RuntimeClientPlugin.builder()
.addConfigProperty(region)
.addConfigProperty(REGION)
.build());
} else {
return List.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.TreeSet;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.model.knowledge.EventStreamIndex;
import software.amazon.smithy.model.knowledge.ServiceIndex;
Expand Down Expand Up @@ -288,9 +290,9 @@ private void writeInterceptorsType(PythonWriter writer) {
private void generateConfig(GenerationContext context, PythonWriter writer) {
var configSymbol = CodegenUtils.getConfigSymbol(context.settings());

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

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