-
-
Notifications
You must be signed in to change notification settings - Fork 906
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
Added x-amz-checksum-sha256 header for Object Lock support #1393
Open
AlexisPPLIN
wants to merge
2
commits into
s3tools:master
Choose a base branch
from
AlexisPPLIN:obj_lock_put_fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ | |
from .ConnMan import ConnMan | ||
from .Crypto import (sign_request_v2, sign_request_v4, checksum_sha256_file, | ||
checksum_sha256_buffer, generate_content_md5, | ||
hash_file_md5, calculateChecksum, format_param_str) | ||
hash_file_md5, calculateChecksum, format_param_str, sha256_hash_to_base64) | ||
|
||
try: | ||
from ctypes import ArgumentError | ||
|
@@ -1848,6 +1848,11 @@ def send_file(self, request, stream, labels, buffer = '', throttle = 0, | |
sha256_hash = checksum_sha256_file(stream, offset, size_total) | ||
request.body = sha256_hash | ||
|
||
# Provide the checksum with the request. This is important for buckets that have | ||
# Object Lock enabled. | ||
|
||
headers['x-amz-checksum-sha256'] = sha256_hash_to_base64(sha256_hash) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As someone could use s3cmd as library this line can override the header potentially comes with request argument's headers attribute. I think it's better to check if it currently has values: if not headers.get("x-amz-checksum-sha256"):
headers['x-amz-checksum-sha256'] = sha256_hash_to_base64(sha256_hash) |
||
|
||
if use_expect_continue: | ||
if not size_total: | ||
use_expect_continue = False | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this module encodestring (which imported above as an alias of encodebytes when available) is the function used for base64 encoding.
I think you can use:
to align with other usecases.