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

Fix issue 30, fully support OSS VPC endpoint #49

Open
wants to merge 1 commit 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
6 changes: 4 additions & 2 deletions lib/fog/aliyun/requests/storage/copy_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions lib/fog/aliyun/requests/storage/delete_bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions lib/fog/aliyun/requests/storage/delete_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions lib/fog/aliyun/requests/storage/delete_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
33 changes: 19 additions & 14 deletions lib/fog/aliyun/requests/storage/get_bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/requests/storage/get_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/requests/storage/get_containers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
3 changes: 1 addition & 2 deletions lib/fog/aliyun/requests/storage/get_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 4 additions & 0 deletions lib/fog/aliyun/requests/storage/get_object_http_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/fog/aliyun/requests/storage/get_object_https_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/fog/aliyun/requests/storage/head_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
6 changes: 2 additions & 4 deletions lib/fog/aliyun/requests/storage/list_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/fog/aliyun/requests/storage/put_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '/'
Expand Down
27 changes: 13 additions & 14 deletions lib/fog/aliyun/requests/storage/put_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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 + '/'
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 = []
Expand Down