From 26a0f425027463b6424b9da219bb17e7a44a3d67 Mon Sep 17 00:00:00 2001 From: tan Date: Thu, 22 Feb 2018 16:37:29 +0530 Subject: [PATCH] use endpoint URL from env if set, for S3 fixes #111 --- src/S3.jl | 7 ++++--- test/tests3.jl | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/S3.jl b/src/S3.jl index 798e08c4b9..6575e79ae6 100644 --- a/src/S3.jl +++ b/src/S3.jl @@ -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 = "$(days)" + ro.body = "$(days)" s3_resp = do_request(env, ro) s3_resp @@ -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) @@ -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) diff --git a/test/tests3.jl b/test/tests3.jl index 54bfd326ab..4ef759ac36 100644 --- a/test/tests3.jl +++ b/test/tests3.jl @@ -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