aws / aws-sdk-cpp

AWS SDK for C++
Apache License 2.0
1.96k stars 1.05k forks source link

fix noisy log when MD5 checksum is specified #3060

Closed sbiscigl closed 2 months ago

sbiscigl commented 2 months ago

Description of changes:

Fixes a problem where the following code would emit the log

Checksum algorithm: md5is not supported by SDK.

even though the checksum was set and is supported. The log is incorrect and should not be logged in this case as MD5 was set and not calculated.

#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/core/utils/HashingUtils.h>
#include <aws/s3/model/PutObjectRequest.h>

using namespace Aws;
using namespace Aws::S3;
using namespace Aws::S3::Model;
using namespace Aws::Utils;

const char * ALLOCATION_TAG = "test";

int main()
{
    SDKOptions options;
    options.loggingOptions.logLevel = Utils::Logging::LogLevel::Info;
    InitAPI(options);
    {
        S3Client client{};
        auto request = PutObjectRequest().WithBucket("bucket_name").WithKey("key");
        const String body{"a test string"};
        std::shared_ptr<Aws::IOStream> inputData = Aws::MakeShared<Aws::StringStream>(ALLOCATION_TAG,
          body,
          std::ios_base::in | std::ios_base::binary);
        request.SetBody(inputData);
        request.SetContentMD5(HashingUtils::Base64Encode(HashingUtils::CalculateMD5(body)));
        assert(client.PutObject(request).IsSuccess());
    }
    ShutdownAPI(options);
    return 0;
}

Check all that applies:

Check which platforms you have built SDK on to verify the correctness of this PR.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.