Skip to content

Commit 77abd70

Browse files
authored
Merge branch 'feature/master/core-interceptors-migration' into somepal/endpoint-resolution-refactoring
2 parents 7b09efe + bfc51a7 commit 77abd70

5 files changed

Lines changed: 187 additions & 51 deletions

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/auth/scheme/query-endpoint-auth-params-auth-scheme-params-with-allowlist.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import software.amazon.awssdk.http.auth.aws.signer.RegionSet;
2121
import software.amazon.awssdk.regions.Region;
2222
import software.amazon.awssdk.services.query.auth.scheme.internal.DefaultQueryAuthSchemeParams;
23+
import software.amazon.awssdk.services.query.endpoints.QueryEndpointParams;
2324
import software.amazon.awssdk.utils.builder.CopyableBuilder;
2425
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
2526

@@ -36,6 +37,25 @@ static Builder builder() {
3637
return DefaultQueryAuthSchemeParams.builder();
3738
}
3839

40+
/**
41+
* Create a builder pre-populated with endpoint parameters.
42+
*
43+
* @param endpointParams
44+
* the endpoint parameters to copy
45+
* @return a builder with values from the endpoint parameters
46+
*/
47+
static Builder fromEndpointParams(QueryEndpointParams endpointParams) {
48+
Builder builder = builder();
49+
builder.region(endpointParams.region());
50+
builder.defaultTrueParam(endpointParams.defaultTrueParam());
51+
builder.defaultStringParam(endpointParams.defaultStringParam());
52+
builder.deprecatedParam(endpointParams.deprecatedParam());
53+
builder.booleanContextParam(endpointParams.booleanContextParam());
54+
builder.stringContextParam(endpointParams.stringContextParam());
55+
builder.operationContextParam(endpointParams.operationContextParam());
56+
return builder;
57+
}
58+
3959
/**
4060
* Returns the operation for which to resolve the auth scheme.
4161
*/

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/auth/scheme/query-endpoint-auth-params-auth-scheme-params-without-allowlist.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import software.amazon.awssdk.http.auth.aws.signer.RegionSet;
77
import software.amazon.awssdk.regions.Region;
88
import software.amazon.awssdk.services.query.auth.scheme.internal.DefaultQueryAuthSchemeParams;
9+
import software.amazon.awssdk.services.query.endpoints.QueryEndpointParams;
910
import software.amazon.awssdk.utils.builder.CopyableBuilder;
1011
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
1112

@@ -22,6 +23,32 @@ static Builder builder() {
2223
return DefaultQueryAuthSchemeParams.builder();
2324
}
2425

