11# frozen_string_literal: true
22
3+ require 'addressable'
4+
35module 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' )
0 commit comments