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 @@ -47,6 +47,8 @@ public class ServiceConfig {

private boolean hasAccelerateModeEnabledProperty = false;

private boolean hasCrossRegionAccessEnabledProperty = false;

public String getClassName() {
return className;
}
Expand Down Expand Up @@ -95,6 +97,14 @@ public void setHasPathStyleAccessEnabledProperty(boolean hasPathStyleAccessEnabl
this.hasPathStyleAccessEnabledProperty = hasPathStyleAccessEnabledProperty;
}

public boolean hasCrossRegionAccessEnabledProperty() {
return hasCrossRegionAccessEnabledProperty;
}

public void setHasCrossRegionAccessEnabledProperty(boolean hasCrossRegionAccessEnabledProperty) {
this.hasCrossRegionAccessEnabledProperty = hasCrossRegionAccessEnabledProperty;
}

public boolean hasAccelerateModeEnabledProperty() {
return hasAccelerateModeEnabledProperty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import software.amazon.awssdk.codegen.utils.AuthUtils;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.endpoints.EndpointProvider;

public class AsyncClientBuilderClass implements ClassSpec {
private final IntermediateModel model;
Expand Down Expand Up @@ -126,6 +127,9 @@ private MethodSpec buildClientMethod() {
.addStatement("$T clientConfiguration = super.asyncClientConfiguration()", SdkClientConfiguration.class)
.addStatement("this.validateClientOptions(clientConfiguration)")
.addStatement("$T endpointOverride = null", URI.class)
.addStatement("$T endpointProvider = clientConfiguration.option($T.ENDPOINT_PROVIDER)",
EndpointProvider.class,
SdkClientOption.class)
.addCode("if (clientConfiguration.option($T.ENDPOINT_OVERRIDDEN) != null"
+ "&& $T.TRUE.equals(clientConfiguration.option($T.ENDPOINT_OVERRIDDEN))) {"
+ "endpointOverride = clientConfiguration.option($T.ENDPOINT);"
Expand All @@ -135,6 +139,7 @@ private MethodSpec buildClientMethod() {
+ ".overrideConfiguration(overrideConfiguration())"
+ ".region(clientConfiguration.option($T.AWS_REGION))"
+ ".endpointOverride(endpointOverride)"
+ ".endpointProvider(endpointProvider)"
+ ".build()",
serviceConfigClassName, serviceConfigClassName, AwsClientOption.class)
.addStatement("return new $T(serviceClientConfiguration, clientConfiguration)", clientClassName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import software.amazon.awssdk.codegen.utils.AuthUtils;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.endpoints.EndpointProvider;

public class SyncClientBuilderClass implements ClassSpec {
private final IntermediateModel model;
Expand Down Expand Up @@ -126,6 +127,8 @@ private MethodSpec buildClientMethod() {
.addStatement("$T clientConfiguration = super.syncClientConfiguration()", SdkClientConfiguration.class)
.addStatement("this.validateClientOptions(clientConfiguration)")
.addStatement("$T endpointOverride = null", URI.class)
.addStatement("$T endpointProvider = clientConfiguration.option($T.ENDPOINT_PROVIDER)",
EndpointProvider.class, SdkClientOption.class)
.addCode("if (clientConfiguration.option($T.ENDPOINT_OVERRIDDEN) != null"
+ "&& $T.TRUE.equals(clientConfiguration.option($T.ENDPOINT_OVERRIDDEN))) {"
+ "endpointOverride = clientConfiguration.option($T.ENDPOINT);"
Expand All @@ -135,6 +138,7 @@ private MethodSpec buildClientMethod() {
+ ".overrideConfiguration(overrideConfiguration())"
+ ".region(clientConfiguration.option($T.AWS_REGION))"
+ ".endpointOverride(endpointOverride)"
+ ".endpointProvider(endpointProvider)"
+ ".build()",
serviceConfigClassName, serviceConfigClassName, AwsClientOption.class)
.addStatement("return new $T(serviceClientConfiguration, clientConfiguration)", clientClassName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import software.amazon.awssdk.codegen.poet.ClassSpec;
import software.amazon.awssdk.codegen.poet.PoetUtils;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.endpoints.EndpointProvider;
import software.amazon.awssdk.regions.Region;

public class ServiceClientConfigurationClass implements ClassSpec {
Expand Down Expand Up @@ -110,6 +111,13 @@ private TypeSpec builderInterfaceSpec() {
.returns(className().nestedClass("Builder"))
.addJavadoc("Configure the client override configuration")
.build())
.addMethod(MethodSpec.methodBuilder("endpointProvider")
.addAnnotation(Override.class)
.addModifiers(PUBLIC, ABSTRACT)
.addParameter(EndpointProvider.class, "endpointProvider")
.returns(className().nestedClass("Builder"))
.addJavadoc("Configure the endpointProvider")
.build())
.build();
}

Expand Down Expand Up @@ -150,6 +158,14 @@ private TypeSpec builderImplSpec() {
.addStatement("this.endpointOverride = endpointOverride")
.addStatement("return this")
.build())
.addMethod(MethodSpec.methodBuilder("endpointProvider")
.addAnnotation(Override.class)
.addModifiers(PUBLIC)
.addParameter(EndpointProvider.class, "endpointProvider")
.returns(className().nestedClass("Builder"))
.addStatement("this.endpointProvider = endpointProvider")
.addStatement("return this")
.build())
.addMethod(MethodSpec.methodBuilder("build")
.addAnnotation(Override.class)
.addModifiers(PUBLIC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import java.util.Map;
import javax.lang.model.element.Modifier;
Expand All @@ -33,6 +35,8 @@
import software.amazon.awssdk.codegen.poet.ClassSpec;
import software.amazon.awssdk.codegen.poet.PoetUtils;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

public class EndpointParametersClassSpec implements ClassSpec {
private final IntermediateModel intermediateModel;
Expand All @@ -53,13 +57,16 @@ public TypeSpec poetSpec() {
.addType(builderInterfaceSpec())
.addType(builderImplSpec())
.addAnnotation(SdkPublicApi.class)
.addSuperinterface(toCopyableBuilderInterface())
.addModifiers(Modifier.PUBLIC, Modifier.FINAL);

parameters().forEach((name, model) -> {
b.addField(fieldSpec(name, model).toBuilder().addModifiers(Modifier.FINAL).build());
b.addMethod(accessorMethod(name, model));
});

b.addMethod(toBuilderMethod());

return b.build();
}

Expand All @@ -70,6 +77,7 @@ public ClassName className() {

private TypeSpec builderInterfaceSpec() {
TypeSpec.Builder b = TypeSpec.interfaceBuilder(builderInterfaceName())
.addSuperinterface(copyableBuilderExtendsInterface())
.addModifiers(Modifier.PUBLIC);

parameters().forEach((name, model) -> {
Expand All @@ -89,6 +97,11 @@ private TypeSpec builderImplSpec() {
.addModifiers(Modifier.PRIVATE, Modifier.STATIC)
.addSuperinterface(builderInterfaceName());

b.addMethod(MethodSpec.constructorBuilder()
.addModifiers(Modifier.PRIVATE)
.build());
b.addMethod(toBuilderConstructor().build());

parameters().forEach((name, model) -> {
b.addField(fieldSpec(name, model).toBuilder().initializer(defaultValueCode(model)).build());
b.addMethod(builderSetterMethod(name, model));
Expand Down Expand Up @@ -183,6 +196,14 @@ private MethodSpec builderMethod() {
.build();
}

private MethodSpec toBuilderMethod() {
return MethodSpec.methodBuilder("toBuilder")
.addModifiers(Modifier.PUBLIC)
.returns(builderInterfaceName())
.addStatement("return new $T(this)", builderClassName())
.build();
}

private String variableName(String name) {
return intermediateModel.getNamingStrategy().getVariableName(name);
}
Expand Down Expand Up @@ -224,4 +245,25 @@ private MethodSpec.Builder paramMethodBuilder(String name, ParameterModel model)
}
return b;
}

private MethodSpec.Builder toBuilderConstructor() {
MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder();
constructorBuilder.addModifiers(Modifier.PRIVATE);
constructorBuilder.addParameter(className(), "builder");
parameters().forEach((name, model) -> {
constructorBuilder.addStatement("this.$1N = builder.$1N", variableName(name));
});
return constructorBuilder;
}

private TypeName toCopyableBuilderInterface() {
return ParameterizedTypeName.get(ClassName.get(ToCopyableBuilder.class),
className().nestedClass(builderInterfaceName().simpleName()),
className());
}

private TypeName copyableBuilderExtendsInterface() {
return ParameterizedTypeName.get(ClassName.get(CopyableBuilder.class),
builderInterfaceName(), className());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.endpoints.EndpointProvider;
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;

/**
Expand All @@ -33,13 +34,14 @@ protected final JsonAsyncClient buildClient() {
SdkClientConfiguration clientConfiguration = super.asyncClientConfiguration();
this.validateClientOptions(clientConfiguration);
URI endpointOverride = null;
EndpointProvider endpointProvider = clientConfiguration.option(SdkClientOption.ENDPOINT_PROVIDER);
if (clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) != null
&& Boolean.TRUE.equals(clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN))) {
endpointOverride = clientConfiguration.option(SdkClientOption.ENDPOINT);
}
JsonServiceClientConfiguration serviceClientConfiguration = JsonServiceClientConfiguration.builder()
.overrideConfiguration(overrideConfiguration()).region(clientConfiguration.option(AwsClientOption.AWS_REGION))
.endpointOverride(endpointOverride).build();
.endpointOverride(endpointOverride).endpointProvider(endpointProvider).build();
return new DefaultJsonAsyncClient(serviceClientConfiguration, clientConfiguration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.endpoints.EndpointProvider;
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;

/**
Expand All @@ -33,13 +34,14 @@ protected final JsonClient buildClient() {
SdkClientConfiguration clientConfiguration = super.syncClientConfiguration();
this.validateClientOptions(clientConfiguration);
URI endpointOverride = null;
EndpointProvider endpointProvider = clientConfiguration.option(SdkClientOption.ENDPOINT_PROVIDER);
if (clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) != null
&& Boolean.TRUE.equals(clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN))) {
endpointOverride = clientConfiguration.option(SdkClientOption.ENDPOINT);
}
JsonServiceClientConfiguration serviceClientConfiguration = JsonServiceClientConfiguration.builder()
.overrideConfiguration(overrideConfiguration()).region(clientConfiguration.option(AwsClientOption.AWS_REGION))
.endpointOverride(endpointOverride).build();
.endpointOverride(endpointOverride).endpointProvider(endpointProvider).build();
return new DefaultJsonClient(serviceClientConfiguration, clientConfiguration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.awscore.AwsServiceClientConfiguration;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.endpoints.EndpointProvider;
import software.amazon.awssdk.regions.Region;

/**
Expand Down Expand Up @@ -45,6 +46,13 @@ public interface Builder extends AwsServiceClientConfiguration.Builder {
*/
@Override
Builder overrideConfiguration(ClientOverrideConfiguration clientOverrideConfiguration);

/**
* Configure the endpointProvider
*/
@Override
Builder endpointProvider(EndpointProvider endpointProvider);

}

private static final class BuilderImpl extends AwsServiceClientConfiguration.BuilderImpl implements Builder {
Expand Down Expand Up @@ -73,6 +81,12 @@ public Builder endpointOverride(URI endpointOverride) {
return this;
}

@Override
public Builder endpointProvider(EndpointProvider endpointProvider) {
this.endpointProvider = endpointProvider;
return this;
}

@Override
public JsonProtocolTestsServiceClientConfiguration build() {
return new JsonProtocolTestsServiceClientConfiguration(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

/**
* The parameters object used to resolve an endpoint for the Query service.
*/
@Generated("software.amazon.awssdk:codegen")
@SdkPublicApi
public final class QueryEndpointParams {
public final class QueryEndpointParams implements ToCopyableBuilder<QueryEndpointParams.Builder, QueryEndpointParams> {
private final Region region;

private final Boolean useDualStackEndpoint;
Expand Down Expand Up @@ -88,7 +90,11 @@ public String operationContextParam() {
return operationContextParam;
}

public interface Builder {
public Builder toBuilder() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this class implement ToCopyableBuilder if we are adding toBuilder method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return new BuilderImpl(this);
}

public interface Builder extends CopyableBuilder<Builder, QueryEndpointParams> {
Builder region(Region region);

Builder useDualStackEndpoint(Boolean useDualStackEndpoint);
Expand Down Expand Up @@ -134,6 +140,22 @@ private static class BuilderImpl implements Builder {

private String operationContextParam;

private BuilderImpl() {
}

private BuilderImpl(QueryEndpointParams builder) {
this.region = builder.region;
this.useDualStackEndpoint = builder.useDualStackEndpoint;
this.useFIPSEndpoint = builder.useFIPSEndpoint;
this.endpointId = builder.endpointId;
this.defaultTrueParam = builder.defaultTrueParam;
this.defaultStringParam = builder.defaultStringParam;
this.deprecatedParam = builder.deprecatedParam;
this.booleanContextParam = builder.booleanContextParam;
this.stringContextParam = builder.stringContextParam;
this.operationContextParam = builder.operationContextParam;
}

@Override
public Builder region(Region region) {
this.region = region;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.core.SdkServiceClientConfiguration;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.endpoints.EndpointProvider;
import software.amazon.awssdk.regions.Region;

/**
Expand Down Expand Up @@ -81,6 +82,9 @@ public interface Builder extends SdkServiceClientConfiguration.Builder {
@Override
Builder endpointOverride(URI endpointOverride);

@Override
Builder endpointProvider(EndpointProvider endpointProvider);

@Override
AwsServiceClientConfiguration build();
}
Expand All @@ -89,6 +93,7 @@ protected abstract static class BuilderImpl implements Builder {
protected ClientOverrideConfiguration overrideConfiguration;
protected Region region;
protected URI endpointOverride;
protected EndpointProvider endpointProvider;

protected BuilderImpl() {
}
Expand All @@ -97,6 +102,7 @@ protected BuilderImpl(AwsServiceClientConfiguration awsServiceClientConfiguratio
this.overrideConfiguration = awsServiceClientConfiguration.overrideConfiguration();
this.region = awsServiceClientConfiguration.region();
this.endpointOverride = awsServiceClientConfiguration.endpointOverride().orElse(null);
this.endpointProvider = awsServiceClientConfiguration.endpointProvider().orElse(null);
}

@Override
Expand All @@ -113,6 +119,12 @@ public final Region region() {
public final URI endpointOverride() {
return endpointOverride;
}

@Override
public final EndpointProvider endpointProvider() {
return endpointProvider;
}

}

}
Loading