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

Enable streaming upload in S3 : put_object #658

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/utilities/request.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Base.@kwdef mutable struct Request
request_method::String

headers::AbstractDict{String,String} = LittleDict{String,String}()
content::Union{String,Vector{UInt8}} = ""
content::Union{String,Vector{UInt8},IO} = ""
resource::String = ""
url::String = ""

Expand Down Expand Up @@ -121,6 +121,12 @@ function submit_request(aws::AbstractAWSConfig, request::Request; return_headers
"EC2ThrottledException",
]

if isa(request.content, IO)
request.headers["x-amz-content-sha256"] = "UNSIGNED-PAYLOAD"
else
request.headers["Content-MD5"] = base64encode(
digest(MD_MD5, request.content))
Copy link
Member

Choose a reason for hiding this comment

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

This repository uses the Blue style guide, which puts closing parentheses on the following line in cases like this

Suggested change
digest(MD_MD5, request.content))
digest(MD_MD5, request.content)
)

Supposedly automatic formatting suggestions are set up but that appears to not have occurred here.

end
request.headers["User-Agent"] = user_agent[]
request.headers["Host"] = HTTP.URI(request.url).host
stream = @something request.response_stream IOBuffer()
Expand Down
18 changes: 8 additions & 10 deletions src/utilities/sign.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,18 @@ function sign_aws4!(aws::AbstractAWSConfig, request::Request, time::DateTime)
# Authentication scope string...
authentication_scope = join(authentication_scope, "/")

# SHA256 hash of content...
content_hash = bytes2hex(digest(MD_SHA256, request.content))
# SHA256 hash of content if data is in memory
if !haskey(request.headers, "x-amz-content-sha256")
content_hash = bytes2hex(digest(MD_SHA256, request.content))
request.headers["x-amz-content-sha256"] = content_hash
else
content_hash = "UNSIGNED-PAYLOAD"
end
Comment on lines +67 to +72
Copy link
Member

Choose a reason for hiding this comment

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

You can write this a bit more concisely like so:

Suggested change
if !haskey(request.headers, "x-amz-content-sha256")
content_hash = bytes2hex(digest(MD_SHA256, request.content))
request.headers["x-amz-content-sha256"] = content_hash
else
content_hash = "UNSIGNED-PAYLOAD"
end
content_hash = get!(request.headers, "x-amz-content-sha256") do
bytes2hex(digest(MD_SHA256, request.content))
end


# HTTP headers...
delete!(request.headers, "Authorization")

merge!(
request.headers,
Dict(
"x-amz-content-sha256" => content_hash,
"x-amz-date" => datetime,
"Content-MD5" => base64encode(digest(MD_MD5, request.content)),
),
)
merge!(request.headers, Dict("x-amz-date" => datetime))

if !isempty(creds.token)
request.headers["x-amz-security-token"] = creds.token
Expand Down
Loading