26+
/**
27+
* Create a builder pre-populated with endpoint parameters.
28+
*
29+
* @param endpointParams
30+
* the endpoint parameters to copy
31+
* @return a builder with values from the endpoint parameters
32+
*/
33+
static Builder fromEndpointParams(QueryEndpointParams endpointParams) {
34+
Builder builder = builder();
35+
builder.region(endpointParams.region());
36+
builder.useDualStackEndpoint(endpointParams.useDualStackEndpoint());
37+
builder.useFipsEndpoint(endpointParams.useFipsEndpoint());
38+
builder.accountId(endpointParams.accountId());
39+
builder.accountIdEndpointMode(endpointParams.accountIdEndpointMode());
40+
builder.listOfStrings(endpointParams.listOfStrings());
41+
builder.defaultListOfStrings(endpointParams.defaultListOfStrings());
42+
builder.endpointId(endpointParams.endpointId());
43+
builder.defaultTrueParam(endpointParams.defaultTrueParam());
44+
builder.defaultStringParam(endpointParams.defaultStringParam());
45+
builder.deprecatedParam(endpointParams.deprecatedParam());
46+
builder.booleanContextParam(endpointParams.booleanContextParam());
47+
builder.stringContextParam(endpointParams.stringContextParam());
48+
builder.operationContextParam(endpointParams.operationContextParam());
49+
return builder;
50+
}
51+
2552
/**
2653
* Returns the operation for which to resolve the auth scheme.
2754
*/

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-h2-usePriorKnowledgeForH2-service-client-builder-class.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption;
3232
import software.amazon.awssdk.retries.api.RetryStrategy;
3333
import software.amazon.awssdk.services.h2.auth.scheme.H2AuthSchemeProvider;
34-
import software.amazon.awssdk.services.h2.auth.scheme.internal.H2AuthSchemeInterceptor;
3534
import software.amazon.awssdk.services.h2.endpoints.H2EndpointProvider;
3635
import software.amazon.awssdk.services.h2.endpoints.internal.H2RequestSetEndpointInterceptor;
3736
import software.amazon.awssdk.services.h2.endpoints.internal.H2ResolveEndpointInterceptor;
@@ -70,7 +69,6 @@ protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfigurati
7069
@Override
7170
protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
7271
List<ExecutionInterceptor> endpointInterceptors = new ArrayList<>();
73-
endpointInterceptors.add(new H2AuthSchemeInterceptor());
7472
endpointInterceptors.add(new H2ResolveEndpointInterceptor());
7573
endpointInterceptors.add(new H2RequestSetEndpointInterceptor());
7674
ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory();

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-custom-context-params-async-client-class.java

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.slf4j.LoggerFactory;
1414
import software.amazon.awssdk.annotations.Generated;
1515
import software.amazon.awssdk.annotations.SdkInternalApi;
16+
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
1617
import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler;
1718
import software.amazon.awssdk.awscore.exception.AwsServiceException;
1819
import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata;
@@ -29,6 +30,7 @@
2930
import software.amazon.awssdk.core.http.HttpResponseHandler;
3031
import software.amazon.awssdk.core.metrics.CoreMetric;
3132
import software.amazon.awssdk.core.retry.RetryMode;
33+
import software.amazon.awssdk.http.auth.spi.scheme.AuthSchemeOption;
3234
import software.amazon.awssdk.metrics.MetricCollector;
3335
import software.amazon.awssdk.metrics.MetricPublisher;
3436
import software.amazon.awssdk.metrics.NoOpMetricCollector;
@@ -38,6 +40,8 @@
3840
import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory;
3941
import software.amazon.awssdk.protocols.json.JsonOperationMetadata;
4042
import software.amazon.awssdk.retries.api.RetryStrategy;
43+
import software.amazon.awssdk.services.foobar.auth.scheme.FooBarAuthSchemeParams;
44+
import software.amazon.awssdk.services.foobar.auth.scheme.FooBarAuthSchemeProvider;
4145
import software.amazon.awssdk.services.foobar.endpoints.FooBarClientContextParams;
4246
import software.amazon.awssdk.services.foobar.internal.FooBarServiceClientConfigurationBuilder;
4347
import software.amazon.awssdk.services.foobar.internal.ServiceVersionInfo;
@@ -60,7 +64,7 @@ final class DefaultFooBarAsyncClient implements FooBarAsyncClient {
6064
private static final Logger log = LoggerFactory.getLogger(DefaultFooBarAsyncClient.class);
6165

6266
private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder()
63-
.serviceProtocol(AwsServiceProtocol.REST_JSON).build();
67+
.serviceProtocol(AwsServiceProtocol.REST_JSON).build();
6468

6569
private final AsyncClientHandler clientHandler;
6670

@@ -71,7 +75,7 @@ final class DefaultFooBarAsyncClient implements FooBarAsyncClient {
7175
protected DefaultFooBarAsyncClient(SdkClientConfiguration clientConfiguration) {
7276
this.clientHandler = new AwsAsyncClientHandler(clientConfiguration);
7377
this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this)
74-
.option(SdkClientOption.API_METADATA, "Foo_Bar" + "#" + ServiceVersionInfo.VERSION).build();
78+
.option(SdkClientOption.API_METADATA, "Foo_Bar" + "#" + ServiceVersionInfo.VERSION).build();
7579
this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build();
7680
}
7781

@@ -100,38 +104,43 @@ protected DefaultFooBarAsyncClient(SdkClientConfiguration clientConfiguration) {
100104
@Override
101105
public CompletableFuture<GetDatabaseVersionResponse> getDatabaseVersion(GetDatabaseVersionRequest getDatabaseVersionRequest) {
102106
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getDatabaseVersionRequest,
103-
this.clientConfiguration);
107+
this.clientConfiguration);
104108
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, getDatabaseVersionRequest
105-
.overrideConfiguration().orElse(null));
109+
.overrideConfiguration().orElse(null));
106110
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
107-
.create("ApiCall");
111+
.create("ApiCall");
108112
try {
109113
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Foo Bar");
110114
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetDatabaseVersion");
111115
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
112-
.isPayloadJson(true).build();
116+
.isPayloadJson(true).build();
113117

114118
HttpResponseHandler<GetDatabaseVersionResponse> responseHandler = protocolFactory.createResponseHandler(
115-
operationMetadata, GetDatabaseVersionResponse::builder);
119+
operationMetadata, GetDatabaseVersionResponse::builder);
116120
Function<String, Optional<ExceptionMetadata>> exceptionMetadataMapper = errorCode -> {
117121
if (errorCode == null) {
118122
return Optional.empty();
119123
}
120124
switch (errorCode) {
121-
default:
122-
return Optional.empty();
125+
default:
126+
return Optional.empty();
123127
}
124128
};
125129
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
126-
operationMetadata, exceptionMetadataMapper);
130+
operationMetadata, exceptionMetadataMapper);
127131

