Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-dccde5b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"category": "AWS SDK for Java v2",
"contributor": "",
"type": "bugfix",
"description": "Fixed an issue where request-level overrides (e.g. credentials) were not applied to endpoint discovery calls."
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.auth.signer.AsyncAws4Signer;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler;
import software.amazon.awssdk.awscore.client.handler.AwsClientHandlerUtils;
Expand Down Expand Up @@ -286,15 +287,20 @@ protected MethodSpec.Builder operationBody(MethodSpec.Builder builder, Operation

builder.addStatement("$T cachedEndpoint = null", URI.class);
builder.beginControlFlow("if (endpointDiscoveryEnabled)");
builder.addStatement("\n\nString key = clientConfiguration.option($T.CREDENTIALS_PROVIDER).resolveCredentials()" +
".accessKeyId()", AwsClientOption.class);
builder.addStatement("EndpointDiscoveryRequest endpointDiscoveryRequest = $T.builder().required($L)" +
".defaultEndpoint(clientConfiguration.option($T.ENDPOINT)).build()",
EndpointDiscoveryRequest.class,
opModel.getInputShape().getEndpointDiscovery().isRequired(),
SdkClientOption.class);
builder.addStatement("cachedEndpoint = $L.get(key, endpointDiscoveryRequest)",
"endpointDiscoveryCache");

builder.addCode("$T key = $N.overrideConfiguration()", String.class, opModel.getInput().getVariableName())
.addCode(" .flatMap($T::credentialsProvider)", AwsRequestOverrideConfiguration.class)
.addCode(" .orElseGet(() -> clientConfiguration.option($T.CREDENTIALS_PROVIDER))", AwsClientOption.class)
.addCode(" .resolveCredentials().accessKeyId();");

builder.addCode("$1T endpointDiscoveryRequest = $1T.builder()", EndpointDiscoveryRequest.class)
.addCode(" .required($L)", opModel.getInputShape().getEndpointDiscovery().isRequired())
.addCode(" .defaultEndpoint(clientConfiguration.option($T.ENDPOINT))", SdkClientOption.class)
.addCode(" .overrideConfiguration($N.overrideConfiguration().orElse(null))",
opModel.getInput().getVariableName())
.addCode(" .build();");

builder.addStatement("cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest)");
builder.endControlFlow();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.stream.Collectors;
import javax.lang.model.element.Modifier;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.codegen.docs.SimpleMethodOverload;
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
Expand Down Expand Up @@ -235,15 +236,20 @@ private List<MethodSpec> operationMethodSpecs(OperationModel opModel) {

method.addStatement("$T cachedEndpoint = null", URI.class);
method.beginControlFlow("if (endpointDiscoveryEnabled)");
method.addStatement("\n\nString key = clientConfiguration.option($T.CREDENTIALS_PROVIDER)." +
"resolveCredentials().accessKeyId()", AwsClientOption.class);
method.addStatement("EndpointDiscoveryRequest endpointDiscoveryRequest = $T.builder().required($L)" +
".defaultEndpoint(clientConfiguration.option($T.ENDPOINT)).build()",
EndpointDiscoveryRequest.class,
opModel.getInputShape().getEndpointDiscovery().isRequired(),
SdkClientOption.class);
method.addStatement("cachedEndpoint = $L.get(key, endpointDiscoveryRequest)",
"endpointDiscoveryCache");

method.addCode("$T key = $N.overrideConfiguration()", String.class, opModel.getInput().getVariableName())
.addCode(" .flatMap($T::credentialsProvider)", AwsRequestOverrideConfiguration.class)
.addCode(" .orElseGet(() -> clientConfiguration.option($T.CREDENTIALS_PROVIDER))", AwsClientOption.class)
.addCode(" .resolveCredentials().accessKeyId();");

method.addCode("$1T endpointDiscoveryRequest = $1T.builder()", EndpointDiscoveryRequest.class)
.addCode(" .required($L)", opModel.getInputShape().getEndpointDiscovery().isRequired())
.addCode(" .defaultEndpoint(clientConfiguration.option($T.ENDPOINT))", SdkClientOption.class)
.addCode(" .overrideConfiguration($N.overrideConfiguration().orElse(null))",
opModel.getInput().getVariableName())
.addCode(" .build();");

method.addStatement("cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest)");
method.endControlFlow();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
Expand Down Expand Up @@ -103,7 +104,9 @@ private MethodSpec discoverEndpoint(OperationModel opModel) {

if (!opModel.getInputShape().isHasHeaderMember()) {
ClassName endpointClass = poetExtensions.getModelClass("Endpoint");
methodBuilder.addCode("return $L.$L($L.builder().build()).thenApply(r -> {",
methodBuilder.addStatement("$1T requestConfig = $1T.from(endpointDiscoveryRequest.overrideConfiguration()"
+ ".orElse(null))", AwsRequestOverrideConfiguration.class)
.addCode("return $L.$L($L.builder().overrideConfiguration(requestConfig).build()).thenApply(r -> {",
CLIENT_FIELD,
opModel.getMethodName(),
poetExtensions.getModelClass(opModel.getInputShape().getC2jName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
Expand Down Expand Up @@ -105,7 +106,9 @@ private MethodSpec discoverEndpoint(OperationModel opModel) {
if (!opModel.getInputShape().isHasHeaderMember()) {
ClassName endpointClass = poetExtensions.getModelClass("Endpoint");
methodBuilder.addCode("return $T.supplyAsync(() -> {", CompletableFuture.class)
.addStatement("$T response = $L.$L($L.builder().build())",
.addStatement("$1T requestConfig = $1T.from(endpointDiscoveryRequest.overrideConfiguration()"
+ ".orElse(null))", AwsRequestOverrideConfiguration.class)
.addStatement("$T response = $L.$L($L.builder().overrideConfiguration(requestConfig).build())",
poetExtensions.getModelClass(opModel.getOutputShape().getC2jName()),
CLIENT_FIELD,
opModel.getMethodName(),
Expand Down
Loading