Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip rules based endpoints for most services #3520

Merged
merged 9 commits into from Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWsSDKforJavav2-ddeebe8.json
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWs SDK for Java v2",
"contributor": "",
"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."
}
4 changes: 0 additions & 4 deletions codegen-lite-maven-plugin/pom.xml
Expand Up @@ -74,10 +74,6 @@
<artifactId>maven-project</artifactId>
<groupId>org.apache.maven</groupId>
</dependency>
<dependency>
zoewangg marked this conversation as resolved.
Show resolved Hide resolved
<artifactId>plexus-utils</artifactId>
<groupId>org.codehaus.plexus</groupId>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 0 additions & 4 deletions codegen-maven-plugin/pom.xml
Expand Up @@ -79,10 +79,6 @@
<artifactId>maven-project</artifactId>
<groupId>org.apache.maven</groupId>
</dependency>
<dependency>
<artifactId>plexus-utils</artifactId>
<groupId>org.codehaus.plexus</groupId>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import software.amazon.awssdk.codegen.emitters.GeneratorTask;
Expand Down Expand Up @@ -45,6 +46,10 @@ public EndpointProviderTasks(GeneratorTaskParams dependencies) {

@Override
protected List<GeneratorTask> createTasks() throws Exception {
if (!generatorTaskParams.getModel().getCustomizationConfig().useRuleBasedEndpoints()) {
return Collections.emptyList();
}

List<GeneratorTask> tasks = new ArrayList<>();
tasks.add(generateInterface());
tasks.add(generateParams());
Expand Down
Expand Up @@ -213,6 +213,11 @@ public class CustomizationConfig {

private boolean useGlobalEndpoint;

/**
* Whether Endpoints 2.0/rule based endpoints should be used for endpoint resolution.
*/
private boolean useRuleBasedEndpoints = false;

private CustomizationConfig() {
}

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

public boolean useRuleBasedEndpoints() {
return useRuleBasedEndpoints;
}

public void setUseRuleBasedEndpoints(boolean useRuleBasedEndpoints) {
this.useRuleBasedEndpoints = useRuleBasedEndpoints;
}
}
Expand Up @@ -68,7 +68,9 @@ public TypeSpec poetSpec() {
}
}

builder.addMethod(endpointProviderMethod());
if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
builder.addMethod(endpointProviderMethod());
}

if (BearerAuthUtils.usesBearerAuth(model)) {
builder.addMethod(bearerTokenProviderMethod());
Expand Down
Expand Up @@ -110,9 +110,11 @@ public TypeSpec poetSpec() {
builder.addMethod(finalizeServiceConfigurationMethod());
defaultAwsAuthSignerMethod().ifPresent(builder::addMethod);
builder.addMethod(signingNameMethod());
builder.addMethod(defaultEndpointProviderMethod());
if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
builder.addMethod(defaultEndpointProviderMethod());
}

if (hasClientContextParams()) {
if (hasClientContextParams() && endpointRulesSpecUtils.isEndpointRulesEnabled()) {
model.getClientContextParams().forEach((n, m) -> {
builder.addMethod(clientContextParamSetter(n, m));
});
Expand Down Expand Up @@ -184,9 +186,11 @@ private MethodSpec mergeServiceDefaultsMethod() {
.addModifiers(PROTECTED, FINAL)
.returns(SdkClientConfiguration.class)
.addParameter(SdkClientConfiguration.class, "config")
.addCode("return config.merge(c -> c")
.addCode(".option($T.ENDPOINT_PROVIDER, defaultEndpointProvider())",
SdkClientOption.class);
.addCode("return config.merge(c -> c");

if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
builder.addCode(".option($T.ENDPOINT_PROVIDER, defaultEndpointProvider())", SdkClientOption.class);
}

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

builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.resolverInterceptorName());
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.authSchemesInterceptorName());
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.requestModifierInterceptorName());
if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.resolverInterceptorName());
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.authSchemesInterceptorName());
builder.addStatement("endpointInterceptors.add(new $T())", endpointRulesSpecUtils.requestModifierInterceptorName());
}

