diff --git a/lib/fog/rackspace.rb b/lib/fog/rackspace.rb index 57678e94d..1499d4381 100644 --- a/lib/fog/rackspace.rb +++ b/lib/fog/rackspace.rb @@ -90,6 +90,13 @@ module Fog end end + def self.normalize_url(endpoint) + return nil unless endpoint + str = endpoint.chomp " " + str = str.chomp "/" + str.downcase + 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 diff --git a/lib/fog/rackspace/block_storage.rb b/lib/fog/rackspace/block_storage.rb index d73075092..6b8f78bf8 100644 --- a/lib/fog/rackspace/block_storage.rb +++ b/lib/fog/rackspace/block_storage.rb @@ -136,7 +136,7 @@ module Fog private def setup_custom_endpoint(options) - @rackspace_endpoint = options[:rackspace_block_storage_url] || options[:rackspace_endpoint] + @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_block_storage_url] || options[:rackspace_endpoint]) if v2_authentication? case @rackspace_endpoint diff --git a/lib/fog/rackspace/compute.rb b/lib/fog/rackspace/compute.rb index eb3658cd4..8621ea460 100644 --- a/lib/fog/rackspace/compute.rb +++ b/lib/fog/rackspace/compute.rb @@ -188,7 +188,7 @@ module Fog @rackspace_auth_url = options[:rackspace_auth_url] @rackspace_servicenet = options[:rackspace_servicenet] @rackspace_auth_token = options[:rackspace_auth_token] - @rackspace_endpoint = options[:rackspace_compute_v1_url] || options[:rackspace_management_url] + @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_compute_v1_url] || options[:rackspace_management_url]) @rackspace_must_reauthenticate = false @connection_options = options[:connection_options] || {} authenticate diff --git a/lib/fog/rackspace/compute_v2.rb b/lib/fog/rackspace/compute_v2.rb index a3f73723d..897edf456 100644 --- a/lib/fog/rackspace/compute_v2.rb +++ b/lib/fog/rackspace/compute_v2.rb @@ -168,7 +168,7 @@ module Fog private def setup_custom_endpoint(options) - @rackspace_endpoint = options[:rackspace_compute_url] || options[:rackspace_endpoint] + @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_compute_url] || options[:rackspace_endpoint]) if v2_authentication? case @rackspace_endpoint diff --git a/lib/fog/rackspace/databases.rb b/lib/fog/rackspace/databases.rb index 5d618dfc5..4a8368881 100644 --- a/lib/fog/rackspace/databases.rb +++ b/lib/fog/rackspace/databases.rb @@ -127,7 +127,7 @@ module Fog private def setup_custom_endpoint(options) - @rackspace_endpoint = options[:rackspace_database_url] || options[:rackspace_endpoint] + @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_database_url] || options[:rackspace_endpoint]) if v2_authentication? case @rackspace_endpoint diff --git a/lib/fog/rackspace/dns.rb b/lib/fog/rackspace/dns.rb index 3e101ee00..81b7757d9 100644 --- a/lib/fog/rackspace/dns.rb +++ b/lib/fog/rackspace/dns.rb @@ -87,7 +87,7 @@ module Fog @rackspace_username = options[:rackspace_username] @rackspace_auth_url = options[:rackspace_auth_url] @connection_options = options[:connection_options] || {} - @rackspace_endpoint = options[:rackspace_dns_url] || options[:rackspace_dns_endpoint] + @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_dns_url] || options[:rackspace_dns_endpoint]) @rackspace_region = options[:rackspace_region] authenticate diff --git a/lib/fog/rackspace/load_balancers.rb b/lib/fog/rackspace/load_balancers.rb index 5ad99dd17..9fdcfe8d5 100644 --- a/lib/fog/rackspace/load_balancers.rb +++ b/lib/fog/rackspace/load_balancers.rb @@ -169,7 +169,7 @@ module Fog private def setup_custom_endpoint(options) - @rackspace_endpoint = options[:rackspace_load_balancers_url] || options[:rackspace_lb_endpoint] + @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_load_balancers_url] || options[:rackspace_lb_endpoint]) if v2_authentication? case @rackspace_endpoint diff --git a/tests/rackspace/rackspace_tests.rb b/tests/rackspace/rackspace_tests.rb new file mode 100644 index 000000000..3b43e6c44 --- /dev/null +++ b/tests/rackspace/rackspace_tests.rb @@ -0,0 +1,21 @@ +Shindo.tests('Fog::Rackspace', ['rackspace']) do + + tests('normalize_url') do + tests('should return nil if endpoint is nil').returns(nil) do + Fog::Rackspace.normalize_url nil + end + tests('should remove trailing spaces').returns("https://dfw.blockstorage.api.rackspacecloud.com/v1") do + Fog::Rackspace.normalize_url "https://dfw.blockstorage.api.rackspacecloud.com/v1 " + end + tests('should remove trailing /').returns("https://dfw.blockstorage.api.rackspacecloud.com/v1") do + Fog::Rackspace.normalize_url "https://dfw.blockstorage.api.rackspacecloud.com/v1/" + end + tests('should downcase url').returns("https://dfw.blockstorage.api.rackspacecloud.com/v1") do + Fog::Rackspace.normalize_url "HTTPS://DFW.BLOCKSTORAGE.API.RACKSPACECLOUD.COM/V1" + end + tests('show do all three').returns("https://dfw.blockstorage.api.rackspacecloud.com/v1") do + Fog::Rackspace.normalize_url "HTTPS://DFW.BLOCKSTORAGE.API.RACKSPACECLOUD.COM/V1/ " + end + end + +end \ No newline at end of file