Skip to content

Commit 0140729

Browse files
dagnirjoviegaszoewangg
authored
Skip rules based endpoints for most services (#3520)
* Skip rules based endpoints for most services We are only enabling rules based endpoints for S3, S3Control, and EventBridge for now in order to roll back incorrect hostprefix handling in the Java SDK. S3, S3Control, and EventBridge are unaffected by this issue because their rules are handwritten, and in the case of S3Control which has a host prefix in the model, it is handled by the rule set. Co-authored-by: John Viegas <[email protected]> Co-authored-by: Zoe Wang <[email protected]>
1 parent 825f8a7 commit 0140729

38 files changed

+151
-201
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWs SDK for Java v2",
4+
"contributor": "",
5+
"description": "We are only enabling rules based endpoints for S3, S3Control, and EventBridge for now in order to roll back incorrect hostprefix handling in the Java SDK. EventBridge are unaffected by this issue because it does not have a `hostPrefix` in its service model. S3 and S3Control have `hostPrefix` in the model, it is handled by the rule set."
6+
}

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/EndpointProviderTasks.java

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.ArrayList;
1919
import java.util.Arrays;
2020
import java.util.Collection;
21+
import java.util.Collections;
2122
import java.util.List;
2223
import java.util.Map;
2324
import software.amazon.awssdk.codegen.emitters.GeneratorTask;
@@ -45,6 +46,10 @@ public EndpointProviderTasks(GeneratorTaskParams dependencies) {
4546

4647
@Override
4748
protected List<GeneratorTask> createTasks() throws Exception {
49+
if (!generatorTaskParams.getModel().getCustomizationConfig().useRuleBasedEndpoints()) {
50+
return Collections.emptyList();
51+
}
52+
4853
List<GeneratorTask> tasks = new ArrayList<>();
4954
tasks.add(generateInterface());
5055
tasks.add(generateParams());

codegen/src/main/java/software/amazon/awssdk/codegen/model/config/customization/CustomizationConfig.java

+12
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ public class CustomizationConfig {
213213

214214
private boolean useGlobalEndpoint;
215215

216+
/**
217+
* Whether Endpoints 2.0/rule based endpoints should be used for endpoint resolution.
218+
*/
219+
private boolean useRuleBasedEndpoints = false;
220+
216221
private CustomizationConfig() {
217222
}
218223

@@ -550,4 +555,11 @@ public void setSkipEndpointTests(Map<String, String> skipEndpointTests) {
550555
this.skipEndpointTests = skipEndpointTests;
551556
}
552557

558+
public boolean useRuleBasedEndpoints() {
559+
return useRuleBasedEndpoints;
560+
}
561+
562+
public void setUseRuleBasedEndpoints(boolean useRuleBasedEndpoints) {
563+
this.useRuleBasedEndpoints = useRuleBasedEndpoints;
564+
}
553565
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/AsyncClientBuilderClass.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public TypeSpec poetSpec() {
6868
}
6969
}
7070

71-
builder.addMethod(endpointProviderMethod());
71+
if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
72+
builder.addMethod(endpointProviderMethod());
73+
}
7274

7375
if (BearerAuthUtils.usesBearerAuth(model)) {
7476
builder.addMethod(bearerTokenProviderMethod());

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ public TypeSpec poetSpec() {
110110
builder.addMethod(finalizeServiceConfigurationMethod());
111111
defaultAwsAuthSignerMethod().ifPresent(builder::addMethod);
112112
builder.addMethod(signingNameMethod());
113-
builder.addMethod(defaultEndpointProviderMethod());
113+
if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
114+
builder.addMethod(defaultEndpointProviderMethod());
115+
}
114116

115-
if (hasClientContextParams()) {
117+
if (hasClientContextParams() && endpointRulesSpecUtils.isEndpointRulesEnabled()) {
116118
model.getClientContextParams().forEach((n, m) -> {
117119
builder.addMethod(clientContextParamSetter(n, m));
118120
});
@@ -184,9 +186,11 @@ private MethodSpec mergeServiceDefaultsMethod() {
184186
.addModifiers(PROTECTED, FINAL)
185187
.returns(SdkClientConfiguration.class)
186188
.addParameter(SdkClientConfiguration.class, "config")
187-
.addCode("return config.merge(c -> c")
188-
.addCode(".option($T.ENDPOINT_PROVIDER, defaultEndpointProvider())",
189-
SdkClientOption.class);
189+
.addCode("return config.merge(c -> c");
190+
191+
if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
192+
builder.addCode(".option($T.ENDPOINT_PROVIDER, defaultEndpointProvider())", SdkClientOption.class);
193+
}
190194

191195
if (defaultAwsAuthSignerMethod().isPresent()) {
192196
builder.addCode(".option($T.SIGNER, defaultSigner())\n", SdkAdvancedClientOption.class);
@@ -252,9 +256,11 @@ private MethodSpec finalizeServiceConfigurationMethod() {
252256
ParameterizedTypeName.get(List.class, ExecutionInterceptor.class),
253257
ArrayList.class);
254258

255-
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.resolverInterceptorName());
256-
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.authSchemesInterceptorName());
257-
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.requestModifierInterceptorName());
259+
if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
260+
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.resolverInterceptorName());
261+
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.authSchemesInterceptorName());
262+
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.requestModifierInterceptorName());
263+
}
258264

