Skip to content

Commit 3207fec

Browse files
philippthunjohha
authored andcommitted
Use Addressable::URI.encode_component instead of URI.encode
Update Ruby version to 3.0. Co-authored-by: Johannes Haass <johannes.haass@sap.com>
1 parent 5de9351 commit 3207fec

20 files changed

+72
-27
lines changed

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.5.1
1+
3.0.4

fog-aliyun.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
2121
spec.require_paths = ['lib']
2222

2323
spec.add_development_dependency 'bundler'
24-
spec.add_development_dependency 'mime-types', '~> 2.6', '>= 2.6.2'
24+
spec.add_development_dependency 'mime-types', '~> 3.4'
2525
spec.add_development_dependency 'pry-nav'
2626
spec.add_development_dependency 'rake'
2727
spec.add_development_dependency 'rspec'
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
3030
spec.add_development_dependency 'memory_profiler'
3131
spec.add_development_dependency 'aliyun-sdk', '~> 0.8.0'
3232

33+
spec.add_dependency 'addressable', '~> 2.8.0'
3334
spec.add_dependency 'aliyun-sdk', '~> 0.8.0'
3435
spec.add_dependency 'fog-core'
3536
spec.add_dependency 'fog-json'

lib/fog/aliyun/compute.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'addressable'
4+
35
module Fog
46
module Compute
57
class Aliyun < Fog::Service
@@ -350,7 +352,7 @@ def VPCrequest(params)
350352
# operation compute-- default URL
351353
def defaultAliyunUri(action, sigNonce, time)
352354
parTimeFormat = time.strftime('%Y-%m-%dT%H:%M:%SZ')
353-
urlTimeFormat = URI.encode(parTimeFormat, ':')
355+
urlTimeFormat = Addressable::URI.encode_component(parTimeFormat, Addressable::URI::CharacterClasses::UNRESERVED + '|')
354356
'?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
355357
end
356358

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

371373
def defaultAliyunVPCUri(action, sigNonce, time)
372374
parTimeFormat = time.strftime('%Y-%m-%dT%H:%M:%SZ')
373-
urlTimeFormat = URI.encode(parTimeFormat, ':')
375+
urlTimeFormat = Addressable::URI.encode_component(parTimeFormat, Addressable::URI::CharacterClasses::UNRESERVED + '|')
374376
'?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
375377
end
376378

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

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

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

437439
digVer = OpenSSL::Digest.new('sha1')

lib/fog/aliyun/requests/compute/attach_disk.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'addressable'
4+
35
module Fog
46
module Compute
57
class Aliyun
@@ -46,7 +48,7 @@ def attach_disk(instanceId, diskId, options = {})
4648
if device
4749
parameters['Device'] = device
4850
pathUrl += '&Device='
49-
pathUrl += URI.encode(device, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
51+
pathUrl += Addressable::URI.encode_component(device, Addressable::URI::CharacterClasses::UNRESERVED + '|')
5052
end
5153

5254
signature = sign(@aliyun_accesskey_secret, parameters)

lib/fog/aliyun/requests/compute/create_security_group_egress_ip_rule.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'addressable'
4+
35
module Fog
46
module Compute
57
class Aliyun
@@ -19,7 +21,7 @@ def create_security_group_egress_ip_rule(securitygroup_id, destCidrIp, nicType,
1921

2022
parameters['DestCidrIp'] = destCidrIp
2123
pathUrl += '&DestCidrIp='
22-
pathUrl += URI.encode(destCidrIp, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
24+
pathUrl += Addressable::URI.encode_component(destCidrIp, Addressable::URI::CharacterClasses::UNRESERVED + '|')
2325
nicType ||= 'intranet'
2426
parameters['NicType'] = nicType
2527
pathUrl += '&NicType='
@@ -29,7 +31,7 @@ def create_security_group_egress_ip_rule(securitygroup_id, destCidrIp, nicType,
2931
portRange ||= '-1/-1'
3032
parameters['PortRange'] = portRange
3133
pathUrl += '&PortRange='
32-
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
34+
pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')
3335

3436
protocol = option[:protocol]
3537
protocol ||= 'all'

lib/fog/aliyun/requests/compute/create_security_group_egress_sg_rule.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'addressable'
4+
35
module Fog
46
module Compute
57
class Aliyun
@@ -30,7 +32,7 @@ def create_security_group_egress_sg_rule(securitygroup_id, dest_group_id, option
3032
portRange ||= '-1/-1'
3133
parameters['PortRange'] = portRange
3234
pathUrl += '&PortRange='
33-
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
35+
pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')
3436

3537
protocol = option[:protocol]
3638
protocol ||= 'all'

lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'addressable'
4+
35
module Fog
46
module Compute
57
class Aliyun
@@ -19,7 +21,7 @@ def create_security_group_ip_rule(securitygroup_id, sourceCidrIp, nicType, optio
1921

2022
parameters['SourceCidrIp'] = sourceCidrIp
2123
pathUrl += '&SourceCidrIp='
22-
pathUrl += URI.encode(sourceCidrIp, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
24+
pathUrl += Addressable::URI.encode_component(sourceCidrIp, Addressable::URI::CharacterClasses::UNRESERVED + '|')
2325
nicType ||= 'intranet'
2426
parameters['NicType'] = nicType
2527
pathUrl += '&NicType='
@@ -29,7 +31,7 @@ def create_security_group_ip_rule(securitygroup_id, sourceCidrIp, nicType, optio
2931
portRange ||= '-1/-1'
3032
parameters['PortRange'] = portRange
3133
pathUrl += '&PortRange='
32-
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
34+
pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')
3335

3436
protocol = option[:protocol]
3537
protocol ||= 'all'

lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'addressable'
4+
35
module Fog
46
module Compute
57
class Aliyun
@@ -30,7 +32,7 @@ def create_security_group_sg_rule(securitygroup_id, source_securitygroup_id, opt
3032
portRange ||= '-1/-1'
3133
parameters['PortRange'] = portRange
3234
pathUrl += '&PortRange='
33-
pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
35+
pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')
3436

3537
protocol = option[:protocol]
3638
protocol ||= 'all'

lib/fog/aliyun/requests/compute/create_vpc.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'addressable'
4+
35
module Fog
46
module Compute
57
class Aliyun
@@ -15,7 +17,7 @@ def create_vpc(cidrBlock, options = {})
1517

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

2022
name = options[:name]
2123
desc = options[:description]

lib/fog/aliyun/requests/compute/create_vswitch.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'addressable'
4+
35
module Fog
46
module Compute
57
class Aliyun
@@ -19,7 +21,7 @@ def create_vswitch(vpcId, cidrBlock, options = {})
1921

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

2426
parameters['ZoneId'] = @aliyun_zone_id
2527
pathUrl += '&ZoneId='

0 commit comments

Comments
 (0)