128132
CompletableFuture<GetDatabaseVersionResponse> executeFuture = clientHandler
129-
.execute(new ClientExecutionParams<GetDatabaseVersionRequest, GetDatabaseVersionResponse>()
130-
.withOperationName("GetDatabaseVersion").withProtocolMetadata(protocolMetadata)
131-
.withMarshaller(new GetDatabaseVersionRequestMarshaller(protocolFactory))
132-
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
133-
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
134-
.withInput(getDatabaseVersionRequest));
133+
.execute(new ClientExecutionParams<GetDatabaseVersionRequest, GetDatabaseVersionResponse>()
134+
.withOperationName("GetDatabaseVersion")
135+
.withProtocolMetadata(protocolMetadata)
136+
.withMarshaller(new GetDatabaseVersionRequestMarshaller(protocolFactory))
137+
.withResponseHandler(responseHandler)
138+
.withErrorResponseHandler(errorResponseHandler)
139+
.withRequestConfiguration(clientConfiguration)
140+
.withMetricCollector(apiCallMetricCollector)
141+
.withAuthSchemeOptionsResolver(
142+
r -> resolveAuthSchemeOptions(r, "GetDatabaseVersion", clientConfiguration))
143+
.withInput(getDatabaseVersionRequest));
135144
CompletableFuture<GetDatabaseVersionResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
136145
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
137146
});
@@ -155,11 +164,11 @@ public final String serviceName() {
155164

156165
private <T extends BaseAwsJsonProtocolFactory.Builder<T>> T init(T builder) {
157166
return builder.clientConfiguration(clientConfiguration).defaultServiceExceptionSupplier(FooBarException::builder)
158-
.protocol(AwsJsonProtocol.REST_JSON).protocolVersion("1.1");
167+
.protocol(AwsJsonProtocol.REST_JSON).protocolVersion("1.1");
159168
}
160169

161170
private static List<MetricPublisher> resolveMetricPublishers(SdkClientConfiguration clientConfiguration,
162-
RequestOverrideConfiguration requestOverrideConfiguration) {
171+
RequestOverrideConfiguration requestOverrideConfiguration) {
163172
List<MetricPublisher> publishers = null;
164173
if (requestOverrideConfiguration != null) {
165174
publishers = requestOverrideConfiguration.metricPublishers();
@@ -173,6 +182,17 @@ private static List<MetricPublisher> resolveMetricPublishers(SdkClientConfigurat
173182
return publishers;
174183
}
175184

185+
private List<AuthSchemeOption> resolveAuthSchemeOptions(SdkRequest request, String operationName,
186+
SdkClientConfiguration clientConfiguration) {
187+
FooBarAuthSchemeProvider authSchemeProvider = Validate.isInstanceOf(FooBarAuthSchemeProvider.class,
188+
clientConfiguration.option(SdkClientOption.AUTH_SCHEME_PROVIDER),
189+
"Expected an instance of FooBarAuthSchemeProvider");
190+
FooBarAuthSchemeParams.Builder paramsBuilder = FooBarAuthSchemeParams.builder().operation(operationName);
191+
paramsBuilder.region(clientConfiguration.option(AwsClientOption.AWS_REGION));
192+
List<AuthSchemeOption> options = authSchemeProvider.resolveAuthScheme(paramsBuilder.build());
193+
return options;
194+
}
195+
176196
private void updateRetryStrategyClientConfiguration(SdkClientConfiguration.Builder configuration) {
177197
ClientOverrideConfiguration.Builder builder = configuration.asOverrideConfigurationBuilder();
178198
RetryMode retryMode = builder.retryMode();
@@ -211,15 +231,15 @@ private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request,
211231
newContextParams = (newContextParams != null) ? newContextParams : AttributeMap.empty();
212232
originalContextParams = originalContextParams != null ? originalContextParams : AttributeMap.empty();
213233
Validate.validState(
214-
Objects.equals(originalContextParams.get(FooBarClientContextParams.CROSS_REGION_ACCESS_ENABLED),
215-
newContextParams.get(FooBarClientContextParams.CROSS_REGION_ACCESS_ENABLED)),
216-
"CROSS_REGION_ACCESS_ENABLED cannot be modified by request level plugins");
234+
Objects.equals(originalContextParams.get(FooBarClientContextParams.CROSS_REGION_ACCESS_ENABLED),
235+
newContextParams.get(FooBarClientContextParams.CROSS_REGION_ACCESS_ENABLED)),
236+
"CROSS_REGION_ACCESS_ENABLED cannot be modified by request level plugins");
217237
updateRetryStrategyClientConfiguration(configuration);
218238
return configuration.build();
219239
}
220240

221241
private HttpResponseHandler<AwsServiceException> createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory,
222-
JsonOperationMetadata operationMetadata, Function<String, Optional<ExceptionMetadata>> exceptionMetadataMapper) {
242+
JsonOperationMetadata operationMetadata, Function<String, Optional<ExceptionMetadata>> exceptionMetadataMapper) {
223243
return protocolFactory.createErrorResponseHandler(operationMetadata, exceptionMetadataMapper);
224244
}
225245

0 commit comments

Comments
 (0)