From 376bfc1f04efd4db9b29876b88dacd5561b91955 Mon Sep 17 00:00:00 2001 From: Zoe Wang <33073555+zoewangg@users.noreply.github.com> Date: Tue, 21 Oct 2025 15:50:15 -0700 Subject: [PATCH] Remove unused interceptors --- .../handlers/ConfigureSignerInterceptor.java | 36 ----- .../DisablePayloadSigningInterceptor.java | 35 ----- .../EnableChunkedEncodingInterceptor.java | 61 -------- .../LegacyMd5ExecutionInterceptor.java | 5 + .../S3OverrideAuthSchemePropertiesPlugin.java | 4 +- .../EnableChunkedEncodingInterceptorTest.java | 141 ------------------ 6 files changed, 7 insertions(+), 275 deletions(-) delete mode 100644 services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/ConfigureSignerInterceptor.java delete mode 100644 services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/DisablePayloadSigningInterceptor.java delete mode 100644 services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/EnableChunkedEncodingInterceptor.java delete mode 100644 services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/handlers/EnableChunkedEncodingInterceptorTest.java diff --git a/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/ConfigureSignerInterceptor.java b/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/ConfigureSignerInterceptor.java deleted file mode 100644 index 859fdfba9678..000000000000 --- a/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/ConfigureSignerInterceptor.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package software.amazon.awssdk.services.s3.internal.handlers; - -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute; -import software.amazon.awssdk.core.interceptor.Context; -import software.amazon.awssdk.core.interceptor.ExecutionAttributes; -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; - -/** - * Don't double-url-encode or normalize path elements for S3, as per - * https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html - */ -@SdkInternalApi -public final class ConfigureSignerInterceptor implements ExecutionInterceptor { - - @Override - public void beforeExecution(Context.BeforeExecution context, ExecutionAttributes executionAttributes) { - executionAttributes.putAttribute(AwsSignerExecutionAttribute.SIGNER_DOUBLE_URL_ENCODE, Boolean.FALSE); - executionAttributes.putAttribute(AwsSignerExecutionAttribute.SIGNER_NORMALIZE_PATH, Boolean.FALSE); - } -} diff --git a/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/DisablePayloadSigningInterceptor.java b/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/DisablePayloadSigningInterceptor.java deleted file mode 100644 index 0fab4dc487ee..000000000000 --- a/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/DisablePayloadSigningInterceptor.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package software.amazon.awssdk.services.s3.internal.handlers; - -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.S3SignerExecutionAttribute; -import software.amazon.awssdk.core.interceptor.Context; -import software.amazon.awssdk.core.interceptor.ExecutionAttributes; -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; - -/** - * Disables payload signing for all S3 operations. - * - *

TODO(sra-identity-auth): After S3's migration to the SRA, we should use signer properties in the auth scheme resolver. - */ -@SdkInternalApi -public class DisablePayloadSigningInterceptor implements ExecutionInterceptor { - @Override - public void beforeExecution(Context.BeforeExecution context, ExecutionAttributes executionAttributes) { - executionAttributes.putAttributeIfAbsent(S3SignerExecutionAttribute.ENABLE_PAYLOAD_SIGNING, false); - } -} diff --git a/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/EnableChunkedEncodingInterceptor.java b/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/EnableChunkedEncodingInterceptor.java deleted file mode 100644 index 0f33488b0043..000000000000 --- a/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/EnableChunkedEncodingInterceptor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package software.amazon.awssdk.services.s3.internal.handlers; - -import software.amazon.awssdk.annotations.SdkInternalApi; -import software.amazon.awssdk.auth.signer.S3SignerExecutionAttribute; -import software.amazon.awssdk.core.SdkRequest; -import software.amazon.awssdk.core.interceptor.Context; -import software.amazon.awssdk.core.interceptor.ExecutionAttributes; -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; -import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute; -import software.amazon.awssdk.services.s3.S3Configuration; -import software.amazon.awssdk.services.s3.model.PutObjectRequest; -import software.amazon.awssdk.services.s3.model.UploadPartRequest; - -/** - * Interceptor to enable chunked encoding on specific upload operations if the option does not already have a value. - *

- * This affects the following requests: - *

- */ -@SdkInternalApi -public final class EnableChunkedEncodingInterceptor implements ExecutionInterceptor { - - @Override - public SdkRequest modifyRequest(Context.ModifyRequest context, ExecutionAttributes executionAttributes) { - SdkRequest sdkRequest = context.request(); - - if (sdkRequest instanceof PutObjectRequest || sdkRequest instanceof UploadPartRequest) { - S3Configuration serviceConfiguration = - (S3Configuration) executionAttributes.getAttribute(SdkExecutionAttribute.SERVICE_CONFIG); - - boolean enableChunkedEncoding; - if (serviceConfiguration != null) { - enableChunkedEncoding = serviceConfiguration.chunkedEncodingEnabled(); - } else { - enableChunkedEncoding = true; - } - - executionAttributes.putAttributeIfAbsent(S3SignerExecutionAttribute.ENABLE_CHUNKED_ENCODING, enableChunkedEncoding); - } - - return sdkRequest; - } -} diff --git a/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/LegacyMd5ExecutionInterceptor.java b/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/LegacyMd5ExecutionInterceptor.java index 0a65c68a806b..c5074ad30f4f 100644 --- a/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/LegacyMd5ExecutionInterceptor.java +++ b/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/LegacyMd5ExecutionInterceptor.java @@ -31,9 +31,14 @@ import software.amazon.awssdk.core.sync.RequestBody; import software.amazon.awssdk.http.Header; import software.amazon.awssdk.http.SdkHttpRequest; +import software.amazon.awssdk.services.s3.LegacyMd5Plugin; import software.amazon.awssdk.utils.Md5Utils; import software.amazon.awssdk.utils.StringUtils; +/** + * Not directly used in the SDK; it's used in a standalone SDK plugin - {@link LegacyMd5Plugin} that enables md5 checksum + * calculation. + */ @SdkInternalApi public class LegacyMd5ExecutionInterceptor implements ExecutionInterceptor { diff --git a/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/plugins/S3OverrideAuthSchemePropertiesPlugin.java b/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/plugins/S3OverrideAuthSchemePropertiesPlugin.java index ba30132c01eb..234123124402 100644 --- a/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/plugins/S3OverrideAuthSchemePropertiesPlugin.java +++ b/services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/plugins/S3OverrideAuthSchemePropertiesPlugin.java @@ -39,7 +39,7 @@ * methods to create plugins for common cases such as enable payload signing by default. For instance, if you want * to unconditionally enable payload signing across the board you can create the S3 client, e.g., * - * {@snippet + * {@snippet : * S3AsyncClient s3 = S3AsyncClient.builder() * .region(Region.US_WEST_2) * .credentialsProvider(CREDENTIALS) @@ -50,7 +50,7 @@ * * The plugin can also be used for a particular request, e.g., * - * {@snippet + * {@snippet : * s3Client.putObject(PutObjectRequest.builder() * .overrideConfiguration(c -> c.addPlugin( * S3OverrideAuthSchemePropertiesPlugin.enablePayloadSigningPlugin())) diff --git a/services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/handlers/EnableChunkedEncodingInterceptorTest.java b/services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/handlers/EnableChunkedEncodingInterceptorTest.java deleted file mode 100644 index dc2623bdf7f7..000000000000 --- a/services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/handlers/EnableChunkedEncodingInterceptorTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package software.amazon.awssdk.services.s3.internal.handlers; - -import static org.assertj.core.api.Assertions.assertThat; -import static software.amazon.awssdk.auth.signer.S3SignerExecutionAttribute.ENABLE_CHUNKED_ENCODING; -import static software.amazon.awssdk.core.interceptor.SdkExecutionAttribute.SERVICE_CONFIG; - -import java.util.Optional; -import org.junit.jupiter.api.Test; -import software.amazon.awssdk.core.SdkRequest; -import software.amazon.awssdk.core.async.AsyncRequestBody; -import software.amazon.awssdk.core.interceptor.Context; -import software.amazon.awssdk.core.interceptor.ExecutionAttributes; -import software.amazon.awssdk.core.sync.RequestBody; -import software.amazon.awssdk.http.SdkHttpRequest; -import software.amazon.awssdk.services.s3.S3Configuration; -import software.amazon.awssdk.services.s3.model.GetObjectRequest; -import software.amazon.awssdk.services.s3.model.PutObjectRequest; -import software.amazon.awssdk.services.s3.model.UploadPartRequest; - -public class EnableChunkedEncodingInterceptorTest { - private final EnableChunkedEncodingInterceptor interceptor = new EnableChunkedEncodingInterceptor(); - - @Test - public void modifyRequest_EnablesChunckedEncoding_ForPutObectRequest() { - - ExecutionAttributes executionAttributes = new ExecutionAttributes(); - assertThat(executionAttributes.getAttribute(ENABLE_CHUNKED_ENCODING)).isNull(); - - interceptor.modifyRequest(context(PutObjectRequest.builder().build()), executionAttributes); - - assertThat(executionAttributes.getAttribute(ENABLE_CHUNKED_ENCODING)).isEqualTo(true); - } - - @Test - public void modifyRequest_EnablesChunckedEncoding_ForUploadPartRequest() { - ExecutionAttributes executionAttributes = new ExecutionAttributes(); - assertThat(executionAttributes.getAttribute(ENABLE_CHUNKED_ENCODING)).isNull(); - - interceptor.modifyRequest(context(UploadPartRequest.builder().build()), executionAttributes); - - assertThat(executionAttributes.getAttribute(ENABLE_CHUNKED_ENCODING)).isEqualTo(true); - } - - @Test - public void modifyRequest_DoesNotEnableChunckedEncoding_ForGetObjectRequest() { - - ExecutionAttributes executionAttributes = new ExecutionAttributes(); - assertThat(executionAttributes.getAttribute(ENABLE_CHUNKED_ENCODING)).isNull(); - - interceptor.modifyRequest(context(GetObjectRequest.builder().build()), executionAttributes); - - assertThat(executionAttributes.getAttribute(ENABLE_CHUNKED_ENCODING)).isNull(); - } - - @Test - public void modifyRequest_DoesNotOverwriteExistingAttributeValue() { - - ExecutionAttributes executionAttributes = new ExecutionAttributes(); - - interceptor.modifyRequest(context(PutObjectRequest.builder().build()), executionAttributes); - - boolean newValue = !executionAttributes.getAttribute(ENABLE_CHUNKED_ENCODING); - - executionAttributes.putAttribute(ENABLE_CHUNKED_ENCODING, newValue); - - interceptor.modifyRequest(context(PutObjectRequest.builder().build()), executionAttributes); - - assertThat(executionAttributes.getAttribute(ENABLE_CHUNKED_ENCODING)).isEqualTo(newValue); - } - - @Test - public void modifyRequest_valueOnServiceConfig_TakesPrecedenceOverDefaultEnabled() { - - S3Configuration config = S3Configuration.builder() - .chunkedEncodingEnabled(false) - .build(); - - ExecutionAttributes executionAttributes = new ExecutionAttributes() - .putAttribute(SERVICE_CONFIG, config); - - interceptor.modifyRequest(context(PutObjectRequest.builder().build()), executionAttributes); - - assertThat(executionAttributes.getAttribute(ENABLE_CHUNKED_ENCODING)).isEqualTo(false); - } - - @Test - public void modifyRequest_existingValueInExecutionAttributes_TakesPrecedenceOverClientConfig() { - - boolean configValue = false; - S3Configuration config = S3Configuration.builder() - .chunkedEncodingEnabled(configValue) - .build(); - - ExecutionAttributes executionAttributes = new ExecutionAttributes() - .putAttribute(SERVICE_CONFIG, config) - .putAttribute(ENABLE_CHUNKED_ENCODING, !configValue); - - interceptor.modifyRequest(context(PutObjectRequest.builder().build()), executionAttributes); - - assertThat(executionAttributes.getAttribute(ENABLE_CHUNKED_ENCODING)).isEqualTo(!configValue); - } - - private Context.ModifyHttpRequest context(SdkRequest request) { - return new Context.ModifyHttpRequest() { - @Override - public SdkHttpRequest httpRequest() { - return null; - } - - @Override - public Optional requestBody() { - return null; - } - - @Override - public Optional asyncRequestBody() { - return null; - } - - @Override - public SdkRequest request() { - return request; - } - }; - } -}