Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.1
3.0.4
3 changes: 2 additions & 1 deletion fog-aliyun.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'mime-types', '~> 2.6', '>= 2.6.2'
spec.add_development_dependency 'mime-types', '~> 3.4'
spec.add_development_dependency 'pry-nav'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec'
Expand All @@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'memory_profiler'
spec.add_development_dependency 'aliyun-sdk', '~> 0.8.0'

spec.add_dependency 'addressable', '~> 2.8.0'
spec.add_dependency 'aliyun-sdk', '~> 0.8.0'
spec.add_dependency 'fog-core'
spec.add_dependency 'fog-json'
Expand Down
12 changes: 7 additions & 5 deletions lib/fog/aliyun/compute.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun < Fog::Service
Expand Down Expand Up @@ -350,7 +352,7 @@ def VPCrequest(params)
# operation compute-- default URL
def defaultAliyunUri(action, sigNonce, time)
parTimeFormat = time.strftime('%Y-%m-%dT%H:%M:%SZ')
urlTimeFormat = URI.encode(parTimeFormat, ':')
urlTimeFormat = Addressable::URI.encode_component(parTimeFormat, Addressable::URI::CharacterClasses::UNRESERVED + '|')
'?Format=JSON&AccessKeyId=' + @aliyun_accesskey_id + '&Action=' + action + '&SignatureMethod=HMAC-SHA1&RegionId=' + @aliyun_region_id + '&SignatureNonce=' + sigNonce + '&SignatureVersion=1.0&Version=2014-05-26&Timestamp=' + urlTimeFormat
end

Expand All @@ -370,7 +372,7 @@ def defaultAliyunQueryParameters(action, sigNonce, time)

def defaultAliyunVPCUri(action, sigNonce, time)
parTimeFormat = time.strftime('%Y-%m-%dT%H:%M:%SZ')
urlTimeFormat = URI.encode(parTimeFormat, ':')
urlTimeFormat = Addressable::URI.encode_component(parTimeFormat, Addressable::URI::CharacterClasses::UNRESERVED + '|')
'?Format=JSON&AccessKeyId=' + @aliyun_accesskey_id + '&Action=' + action + '&SignatureMethod=HMAC-SHA1&RegionId=' + @aliyun_region_id + '&SignatureNonce=' + sigNonce + '&SignatureVersion=1.0&Version=2016-04-28&Timestamp=' + urlTimeFormat
end