259265
builder.addCode("$1T interceptorFactory = new $1T();\n", ClasspathInterceptorChainFactory.class)
260266
.addCode("$T<$T> interceptors = interceptorFactory.getInterceptors($S);\n",

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderInterface.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ public TypeSpec poetSpec() {
7373
builder.addMethod(serviceConfigurationConsumerBuilderMethod());
7474
}
7575

76-
builder.addMethod(endpointProviderMethod());
76+
if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
77+
builder.addMethod(endpointProviderMethod());
7778

78-
if (hasClientContextParams()) {
79-
model.getClientContextParams().forEach((n, m) -> {
80-
builder.addMethod(clientContextParamSetter(n, m));
81-
});
79+
if (hasClientContextParams()) {
80+
model.getClientContextParams().forEach((n, m) -> {
81+
builder.addMethod(clientContextParamSetter(n, m));
82+
});
83+
}
8284
}
8385

8486
if (generateTokenProviderMethod()) {

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/SyncClientBuilderClass.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public TypeSpec poetSpec() {
6868
}
6969
}
7070

71-
builder.addMethod(endpointProviderMethod());
71+
if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
72+
builder.addMethod(endpointProviderMethod());
73+
}
7274

7375
if (BearerAuthUtils.usesBearerAuth(model)) {
7476
builder.addMethod(tokenProviderMethodImpl());

codegen/src/main/java/software/amazon/awssdk/codegen/poet/rules/EndpointRulesSpecUtils.java

+4
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,8 @@ public boolean isS3Control() {
182182
public TypeName resolverReturnType() {
183183
return ParameterizedTypeName.get(CompletableFuture.class, Endpoint.class);
184184
}
185+
186+
public boolean isEndpointRulesEnabled() {
187+
return intermediateModel.getCustomizationConfig().useRuleBasedEndpoints();
188+
}
185189
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-async-client-builder-class.java

-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import software.amazon.awssdk.annotations.SdkInternalApi;
55
import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
66
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
7-
import software.amazon.awssdk.core.client.config.SdkClientOption;
8-
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;
97

108
/**
119
* Internal implementation of {@link JsonAsyncClientBuilder}.
@@ -14,12 +12,6 @@
1412
@SdkInternalApi
1513
final class DefaultJsonAsyncClientBuilder extends DefaultJsonBaseClientBuilder<JsonAsyncClientBuilder, JsonAsyncClient> implements
1614
JsonAsyncClientBuilder {
17-
@Override
18-
public DefaultJsonAsyncClientBuilder endpointProvider(JsonEndpointProvider endpointProvider) {
19-
clientConfiguration.option(SdkClientOption.ENDPOINT_PROVIDER, endpointProvider);
20-
return this;
21-
}
22-
2315
@Override
2416
public DefaultJsonAsyncClientBuilder tokenProvider(SdkTokenProvider tokenProvider) {
2517
clientConfiguration.option(AwsClientOption.TOKEN_PROVIDER, tokenProvider);

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-bearer-auth-client-builder-class.java

+2-14
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory;
1616
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
1717
import software.amazon.awssdk.core.signer.Signer;
18-
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;
19-
import software.amazon.awssdk.services.json.endpoints.internal.JsonEndpointAuthSchemeInterceptor;
20-
import software.amazon.awssdk.services.json.endpoints.internal.JsonRequestSetEndpointInterceptor;
21-
import software.amazon.awssdk.services.json.endpoints.internal.JsonResolveEndpointInterceptor;
2218
import software.amazon.awssdk.utils.CollectionUtils;
2319

2420
/**
@@ -39,18 +35,14 @@ protected final String serviceName() {
3935

4036
@Override
4137
protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) {
42-
return config.merge(c -> c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider())
43-
.option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false)
38+
return config.merge(c -> c.option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false)
4439
.option(AwsClientOption.TOKEN_PROVIDER, defaultTokenProvider())
4540
.option(SdkAdvancedClientOption.TOKEN_SIGNER, defaultTokenSigner()));
4641
}
4742

4843
@Override
4944
protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
5045
List<ExecutionInterceptor> endpointInterceptors = new ArrayList<>();
51-
endpointInterceptors.add(new JsonResolveEndpointInterceptor());
52-
endpointInterceptors.add(new JsonEndpointAuthSchemeInterceptor());
53-
endpointInterceptors.add(new JsonRequestSetEndpointInterceptor());
5446
ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory();
5547
List<ExecutionInterceptor> interceptors = interceptorFactory
5648
.getInterceptors("software/amazon/awssdk/services/json/execution.interceptors");
@@ -66,15 +58,11 @@ protected final String signingName() {
6658
return "json-service";
6759
}
6860

69-
private JsonEndpointProvider defaultEndpointProvider() {
70-
return JsonEndpointProvider.defaultProvider();
71-
}
72-
7361
private SdkTokenProvider defaultTokenProvider() {
7462
return DefaultAwsTokenProvider.create();
7563
}
7664

7765
private Signer defaultTokenSigner() {
7866
return BearerTokenSigner.create();
7967
}
80-
}
68+
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-bearer-auth-client-builder-interface.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,13 @@
33
import software.amazon.awssdk.annotations.Generated;
44
import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
55
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
6-
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;
76

87
/**
98
* This includes configuration specific to Json Service that is supported by both {@link JsonClientBuilder} and
109
* {@link JsonAsyncClientBuilder}.
1110
*/
1211
@Generated("software.amazon.awssdk:codegen")
1312
public interface JsonBaseClientBuilder<B extends JsonBaseClientBuilder<B, C>, C> extends AwsClientBuilder<B, C> {
14-
/**
15-
* Set the {@link JsonEndpointProvider} implementation that will be used by the client to determine the endpoint for
16-
* each request. This is optional; if none is provided a default implementation will be used the SDK.
17-
*/
18-
B endpointProvider(JsonEndpointProvider endpointProvider);
19-
2013
/**
2114
* Set the token provider to use for bearer token authorization. This is optional, if none is provided, the SDK will
2215
* use {@link software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider}.
@@ -29,4 +22,4 @@ public interface JsonBaseClientBuilder<B extends JsonBaseClientBuilder<B, C>, C>
2922
* default it is {@link software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner}.
3023
*/
3124
B tokenProvider(SdkTokenProvider tokenProvider);
32-
}
25+
}

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

+1-13
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
2020
import software.amazon.awssdk.core.signer.Signer;
2121
import software.amazon.awssdk.services.json.endpoints.JsonClientContextParams;
22-
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;
23-
import software.amazon.awssdk.services.json.endpoints.internal.JsonEndpointAuthSchemeInterceptor;
24-
import software.amazon.awssdk.services.json.endpoints.internal.JsonRequestSetEndpointInterceptor;
25-
import software.amazon.awssdk.services.json.endpoints.internal.JsonResolveEndpointInterceptor;
2622
import software.amazon.awssdk.utils.AttributeMap;
2723
import software.amazon.awssdk.utils.CollectionUtils;
2824
import software.amazon.awssdk.utils.Validate;
@@ -45,8 +41,7 @@ protected final String serviceName() {
4541

4642
@Override
4743
protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) {
48-
return config.merge(c -> c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider())
49-
.option(SdkAdvancedClientOption.SIGNER, defaultSigner())
44+
return config.merge(c -> c.option(SdkAdvancedClientOption.SIGNER, defaultSigner())
5045
.option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false)
5146
.option(SdkClientOption.SERVICE_CONFIGURATION, ServiceConfiguration.builder().build())
5247
.option(AwsClientOption.TOKEN_PROVIDER, defaultTokenProvider())
@@ -56,9 +51,6 @@ protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfigurati
5651
@Override
5752
protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
5853
List<ExecutionInterceptor> endpointInterceptors = new ArrayList<>();
59-
endpointInterceptors.add(new JsonResolveEndpointInterceptor());
60-
endpointInterceptors.add(new JsonEndpointAuthSchemeInterceptor());
61-
endpointInterceptors.add(new JsonRequestSetEndpointInterceptor());
6254
ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory();
6355
List<ExecutionInterceptor> interceptors = interceptorFactory
6456
.getInterceptors("software/amazon/awssdk/services/json/execution.interceptors");
@@ -137,10 +129,6 @@ protected final String signingName() {
137129
return "json-service";
138130
}
139131

140-
private JsonEndpointProvider defaultEndpointProvider() {
141-
return JsonEndpointProvider.defaultProvider();
142-
}
143-
144132
public B serviceConfiguration(ServiceConfiguration serviceConfiguration) {
145133
clientConfiguration.option(SdkClientOption.SERVICE_CONFIGURATION, serviceConfiguration);
146134
return thisBuilder();

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-interface.java

-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import software.amazon.awssdk.annotations.Generated;
55
import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
66
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
7-
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;
87

98
/**
109
* This includes configuration specific to Json Service that is supported by both {@link JsonClientBuilder} and
@@ -18,12 +17,6 @@ default B serviceConfiguration(Consumer<ServiceConfiguration.Builder> serviceCon
1817
return serviceConfiguration(ServiceConfiguration.builder().applyMutation(serviceConfiguration).build());
1918
}
2019

21-
/**
22-
* Set the {@link JsonEndpointProvider} implementation that will be used by the client to determine the endpoint for
23-
* each request. This is optional; if none is provided a default implementation will be used the SDK.
24-
*/
25-
B endpointProvider(JsonEndpointProvider endpointProvider);
26-
2720
/**
2821
* Set the token provider to use for bearer token authorization. This is optional, if none is provided, the SDK will
2922
* use {@link software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider}.

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/builder/test-client-builder-internal-defaults-class.java

+2-14
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
1414
import software.amazon.awssdk.core.retry.RetryMode;
1515
import software.amazon.awssdk.core.signer.Signer;
16-
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;
17-
import software.amazon.awssdk.services.json.endpoints.internal.JsonEndpointAuthSchemeInterceptor;
18-
import software.amazon.awssdk.services.json.endpoints.internal.JsonRequestSetEndpointInterceptor;
19-
import software.amazon.awssdk.services.json.endpoints.internal.JsonResolveEndpointInterceptor;
2016
import software.amazon.awssdk.utils.CollectionUtils;
2117

2218
/**
@@ -37,9 +33,8 @@ protected final String serviceName() {
3733

3834
@Override
3935
protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) {
40-
return config.merge(c -> c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider())
41-
.option(SdkAdvancedClientOption.SIGNER, defaultSigner())
42-
.option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false));
36+
return config.merge(c -> c.option(SdkAdvancedClientOption.SIGNER, defaultSigner()).option(
37+
SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false));
4338
}
4439

4540
@Override
@@ -53,9 +48,6 @@ protected final SdkClientConfiguration mergeInternalDefaults(SdkClientConfigurat
5348
@Override
5449
protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
5550
List<ExecutionInterceptor> endpointInterceptors = new ArrayList<>();
56-
endpointInterceptors.add(new JsonResolveEndpointInterceptor());
57-
endpointInterceptors.add(new JsonEndpointAuthSchemeInterceptor());
58-
endpointInterceptors.add(new JsonRequestSetEndpointInterceptor());
5951
ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory();
6052
List<ExecutionInterceptor> interceptors = interceptorFactory
6153
.getInterceptors("software/amazon/awssdk/services/json/execution.interceptors");
@@ -74,8 +66,4 @@ private Signer defaultSigner() {
7466
protected final String signingName() {
7567
return "json-service";
7668
}
77-
78-
private JsonEndpointProvider defaultEndpointProvider() {
79-
return JsonEndpointProvider.defaultProvider();
80-
}
8169
}

0 commit comments

Comments
 (0)