Skip to content

Commit

Permalink
Merge pull request #112 from JuliaCloud/tan/misc
Browse files Browse the repository at this point in the history
use endpoint URL from env if set, for S3
  • Loading branch information
tanmaykm authored Feb 22, 2018
2 parents 4ca3279 + 26a0f42 commit bcd126f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/S3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ function restore_object(env::AWSEnv, bkt::String, key::String, days::Int)
ro.cont_typ = "application/octet-stream"

ro.sub_res=[("restore", "")]
ro.body = "<RestoreRequest xmlns=\"http://$(amz_s3_endpoint(env.region))/doc/2006-3-01\"><Days>$(days)</Days></RestoreRequest>"
ro.body = "<RestoreRequest xmlns=\"http://$(amz_s3_endpoint(env))/doc/2006-3-01\"><Days>$(days)</Days></RestoreRequest>"

s3_resp = do_request(env, ro)
s3_resp
Expand Down Expand Up @@ -725,7 +725,7 @@ function do_http(env::AWSEnv, ro::RO)

push!(all_hdrs, ("Authorization", "AWS " * env.aws_id * ":" * s_b64))

url = "https://$(amz_s3_endpoint(env.region))" * full_path
url = "https://$(amz_s3_endpoint(env))" * full_path

http_options = RequestOptions(headers=all_hdrs, ostream=ro.ostream, request_timeout=env.timeout, auto_content_type=false)

Expand Down Expand Up @@ -906,7 +906,8 @@ function get_canon_amz_headers(headers::Vector{Tuple})
return sorted, canon_hdr_str
end

amz_s3_endpoint(region) = ((isempty(region) || (region == "us-east-1")) ? "s3" : ("s3-"*region)) * ".amazonaws.com"
amz_s3_endpoint(region::String) = ((isempty(region) || (region == "us-east-1")) ? "s3" : ("s3-"*region)) * ".amazonaws.com"
amz_s3_endpoint(env::AWSEnv) = isempty(env.ep_host) ? amz_s3_endpoint(env.region) : env.ep_host

rfc1123_date() = rfc1123_date(now(Dates.UTC))
function rfc1123_date(dt)
Expand Down
13 changes: 13 additions & 0 deletions test/tests3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,21 @@ function test_bucket_ops(env)
check_resp(resp, String)
end

function test_endpoint(env)
info("custom s3 endpoint")
env2 = AWSEnv(env, ep="http://localhost/")
try
S3.list_all_buckets(env2)
error("expected connect failure")
catch ex
@test isa(ex, Base.UVError)
@test ex.prefix == "connect"
end
end

function runtests(env, config)
info("testing s3 bucket ops...")
test_endpoint(env)
test_bucket_ops(env)
end

Expand Down

0 comments on commit bcd126f

Please sign in to comment.