Expand Down Expand Up @@ -420,18 +422,18 @@ def defalutVPCParameters(action, sigNonce, time)
# building querystrings with string concatination.
def sign(accessKeySecret, parameters)
signature = sign_without_encoding(accessKeySecret, parameters)
URI.encode(signature, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
Addressable::URI.encode_component(signature, Addressable::URI::CharacterClasses::UNRESERVED + '|')
end

def sign_without_encoding(accessKeySecret, parameters)
sortedParameters = parameters.sort
canonicalizedQueryString = ''
sortedParameters.each do |k, v|
canonicalizedQueryString += '&' + URI.encode(k, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ') + '=' + URI.encode(v, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
canonicalizedQueryString += '&' + Addressable::URI.encode_component(k, Addressable::URI::CharacterClasses::UNRESERVED + '|') + '=' + Addressable::URI.encode_component(v, Addressable::URI::CharacterClasses::UNRESERVED + '|')
end

canonicalizedQueryString[0] = ''
stringToSign = 'GET&%2F&' + URI.encode(canonicalizedQueryString, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
stringToSign = 'GET&%2F&' + Addressable::URI.encode_component(canonicalizedQueryString, Addressable::URI::CharacterClasses::UNRESERVED + '|')
key = accessKeySecret + '&'

digVer = OpenSSL::Digest.new('sha1')
Expand Down
18 changes: 8 additions & 10 deletions lib/fog/aliyun/models/storage/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ def get(key, options = {}, &block)
})
new(file_data)
rescue Exception => error
case error.http_code.to_i
when 404
nil
else
raise(error)
if error.respond_to?(:http_code) && error.http_code.to_i == 404
nil
else
raise(error)
end
end
end
Expand Down Expand Up @@ -108,11 +107,10 @@ def head(key, options = {})
})
new(file_data)
rescue Exception => error
case error.http_code.to_i
when 404
nil
else
raise(error)
if error.respond_to?(:http_code) && error.http_code.to_i == 404
nil
else
raise(error)
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/fog/aliyun/requests/compute/attach_disk.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand Down Expand Up @@ -46,7 +48,7 @@ def attach_disk(instanceId, diskId, options = {})
if device
parameters['Device'] = device
pathUrl += '&Device='
pathUrl += URI.encode(device, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(device, Addressable::URI::CharacterClasses::UNRESERVED + '|')
end

signature = sign(@aliyun_accesskey_secret, parameters)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand All @@ -19,7 +21,7 @@ def create_security_group_egress_ip_rule(securitygroup_id, destCidrIp, nicType,

parameters['DestCidrIp'] = destCidrIp
pathUrl += '&DestCidrIp='
pathUrl += URI.encode(destCidrIp, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(destCidrIp, Addressable::URI::CharacterClasses::UNRESERVED + '|')
nicType ||= 'intranet'
parameters['NicType'] = nicType
pathUrl += '&NicType='
Expand All @@ -29,7 +31,7 @@ def create_security_group_egress_ip_rule(securitygroup_id, destCidrIp, nicType,
portRange ||= '-1/-1'
parameters['PortRange'] = portRange
pathUrl += '&PortRange='
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')

protocol = option[:protocol]
protocol ||= 'all'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand Down Expand Up @@ -30,7 +32,7 @@ def create_security_group_egress_sg_rule(securitygroup_id, dest_group_id, option
portRange ||= '-1/-1'
parameters['PortRange'] = portRange
pathUrl += '&PortRange='
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')

protocol = option[:protocol]
protocol ||= 'all'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand All @@ -19,7 +21,7 @@ def create_security_group_ip_rule(securitygroup_id, sourceCidrIp, nicType, optio

parameters['SourceCidrIp'] = sourceCidrIp
pathUrl += '&SourceCidrIp='
pathUrl += URI.encode(sourceCidrIp, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(sourceCidrIp, Addressable::URI::CharacterClasses::UNRESERVED + '|')
nicType ||= 'intranet'
parameters['NicType'] = nicType
pathUrl += '&NicType='
Expand All @@ -29,7 +31,7 @@ def create_security_group_ip_rule(securitygroup_id, sourceCidrIp, nicType, optio
portRange ||= '-1/-1'
parameters['PortRange'] = portRange
pathUrl += '&PortRange='
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')

protocol = option[:protocol]
protocol ||= 'all'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand Down Expand Up @@ -30,7 +32,7 @@ def create_security_group_sg_rule(securitygroup_id, source_securitygroup_id, opt
portRange ||= '-1/-1'
parameters['PortRange'] = portRange
pathUrl += '&PortRange='
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')

protocol = option[:protocol]
protocol ||= 'all'
Expand Down
4 changes: 3 additions & 1 deletion lib/fog/aliyun/requests/compute/create_vpc.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand All @@ -15,7 +17,7 @@ def create_vpc(cidrBlock, options = {})

parameters['CidrBlock'] = cidrBlock
pathUrl += '&CidrBlock='
pathUrl += URI.encode(cidrBlock, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(cidrBlock, Addressable::URI::CharacterClasses::UNRESERVED + '|')

name = options[:name]
desc = options[:description]
Expand Down
4 changes: 3 additions & 1 deletion lib/fog/aliyun/requests/compute/create_vswitch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand All @@ -19,7 +21,7 @@ def create_vswitch(vpcId, cidrBlock, options = {})

parameters['CidrBlock'] = cidrBlock
pathUrl += '&CidrBlock='
pathUrl += URI.encode(cidrBlock, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(cidrBlock, Addressable::URI::CharacterClasses::UNRESERVED + '|')

parameters['ZoneId'] = @aliyun_zone_id
pathUrl += '&ZoneId='
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand All @@ -19,7 +21,7 @@ def delete_security_group_egress_ip_rule(securitygroup_id, destCidrIp, nicType,

parameters['DestCidrIp'] = destCidrIp
pathUrl += '&DestCidrIp='
pathUrl += URI.encode(destCidrIp, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(destCidrIp, Addressable::URI::CharacterClasses::UNRESERVED + '|')
nicType ||= 'intranet'
parameters['NicType'] = nicType
pathUrl += '&NicType='
Expand All @@ -29,7 +31,7 @@ def delete_security_group_egress_ip_rule(securitygroup_id, destCidrIp, nicType,
portRange ||= '-1/-1'
parameters['PortRange'] = portRange
pathUrl += '&PortRange='
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')

protocol = option[:protocol]
protocol ||= 'all'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand Down Expand Up @@ -30,7 +32,7 @@ def delete_security_group_egress_sg_rule(securitygroup_id, dest_group_id, option
portRange ||= '-1/-1'
parameters['PortRange'] = portRange
pathUrl += '&PortRange='
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')

protocol = option[:protocol]
protocol ||= 'all'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand All @@ -19,7 +21,7 @@ def delete_security_group_ip_rule(securitygroup_id, sourceCidrIp, nicType, optio

parameters['SourceCidrIp'] = sourceCidrIp
pathUrl += '&SourceCidrIp='
pathUrl += URI.encode(sourceCidrIp, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(sourceCidrIp, Addressable::URI::CharacterClasses::UNRESERVED + '|')
nicType ||= 'intranet'
parameters['NicType'] = nicType
pathUrl += '&NicType='
Expand All @@ -29,7 +31,7 @@ def delete_security_group_ip_rule(securitygroup_id, sourceCidrIp, nicType, optio
portRange ||= '-1/-1'
parameters['PortRange'] = portRange
pathUrl += '&PortRange='
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')

protocol = option[:protocol]
protocol ||= 'all'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand Down Expand Up @@ -30,7 +32,7 @@ def delete_security_group_sg_rule(securitygroup_id, source_securitygroup_id, opt
portRange ||= '-1/-1'
parameters['PortRange'] = portRange
pathUrl += '&PortRange='
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')

protocol = option[:protocol]
protocol ||= 'all'
Expand Down
4 changes: 3 additions & 1 deletion lib/fog/aliyun/requests/compute/detach_disk.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand All @@ -25,7 +27,7 @@ def detach_disk(instanceId, diskId, _options = {})
if device
parameters['Device'] = device
pathUrl += '&Device='
pathUrl += URI.encode(device, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(device, Addressable::URI::CharacterClasses::UNRESERVED + '|')
end
signature = sign(@aliyun_accesskey_secret, parameters)
pathUrl += '&Signature='
Expand Down
4 changes: 3 additions & 1 deletion lib/fog/aliyun/requests/compute/modify_vpc.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand All @@ -15,7 +17,7 @@ def modify_vpc(vpcId, options = {})

parameters['VpcId'] = vpcId
pathUrl += '&VpcId='
pathUrl += URI.encode(vpcId, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(vpcId, Addressable::URI::CharacterClasses::UNRESERVED + '|')
name = options[:name]
desc = options[:description]

Expand Down
4 changes: 3 additions & 1 deletion lib/fog/aliyun/requests/compute/modify_vswitch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Compute
class Aliyun
Expand All @@ -15,7 +17,7 @@ def modify_switch(vSwitchId, options = {})

parameters['VSwitchId'] = vSwitchId
pathUrl += '&VSwitchId='
pathUrl += URI.encode(vpcId, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
pathUrl += Addressable::URI.encode_component(vpcId, Addressable::URI::CharacterClasses::UNRESERVED + '|')
name = options[:name]
desc = options[:description]

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/requests/storage/get_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_object(bucket_name, object_name, options = {}, &block)
end

if block_given?
http_options[:response_block] = Proc.new
http_options[:response_block] = Proc.new {}
end

resources = {
Expand Down
4 changes: 3 additions & 1 deletion lib/fog/aliyun/requests/storage/get_object_http_url.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'addressable'

module Fog
module Aliyun
class Storage
Expand All @@ -24,7 +26,7 @@ def get_object_http_url_public(bucket_name, object_name, expires)
signature = sign('GET', expires_time, nil, resource)
'http://' + bucket_name + '.' + @host + '/' + object_name +
'?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
'&Signature=' + URI.encode(signature, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
'&Signature=' + Addressable::URI.encode_component(signature, Addressable::URI::CharacterClasses::UNRESERVED + '|')
elsif acl == 'public-read' || acl == 'public-read-write'
'http://' + bucket_name + '.' + @host + '/' + object_name
else
Expand Down
Loading