mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Refactor escape method for container and object names and move it to the HP provider from individual namespaces.
This commit is contained in:
parent
f781680309
commit
813c23ae10
17 changed files with 23 additions and 32 deletions
|
@ -167,6 +167,13 @@ module Fog
|
|||
|
||||
end
|
||||
|
||||
# CGI.escape, but without special treatment on spaces
|
||||
def self.escape(str,extra_exclude_chars = '')
|
||||
str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do
|
||||
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.get_endpoint_from_catalog(service_catalog, service_type, avl_zone)
|
||||
|
|
|
@ -18,14 +18,7 @@ module Fog
|
|||
request :delete_container
|
||||
|
||||
module Utils
|
||||
# Take care of container names with '?' in them
|
||||
def escape_name(name)
|
||||
if name.include?('?')
|
||||
URI.escape(name).gsub('?', '%3F')
|
||||
else
|
||||
URI.escape(name)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
|
|
@ -70,7 +70,7 @@ module Fog
|
|||
@public_url ||= begin
|
||||
begin response = connection.head_container(key)
|
||||
# escape the key to cover for special char. in container names
|
||||
url = "#{connection.url}/#{connection.escape_name(key)}"
|
||||
url = "#{connection.url}/#{Fog::HP.escape(key)}"
|
||||
rescue Fog::Storage::HP::NotFound => err
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -68,7 +68,7 @@ module Fog
|
|||
requires :directory
|
||||
if self.directory.public_url
|
||||
# escape the key to cover for special char. in object names
|
||||
"#{self.directory.public_url}/#{connection.escape_name(key)}"
|
||||
"#{self.directory.public_url}/#{Fog::HP.escape(key)}"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -76,7 +76,7 @@ module Fog
|
|||
requires :directory
|
||||
if self.directory.cdn_public_url
|
||||
# escape the key to cover for special char. in object names
|
||||
"#{self.directory.cdn_public_url}/#{connection.escape_name(key)}"
|
||||
"#{self.directory.cdn_public_url}/#{Fog::HP.escape(key)}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ module Fog
|
|||
response = request(
|
||||
:expects => 204,
|
||||
:method => 'DELETE',
|
||||
:path => escape_name(name)
|
||||
:path => Fog::HP.escape(name)
|
||||
)
|
||||
response
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ module Fog
|
|||
response = request(
|
||||
:expects => 204,
|
||||
:method => 'HEAD',
|
||||
:path => escape_name(name),
|
||||
:path => Fog::HP.escape(name),
|
||||
:query => {'format' => 'json'}
|
||||
)
|
||||
response
|
||||
|
|
|
@ -17,7 +17,7 @@ module Fog
|
|||
:expects => [201, 202],
|
||||
:headers => options,
|
||||
:method => 'POST',
|
||||
:path => escape_name(name)
|
||||
:path => Fog::HP.escape(name)
|
||||
)
|
||||
response
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ module Fog
|
|||
:expects => [201, 202],
|
||||
:headers => options,
|
||||
:method => 'PUT',
|
||||
:path => escape_name(name)
|
||||
:path => Fog::HP.escape(name)
|
||||
)
|
||||
response
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ module Fog
|
|||
response = request(
|
||||
:expects => 204,
|
||||
:method => 'DELETE',
|
||||
:path => escape_name(name)
|
||||
:path => Fog::HP.escape(name)
|
||||
)
|
||||
response
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
response = request(
|
||||
:expects => 204,
|
||||
:method => 'DELETE',
|
||||
:path => "#{escape_name(container)}/#{escape_name(object)}"
|
||||
:path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}"
|
||||
)
|
||||
response
|
||||
end
|
||||
|
|
|
@ -33,7 +33,7 @@ module Fog
|
|||
response = request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => escape_name(container),
|
||||
:path => Fog::HP.escape(container),
|
||||
:query => {'format' => 'json'}.merge!(options)
|
||||
)
|
||||
response
|
||||
|
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
:block => block,
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "#{escape_name(container)}/#{escape_name(object)}"
|
||||
:path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}"
|
||||
}, false, &block)
|
||||
response
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ module Fog
|
|||
response = request(
|
||||
:expects => 204,
|
||||
:method => 'HEAD',
|
||||
:path => escape_name(container),
|
||||
:path => Fog::HP.escape(container),
|
||||
:query => {'format' => 'json'}
|
||||
)
|
||||
response
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
response = request({
|
||||
:expects => 200,
|
||||
:method => 'HEAD',
|
||||
:path => "#{escape_name(container)}/#{escape_name(object)}"
|
||||
:path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}"
|
||||
}, false)
|
||||
response
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
:expects => [201, 202],
|
||||
:headers => options,
|
||||
:method => 'PUT',
|
||||
:path => escape_name(name)
|
||||
:path => Fog::HP.escape(name)
|
||||
)
|
||||
response
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ module Fog
|
|||
:expects => 201,
|
||||
:headers => headers,
|
||||
:method => 'PUT',
|
||||
:path => "#{escape_name(container)}/#{escape_name(object)}"
|
||||
:path => "#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}"
|
||||
)
|
||||
response
|
||||
end
|
||||
|
|
|
@ -80,15 +80,6 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
# Take care of container names with '?' in them
|
||||
def escape_name(name)
|
||||
if name.include?('?')
|
||||
URI.escape(name).gsub('?', '%3F')
|
||||
else
|
||||
URI.escape(name)
|
||||
end
|
||||
end
|
||||
|
||||
def info
|
||||
{:url => url, :auth_token => @auth_token}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue