diff --git a/lib/fog/aliyun/requests/storage/copy_object.rb b/lib/fog/aliyun/requests/storage/copy_object.rb index dc4d1ef..a7d273c 100644 --- a/lib/fog/aliyun/requests/storage/copy_object.rb +++ b/lib/fog/aliyun/requests/storage/copy_object.rb @@ -19,8 +19,10 @@ def copy_object(source_bucket, source_object, target_bucket, target_object, opti source_bucket ||= bucket target_bucket ||= bucket headers = { 'x-oss-copy-source' => "/#{source_bucket}/#{source_object}" } - location = get_bucket_location(target_bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = options[:endpoint] + if endpoint.nil? + endpoint = get_bucket_endpoint(bucket) + end resource = target_bucket + '/' + target_object request(expects: [200, 203], headers: headers, diff --git a/lib/fog/aliyun/requests/storage/delete_bucket.rb b/lib/fog/aliyun/requests/storage/delete_bucket.rb index ea932dc..9fe4083 100644 --- a/lib/fog/aliyun/requests/storage/delete_bucket.rb +++ b/lib/fog/aliyun/requests/storage/delete_bucket.rb @@ -10,8 +10,7 @@ class Real # * bucket<~String> - Name of bucket to delete # def delete_bucket(bucket) - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) resource = bucket + '/' request( expects: 204, diff --git a/lib/fog/aliyun/requests/storage/delete_container.rb b/lib/fog/aliyun/requests/storage/delete_container.rb index ebf8653..20d18df 100644 --- a/lib/fog/aliyun/requests/storage/delete_container.rb +++ b/lib/fog/aliyun/requests/storage/delete_container.rb @@ -13,8 +13,10 @@ class Real def delete_container(container, options = {}) bucket = options[:bucket] bucket ||= @aliyun_oss_bucket - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = options[:endpoint] + if endpoint.nil? + endpoint = get_bucket_endpoint(bucket) + end object = container + '/' resource = bucket + '/' + object diff --git a/lib/fog/aliyun/requests/storage/delete_object.rb b/lib/fog/aliyun/requests/storage/delete_object.rb index 1697521..6f2017c 100644 --- a/lib/fog/aliyun/requests/storage/delete_object.rb +++ b/lib/fog/aliyun/requests/storage/delete_object.rb @@ -12,8 +12,10 @@ class Real def delete_object(object, options = {}) bucket = options[:bucket] bucket ||= @aliyun_oss_bucket - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = options[:endpoint] + if endpoint.nil? + endpoint = get_bucket_endpoint(bucket) + end resource = bucket + '/' + object request( expects: 204, @@ -27,8 +29,7 @@ def delete_object(object, options = {}) def abort_multipart_upload(bucket, object, endpoint, uploadid) if endpoint.nil? - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) end path = object + '?uploadId=' + uploadid resource = bucket + '/' + path diff --git a/lib/fog/aliyun/requests/storage/get_bucket.rb b/lib/fog/aliyun/requests/storage/get_bucket.rb index b8ef0b3..33c3e88 100644 --- a/lib/fog/aliyun/requests/storage/get_bucket.rb +++ b/lib/fog/aliyun/requests/storage/get_bucket.rb @@ -5,8 +5,7 @@ module Storage class Aliyun class Real def get_bucket(bucket) - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) resource = bucket + '/' ret = request( expects: [200, 203], @@ -19,6 +18,18 @@ def get_bucket(bucket) XmlSimple.xml_in(xml) end + def get_bucket_endpoint(bucket) + location = get_bucket_location(bucket) + # If the endpoint specified contains with -internal, then assume it is a vpc endpoint, + # hence, the bucket endpoint returned is also internal one... + # Otherwise, continue to use the public endpoint as previous edition. + if @aliyun_oss_endpoint.downcase()['-internal'] + endpoint = 'http://' + location + '-internal'+'.aliyuncs.com' + else + endpoint = 'http://' + location +'.aliyuncs.com' + end + end + def get_bucket_location(bucket) attribute = '?location' resource = bucket + '/' + attribute @@ -33,8 +44,7 @@ def get_bucket_location(bucket) end def get_bucket_acl(bucket) - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) attribute = '?acl' resource = bucket + '/' + attribute ret = request( @@ -49,8 +59,7 @@ def get_bucket_acl(bucket) end def get_bucket_CORSRules(bucket) - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) attribute = '?cors' resource = bucket + '/' + attribute ret = request( @@ -65,8 +74,7 @@ def get_bucket_CORSRules(bucket) end def get_bucket_lifecycle(bucket) - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) attribute = '?lifecycle' resource = bucket + '/' + attribute ret = request( @@ -81,8 +89,7 @@ def get_bucket_lifecycle(bucket) end def get_bucket_logging(bucket) - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) attribute = '?logging' resource = bucket + '/' + attribute ret = request( @@ -97,8 +104,7 @@ def get_bucket_logging(bucket) end def get_bucket_referer(bucket) - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) attribute = '?referer' resource = bucket + '/' + attribute ret = request( @@ -113,8 +119,7 @@ def get_bucket_referer(bucket) end def get_bucket_website(bucket) - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) attribute = '?website' resource = bucket + '/' + attribute ret = request( diff --git a/lib/fog/aliyun/requests/storage/get_container.rb b/lib/fog/aliyun/requests/storage/get_container.rb index 179c7af..21729cd 100644 --- a/lib/fog/aliyun/requests/storage/get_container.rb +++ b/lib/fog/aliyun/requests/storage/get_container.rb @@ -38,7 +38,7 @@ def get_container(container, options = {}) path += '?delimiter=' + delimiter end - location = get_bucket_location(bucket) + # location = get_bucket_location(bucket) resource = bucket + '/' ret = request( expects: [200, 203, 400], diff --git a/lib/fog/aliyun/requests/storage/get_containers.rb b/lib/fog/aliyun/requests/storage/get_containers.rb index 58ee265..8e0c3b0 100644 --- a/lib/fog/aliyun/requests/storage/get_containers.rb +++ b/lib/fog/aliyun/requests/storage/get_containers.rb @@ -42,7 +42,7 @@ def get_containers(options = {}) path += '?delimiter=' + delimiter end - location = get_bucket_location(bucket) + # location = get_bucket_location(bucket) resource = bucket + '/' ret = request( expects: [200, 203, 400], diff --git a/lib/fog/aliyun/requests/storage/get_object.rb b/lib/fog/aliyun/requests/storage/get_object.rb index a9ea95a..3c03b4a 100644 --- a/lib/fog/aliyun/requests/storage/get_object.rb +++ b/lib/fog/aliyun/requests/storage/get_object.rb @@ -15,8 +15,7 @@ def get_object(object, range = nil, options = {}) bucket ||= @aliyun_oss_bucket endpoint = options[:endpoint] if endpoint.nil? - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) end resource = bucket + '/' + object para = { diff --git a/lib/fog/aliyun/requests/storage/get_object_http_url.rb b/lib/fog/aliyun/requests/storage/get_object_http_url.rb index 9b12e3d..5a01336 100644 --- a/lib/fog/aliyun/requests/storage/get_object_http_url.rb +++ b/lib/fog/aliyun/requests/storage/get_object_http_url.rb @@ -21,6 +21,10 @@ def get_object_http_url_public(object, expires, options = {}) acl = get_bucket_acl(bucket) location = get_bucket_location(bucket) + if @aliyun_oss_endpoint.downcase()['-internal'] + location = location + '-internal' + end + if acl == 'private' expires_time = (Time.now.to_i + (expires.nil? ? 0 : expires.to_i)).to_s resource = bucket + '/' + object diff --git a/lib/fog/aliyun/requests/storage/get_object_https_url.rb b/lib/fog/aliyun/requests/storage/get_object_https_url.rb index d7a2fb8..e2bad0f 100644 --- a/lib/fog/aliyun/requests/storage/get_object_https_url.rb +++ b/lib/fog/aliyun/requests/storage/get_object_https_url.rb @@ -21,6 +21,10 @@ def get_object_https_url_public(object, expires, options = {}) acl = get_bucket_acl(bucket) location = get_bucket_location(bucket) + if @aliyun_oss_endpoint.downcase()['-internal'] + location = location + '-internal' + end + if acl == 'private' expires_time = (Time.now.to_i + (expires.nil? ? 0 : expires.to_i)).to_s resource = bucket + '/' + object diff --git a/lib/fog/aliyun/requests/storage/head_object.rb b/lib/fog/aliyun/requests/storage/head_object.rb index e154ae2..bc1381a 100644 --- a/lib/fog/aliyun/requests/storage/head_object.rb +++ b/lib/fog/aliyun/requests/storage/head_object.rb @@ -12,8 +12,10 @@ class Real def head_object(object, options = {}) bucket = options[:bucket] bucket ||= @aliyun_oss_bucket - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = options[:endpoint] + if endpoint.nil? + endpoint = get_bucket_endpoint(bucket) + end resource = bucket + '/' + object ret = request( expects: [200, 404], diff --git a/lib/fog/aliyun/requests/storage/list_objects.rb b/lib/fog/aliyun/requests/storage/list_objects.rb index 2da7eba..b266b54 100644 --- a/lib/fog/aliyun/requests/storage/list_objects.rb +++ b/lib/fog/aliyun/requests/storage/list_objects.rb @@ -45,8 +45,7 @@ def list_objects(options = {}) def list_multipart_uploads(bucket, endpoint, _options = {}) if endpoint.nil? - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) end path = '?uploads' resource = bucket + '/' + path @@ -64,8 +63,7 @@ def list_multipart_uploads(bucket, endpoint, _options = {}) def list_parts(bucket, object, endpoint, uploadid, _options = {}) if endpoint.nil? - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) end path = object + '?uploadId=' + uploadid resource = bucket + '/' + path diff --git a/lib/fog/aliyun/requests/storage/put_container.rb b/lib/fog/aliyun/requests/storage/put_container.rb index 9a61704..4208474 100644 --- a/lib/fog/aliyun/requests/storage/put_container.rb +++ b/lib/fog/aliyun/requests/storage/put_container.rb @@ -12,8 +12,10 @@ class Real def put_container(name, options = {}) bucket = options[:bucket] bucket ||= @aliyun_oss_bucket - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = options[:endpoint] + if endpoint.nil? + endpoint = get_bucket_endpoint(bucket) + end path = name + '/' resource = bucket + '/' + name + '/' diff --git a/lib/fog/aliyun/requests/storage/put_object.rb b/lib/fog/aliyun/requests/storage/put_object.rb index 64b5b15..83388cc 100644 --- a/lib/fog/aliyun/requests/storage/put_object.rb +++ b/lib/fog/aliyun/requests/storage/put_object.rb @@ -12,8 +12,10 @@ class Real def put_object(object, file = nil, options = {}) bucket = options[:bucket] bucket ||= @aliyun_oss_bucket - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = options[:endpoint] + if endpoint.nil? + endpoint = get_bucket_endpoint(bucket) + end return put_folder(bucket, object, endpoint) if file.nil? # put multiparts if object's size is over 100m @@ -36,8 +38,10 @@ def put_object(object, file = nil, options = {}) def put_object_with_body(object, body, options = {}) bucket = options[:bucket] bucket ||= @aliyun_oss_bucket - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = options[:endpoint] + if endpoint.nil? + endpoint = get_bucket_endpoint(bucket) + end resource = bucket + '/' + object request( @@ -53,8 +57,7 @@ def put_object_with_body(object, body, options = {}) def put_folder(bucket, folder, endpoint) if endpoint.nil? - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) end path = folder + '/' resource = bucket + '/' + folder + '/' @@ -69,8 +72,7 @@ def put_folder(bucket, folder, endpoint) end def put_multipart_object(bucket, object, file) - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) # find the right uploadid uploads = list_multipart_uploads(bucket, endpoint) @@ -113,8 +115,7 @@ def put_multipart_object(bucket, object, file) def initiate_multipart_upload(bucket, object, endpoint) if endpoint.nil? - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) end path = object + '?uploads' resource = bucket + '/' + path @@ -131,8 +132,7 @@ def initiate_multipart_upload(bucket, object, endpoint) def upload_part(bucket, object, endpoint, partNumber, uploadId, body) if endpoint.nil? - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) end path = object + '?partNumber=' + partNumber + '&uploadId=' + uploadId resource = bucket + '/' + path @@ -149,8 +149,7 @@ def upload_part(bucket, object, endpoint, partNumber, uploadId, body) def complete_multipart_upload(bucket, object, endpoint, uploadId) if endpoint.nil? - location = get_bucket_location(bucket) - endpoint = 'http://' + location + '.aliyuncs.com' + endpoint = get_bucket_endpoint(bucket) end parts = list_parts(bucket, object, endpoint, uploadId, options = {}) request_part = []