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

enhancement: flexible checksums #2999

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

stobrien89
Copy link
Member

Description of changes:
Adds default checksum calculation, deprecates the AddContentMD5 config option as S3 plans to deprecate MD5 checksums soon, adds two S3 client config options: request_checksum_calculation and response_checksum_validation with acceptable values for both being either when_supported or when_required.

request_checksum_calculation will default to when_supported, which means if an operation supports checksum calculation (indicated via modeling), the SDK will calculate the checksum and add the appropriate header. If it is set to when_required, the SDK will only compute and send a checksum when the operation requires an httpRequestChecksum.

response_checksum_validation also defaults to when_supported, which means if an operation models response algorithms, an attempt to validate a response checksum will be made. when_required will only validate response checksums when response checksum are modeled AND ChecksumMode is set to enabled on the command.

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

src/S3/ApplyChecksumMiddleware.php Show resolved Hide resolved
src/S3/ApplyChecksumMiddleware.php Outdated Show resolved Hide resolved
src/S3/ApplyChecksumMiddleware.php Outdated Show resolved Hide resolved
.changes/nextrelease/checksumsv2.json Outdated Show resolved Hide resolved
src/S3/ApplyChecksumMiddleware.php Show resolved Hide resolved
src/S3/S3Client.php Outdated Show resolved Hide resolved
src/S3/S3Client.php Show resolved Hide resolved
src/S3/S3Client.php Show resolved Hide resolved
src/S3/S3Client.php Outdated Show resolved Hide resolved
src/Signature/S3SignatureV4.php Show resolved Hide resolved
src/S3/CalculatesChecksumTrait.php Outdated Show resolved Hide resolved
src/S3/CalculatesChecksumTrait.php Outdated Show resolved Hide resolved
src/S3/MultipartUploadingTrait.php Outdated Show resolved Hide resolved
src/S3/S3Client.php Outdated Show resolved Hide resolved
@stobrien89 stobrien89 force-pushed the checksums-v2 branch 2 times, most recently from a507de5 to dce99fd Compare October 10, 2024 23:14
Copy link
Contributor

@yenfryherrerafeliz yenfryherrerafeliz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Just some minor changes. I also did not see a test for when generating a presigned url with PUT operations and the checksum here should be omitted?

src/S3/ApplyChecksumMiddleware.php Outdated Show resolved Hide resolved
Copy link
Contributor

@yenfryherrerafeliz yenfryherrerafeliz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great. Just two minor suggestion that are not required to address.

Comment on lines +99 to +101
$supportedAlgorithms = isset($checksumMember['enum'])
? array_map('strtolower', $checksumMember['enum'])
: [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this could be simplified to:

$supportedAlgorithms =  array_map('strtolower', $checksumMember['enum'] ?? []);

Comment on lines +54 to +57
throw new InvalidArgumentException(
"Invalid checksum requested: {$requestedAlgorithm}."
. " Valid algorithms are {$validAlgorithms}."
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another place that validates if the checksum is valid or not. For example here. I know one validates if is valid based on what the operation supports and the other one validates if is supported by the SDK in specific. Would not be worth to make that more clear here?, like state why it is not supported.
For example:

  throw new InvalidArgumentException(
      "Invalid checksum requested: {$requestedAlgorithm}."
      . "  Valid algorithms supported by this runtime are {$validAlgorithms}."
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants