From 76d1a4e902b8f75c184f0f02047f3ae7bcd78bec Mon Sep 17 00:00:00 2001 From: sbiscigl Date: Fri, 9 Aug 2024 16:07:09 -0400 Subject: [PATCH] fix bug where we did not pass crt flex checksum configuration --- .../include/aws/s3-crt/S3CrtClient.h | 1 + .../aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp | 46 +++++++++++++++++++ .../S3ExpressTest.cpp | 19 ++++++++ .../velocity/cpp/s3/S3ClientHeader.vm | 1 + .../cpp/s3/s3-crt/S3CrtSpecificOperations.vm | 25 ++++++++++ tools/scripts/run_integration_tests.py | 2 +- 6 files changed, 93 insertions(+), 1 deletion(-) diff --git a/generated/src/aws-cpp-sdk-s3-crt/include/aws/s3-crt/S3CrtClient.h b/generated/src/aws-cpp-sdk-s3-crt/include/aws/s3-crt/S3CrtClient.h index d2bfdbcb2be..2fd128f6a67 100644 --- a/generated/src/aws-cpp-sdk-s3-crt/include/aws/s3-crt/S3CrtClient.h +++ b/generated/src/aws-cpp-sdk-s3-crt/include/aws/s3-crt/S3CrtClient.h @@ -6275,6 +6275,7 @@ namespace Aws std::shared_ptr request; std::shared_ptr response; std::shared_ptr crtHttpRequest; + std::shared_ptr checksumConfig; }; Aws::Client::XmlOutcome GenerateXmlOutcome(const std::shared_ptr& response) const; diff --git a/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp b/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp index 92d56469c70..a0dd0c86681 100644 --- a/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp +++ b/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp @@ -788,6 +788,29 @@ void S3CrtClient::CopyObjectAsync(const CopyObjectRequest& request, const CopyOb } options.signing_config = &signing_config_override; + if (request.ChecksumAlgorithmHasBeenSet()) + { + static std::pair crtChecksumMapping[]{ + {ChecksumAlgorithm::CRC32, aws_s3_checksum_algorithm::AWS_SCA_CRC32}, + {ChecksumAlgorithm::CRC32C, aws_s3_checksum_algorithm::AWS_SCA_CRC32C}, + {ChecksumAlgorithm::SHA1, aws_s3_checksum_algorithm::AWS_SCA_SHA1}, + {ChecksumAlgorithm::SHA256, aws_s3_checksum_algorithm::AWS_SCA_SHA256}, + }; + + const auto checksumAlgorithm = request.GetChecksumAlgorithm(); + const auto mapping = std::find_if(std::begin(crtChecksumMapping), + std::end(crtChecksumMapping), + [&checksumAlgorithm](const std::pair& mapping){ return mapping.first == checksumAlgorithm; }); + if (mapping != std::end(crtChecksumMapping)) + { + std::shared_ptr checksum_config{Aws::New(ALLOCATION_TAG)}; + userData->checksumConfig = checksum_config; + checksum_config->checksum_algorithm = mapping->second; + checksum_config->location = AWS_SCL_TRAILER; + options.checksum_config = checksum_config.get(); + } + } + std::shared_ptr crtHttpRequest = userData->request->ToCrtHttpRequest(); options.message= crtHttpRequest->GetUnderlyingMessage(); userData->crtHttpRequest = crtHttpRequest; @@ -1030,6 +1053,29 @@ void S3CrtClient::PutObjectAsync(const PutObjectRequest& request, const PutObjec } options.signing_config = &signing_config_override; + if (request.ChecksumAlgorithmHasBeenSet()) + { + static std::pair crtChecksumMapping[]{ + {ChecksumAlgorithm::CRC32, aws_s3_checksum_algorithm::AWS_SCA_CRC32}, + {ChecksumAlgorithm::CRC32C, aws_s3_checksum_algorithm::AWS_SCA_CRC32C}, + {ChecksumAlgorithm::SHA1, aws_s3_checksum_algorithm::AWS_SCA_SHA1}, + {ChecksumAlgorithm::SHA256, aws_s3_checksum_algorithm::AWS_SCA_SHA256}, + }; + + const auto checksumAlgorithm = request.GetChecksumAlgorithm(); + const auto mapping = std::find_if(std::begin(crtChecksumMapping), + std::end(crtChecksumMapping), + [&checksumAlgorithm](const std::pair& mapping){ return mapping.first == checksumAlgorithm; }); + if (mapping != std::end(crtChecksumMapping)) + { + std::shared_ptr checksum_config{Aws::New(ALLOCATION_TAG)}; + userData->checksumConfig = checksum_config; + checksum_config->checksum_algorithm = mapping->second; + checksum_config->location = AWS_SCL_TRAILER; + options.checksum_config = checksum_config.get(); + } + } + std::shared_ptr crtHttpRequest = userData->request->ToCrtHttpRequest(); options.message= crtHttpRequest->GetUnderlyingMessage(); userData->crtHttpRequest = crtHttpRequest; diff --git a/tests/aws-cpp-sdk-s3-crt-integration-tests/S3ExpressTest.cpp b/tests/aws-cpp-sdk-s3-crt-integration-tests/S3ExpressTest.cpp index fb0d8ed07a6..9f846b9c4ce 100644 --- a/tests/aws-cpp-sdk-s3-crt-integration-tests/S3ExpressTest.cpp +++ b/tests/aws-cpp-sdk-s3-crt-integration-tests/S3ExpressTest.cpp @@ -479,6 +479,25 @@ namespace { } } + TEST_F(S3ExpressTest, PutObjectChecksumWithoutAlgorithmValue) { + const auto bucketName = Testing::GetAwsResourcePrefix() + randomString() + S3_EXPRESS_SUFFIX; + const auto createOutcome = CreateBucket(bucketName); + AWS_EXPECT_SUCCESS(createOutcome); + + auto request = PutObjectRequest() + .WithBucket(bucketName) + .WithKey("swingingparty") + .WithChecksumAlgorithm(ChecksumAlgorithm::CRC32); + + std::shared_ptr body = Aws::MakeShared(ALLOCATION_TAG, + "Bring your own lampshade, somewhere there's a party.", + std::ios_base::in | std::ios_base::binary); + request.SetBody(body); + + const auto response = client->PutObject(request); + AWS_EXPECT_SUCCESS(response); + } + TEST_F(S3ExpressTest, PutObjectChecksumWithoutAlgorithm) { const auto bucketName = Testing::GetAwsResourcePrefix() + randomString() + S3_EXPRESS_SUFFIX; const auto createOutcome = CreateBucket(bucketName); diff --git a/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/S3ClientHeader.vm b/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/S3ClientHeader.vm index 0f0c6a95e71..80367d023d7 100644 --- a/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/S3ClientHeader.vm +++ b/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/S3ClientHeader.vm @@ -205,6 +205,7 @@ namespace ${rootNamespace} std::shared_ptr request; std::shared_ptr response; std::shared_ptr crtHttpRequest; + std::shared_ptr checksumConfig; }; Aws::Client::XmlOutcome GenerateXmlOutcome(const std::shared_ptr& response) const; diff --git a/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/s3-crt/S3CrtSpecificOperations.vm b/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/s3-crt/S3CrtSpecificOperations.vm index acea83d8f2c..92baea9da5e 100644 --- a/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/s3-crt/S3CrtSpecificOperations.vm +++ b/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/s3-crt/S3CrtSpecificOperations.vm @@ -354,6 +354,31 @@ void ${className}::${operation.name}Async(${constText}${operation.request.shape. signing_config_override.service = Aws::Crt::ByteCursorFromCString(computeEndpointOutcome.GetResult().signerServiceName.c_str()); #end options.signing_config = &signing_config_override; +#if($operation.name == "PutObject" || $operation.name == "CopyObject") + + if (request.ChecksumAlgorithmHasBeenSet()) + { + static std::pair crtChecksumMapping[]{ + {ChecksumAlgorithm::CRC32, aws_s3_checksum_algorithm::AWS_SCA_CRC32}, + {ChecksumAlgorithm::CRC32C, aws_s3_checksum_algorithm::AWS_SCA_CRC32C}, + {ChecksumAlgorithm::SHA1, aws_s3_checksum_algorithm::AWS_SCA_SHA1}, + {ChecksumAlgorithm::SHA256, aws_s3_checksum_algorithm::AWS_SCA_SHA256}, + }; + + const auto checksumAlgorithm = request.GetChecksumAlgorithm(); + const auto mapping = std::find_if(std::begin(crtChecksumMapping), + std::end(crtChecksumMapping), + [&checksumAlgorithm](const std::pair& mapping){ return mapping.first == checksumAlgorithm; }); + if (mapping != std::end(crtChecksumMapping)) + { + std::shared_ptr checksum_config{Aws::New(ALLOCATION_TAG)}; + userData->checksumConfig = checksum_config; + checksum_config->checksum_algorithm = mapping->second; + checksum_config->location = AWS_SCL_TRAILER; + options.checksum_config = checksum_config.get(); + } + } + #end std::shared_ptr crtHttpRequest = userData->request->ToCrtHttpRequest(); options.message= crtHttpRequest->GetUnderlyingMessage(); diff --git a/tools/scripts/run_integration_tests.py b/tools/scripts/run_integration_tests.py index cd7dbed9fda..f9df5418170 100644 --- a/tools/scripts/run_integration_tests.py +++ b/tools/scripts/run_integration_tests.py @@ -41,7 +41,7 @@ def main(): "aws-cpp-sdk-sqs-integration-tests", "aws-cpp-sdk-s3-integration-tests", "aws-cpp-sdk-s3-unit-tests", - #"aws-cpp-sdk-s3-crt-integration-tests", + "aws-cpp-sdk-s3-crt-integration-tests", #"aws-cpp-sdk-s3control-integration-tests", # "aws-cpp-sdk-lambda-integration-tests", "aws-cpp-sdk-cognitoidentity-integration-tests",