builder.addCode("$1T interceptorFactory = new $1T();\n", ClasspathInterceptorChainFactory.class)
.addCode("$T<$T> interceptors = interceptorFactory.getInterceptors($S);\n",
Expand Down
Expand Up @@ -73,12 +73,14 @@ public TypeSpec poetSpec() {
builder.addMethod(serviceConfigurationConsumerBuilderMethod());
}

builder.addMethod(endpointProviderMethod());
if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
builder.addMethod(endpointProviderMethod());

if (hasClientContextParams()) {
model.getClientContextParams().forEach((n, m) -> {
builder.addMethod(clientContextParamSetter(n, m));
});
if (hasClientContextParams()) {
model.getClientContextParams().forEach((n, m) -> {
builder.addMethod(clientContextParamSetter(n, m));
});
}
}

if (generateTokenProviderMethod()) {
Expand Down
Expand Up @@ -68,7 +68,9 @@ public TypeSpec poetSpec() {
}
}

builder.addMethod(endpointProviderMethod());
if (endpointRulesSpecUtils.isEndpointRulesEnabled()) {
builder.addMethod(endpointProviderMethod());
}

if (BearerAuthUtils.usesBearerAuth(model)) {
builder.addMethod(tokenProviderMethodImpl());
Expand Down
Expand Up @@ -182,4 +182,8 @@ public boolean isS3Control() {
public TypeName resolverReturnType() {
return ParameterizedTypeName.get(CompletableFuture.class, Endpoint.class);
}

public boolean isEndpointRulesEnabled() {
return intermediateModel.getCustomizationConfig().useRuleBasedEndpoints();
}
}
Expand Up @@ -4,8 +4,6 @@
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;

/**
* Internal implementation of {@link JsonAsyncClientBuilder}.
Expand All @@ -14,12 +12,6 @@
@SdkInternalApi
final class DefaultJsonAsyncClientBuilder extends DefaultJsonBaseClientBuilder<JsonAsyncClientBuilder, JsonAsyncClient> implements
JsonAsyncClientBuilder {
@Override
public DefaultJsonAsyncClientBuilder endpointProvider(JsonEndpointProvider endpointProvider) {
clientConfiguration.option(SdkClientOption.ENDPOINT_PROVIDER, endpointProvider);
return this;
}

@Override
public DefaultJsonAsyncClientBuilder tokenProvider(SdkTokenProvider tokenProvider) {
clientConfiguration.option(AwsClientOption.TOKEN_PROVIDER, tokenProvider);
Expand Down
Expand Up @@ -15,10 +15,6 @@
import software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory;
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
import software.amazon.awssdk.core.signer.Signer;
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;
import software.amazon.awssdk.services.json.endpoints.internal.JsonEndpointAuthSchemeInterceptor;
import software.amazon.awssdk.services.json.endpoints.internal.JsonRequestSetEndpointInterceptor;
import software.amazon.awssdk.services.json.endpoints.internal.JsonResolveEndpointInterceptor;
import software.amazon.awssdk.utils.CollectionUtils;

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

@Override
protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) {
return config.merge(c -> c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider())
.option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false)
return config.merge(c -> c.option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false)
.option(AwsClientOption.TOKEN_PROVIDER, defaultTokenProvider())
.option(SdkAdvancedClientOption.TOKEN_SIGNER, defaultTokenSigner()));
}

@Override
protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
List<ExecutionInterceptor> endpointInterceptors = new ArrayList<>();
endpointInterceptors.add(new JsonResolveEndpointInterceptor());
endpointInterceptors.add(new JsonEndpointAuthSchemeInterceptor());
endpointInterceptors.add(new JsonRequestSetEndpointInterceptor());
ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory();
List<ExecutionInterceptor> interceptors = interceptorFactory
.getInterceptors("software/amazon/awssdk/services/json/execution.interceptors");
Expand All @@ -66,15 +58,11 @@ protected final String signingName() {
return "json-service";
}

private JsonEndpointProvider defaultEndpointProvider() {
return JsonEndpointProvider.defaultProvider();
}

private SdkTokenProvider defaultTokenProvider() {
return DefaultAwsTokenProvider.create();
}

private Signer defaultTokenSigner() {
return BearerTokenSigner.create();
}
}
}
Expand Up @@ -3,20 +3,13 @@
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;

/**
* This includes configuration specific to Json Service that is supported by both {@link JsonClientBuilder} and
* {@link JsonAsyncClientBuilder}.
*/
@Generated("software.amazon.awssdk:codegen")
public interface JsonBaseClientBuilder<B extends JsonBaseClientBuilder<B, C>, C> extends AwsClientBuilder<B, C> {
/**
* Set the {@link JsonEndpointProvider} implementation that will be used by the client to determine the endpoint for
* each request. This is optional; if none is provided a default implementation will be used the SDK.
*/
B endpointProvider(JsonEndpointProvider endpointProvider);

/**
* Set the token provider to use for bearer token authorization. This is optional, if none is provided, the SDK will
* use {@link software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider}.
Expand All @@ -29,4 +22,4 @@ public interface JsonBaseClientBuilder<B extends JsonBaseClientBuilder<B, C>, C>
* default it is {@link software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner}.
*/
B tokenProvider(SdkTokenProvider tokenProvider);
}
}
Expand Up @@ -19,10 +19,6 @@
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
import software.amazon.awssdk.core.signer.Signer;
import software.amazon.awssdk.services.json.endpoints.JsonClientContextParams;
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;
import software.amazon.awssdk.services.json.endpoints.internal.JsonEndpointAuthSchemeInterceptor;
import software.amazon.awssdk.services.json.endpoints.internal.JsonRequestSetEndpointInterceptor;
import software.amazon.awssdk.services.json.endpoints.internal.JsonResolveEndpointInterceptor;
import software.amazon.awssdk.utils.AttributeMap;
import software.amazon.awssdk.utils.CollectionUtils;
import software.amazon.awssdk.utils.Validate;
Expand All @@ -45,8 +41,7 @@ protected final String serviceName() {

@Override
protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) {
return config.merge(c -> c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider())
.option(SdkAdvancedClientOption.SIGNER, defaultSigner())
return config.merge(c -> c.option(SdkAdvancedClientOption.SIGNER, defaultSigner())
.option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false)
.option(SdkClientOption.SERVICE_CONFIGURATION, ServiceConfiguration.builder().build())
.option(AwsClientOption.TOKEN_PROVIDER, defaultTokenProvider())
Expand All @@ -56,9 +51,6 @@ protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfigurati
@Override
protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
List<ExecutionInterceptor> endpointInterceptors = new ArrayList<>();
endpointInterceptors.add(new JsonResolveEndpointInterceptor());
endpointInterceptors.add(new JsonEndpointAuthSchemeInterceptor());
endpointInterceptors.add(new JsonRequestSetEndpointInterceptor());
ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory();
List<ExecutionInterceptor> interceptors = interceptorFactory
.getInterceptors("software/amazon/awssdk/services/json/execution.interceptors");
Expand Down Expand Up @@ -137,10 +129,6 @@ protected final String signingName() {
return "json-service";
}

private JsonEndpointProvider defaultEndpointProvider() {
return JsonEndpointProvider.defaultProvider();
}

public B serviceConfiguration(ServiceConfiguration serviceConfiguration) {
clientConfiguration.option(SdkClientOption.SERVICE_CONFIGURATION, serviceConfiguration);
return thisBuilder();
Expand Down
Expand Up @@ -4,7 +4,6 @@
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;

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

/**
* Set the {@link JsonEndpointProvider} implementation that will be used by the client to determine the endpoint for
* each request. This is optional; if none is provided a default implementation will be used the SDK.
*/
B endpointProvider(JsonEndpointProvider endpointProvider);

/**
* Set the token provider to use for bearer token authorization. This is optional, if none is provided, the SDK will
* use {@link software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider}.
Expand Down
Expand Up @@ -13,10 +13,6 @@
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
import software.amazon.awssdk.core.retry.RetryMode;
import software.amazon.awssdk.core.signer.Signer;
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;
import software.amazon.awssdk.services.json.endpoints.internal.JsonEndpointAuthSchemeInterceptor;
import software.amazon.awssdk.services.json.endpoints.internal.JsonRequestSetEndpointInterceptor;
import software.amazon.awssdk.services.json.endpoints.internal.JsonResolveEndpointInterceptor;
import software.amazon.awssdk.utils.CollectionUtils;

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

@Override
protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) {
return config.merge(c -> c.option(SdkClientOption.ENDPOINT_PROVIDER, defaultEndpointProvider())
.option(SdkAdvancedClientOption.SIGNER, defaultSigner())
.option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false));
return config.merge(c -> c.option(SdkAdvancedClientOption.SIGNER, defaultSigner()).option(
SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false));
}

@Override
Expand All @@ -53,9 +48,6 @@ protected final SdkClientConfiguration mergeInternalDefaults(SdkClientConfigurat
@Override
protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
List<ExecutionInterceptor> endpointInterceptors = new ArrayList<>();
endpointInterceptors.add(new JsonResolveEndpointInterceptor());
endpointInterceptors.add(new JsonEndpointAuthSchemeInterceptor());
endpointInterceptors.add(new JsonRequestSetEndpointInterceptor());
ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory();
List<ExecutionInterceptor> interceptors = interceptorFactory
.getInterceptors("software/amazon/awssdk/services/json/execution.interceptors");
Expand All @@ -74,8 +66,4 @@ private Signer defaultSigner() {
protected final String signingName() {
return "json-service";
}

private JsonEndpointProvider defaultEndpointProvider() {
return JsonEndpointProvider.defaultProvider();
}
}