From 7aad7fbe5207eb8023aa32926eae366bc88e0b20 Mon Sep 17 00:00:00 2001 From: biomancer Date: Sat, 28 Mar 2015 17:34:59 +0300 Subject: [PATCH 1/5] Host and port options support for create_temp_url --- lib/fog/hp/storage.rb | 20 ++++++++++++++++--- .../requests/storage/get_object_https_url.rb | 10 +++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/fog/hp/storage.rb b/lib/fog/hp/storage.rb index 5a96a1e7e..8613f77d1 100644 --- a/lib/fog/hp/storage.rb +++ b/lib/fog/hp/storage.rb @@ -197,8 +197,10 @@ module Fog # * object<~String> - Name of object to get expiring url for # * expires<~Time> - An expiry time for this url # * method<~String> - The method to use for accessing the object (GET, PUT, HEAD) - # * scheme<~String> - The scheme to use (http, https) # * options<~Hash> - An optional options hash + # * 'scheme'<~String> - The scheme to use (http, https) + # * 'host'<~String> - The host to use + # * 'port'<~Integer> - The port to use # # ==== Returns # * response<~Excon::Response>: @@ -214,6 +216,8 @@ module Fog expires = expires.to_i scheme = options[:scheme] || @scheme + host = options[:host] || @host + port = options[:port] || @port # do not encode before signature generation, encode after sig_path = "#{@path}/#{container}/#{object}" @@ -226,7 +230,7 @@ module Fog # HP uses a different strategy to create the signature that is passed to swift than OpenStack. # As the HP provider is broadly used by OpenStack users the OpenStack strategy is applied when # the @os_account_meta_temp_url_key is given. - if @os_account_meta_temp_url_key then + if @os_account_meta_temp_url_key hmac = OpenSSL::HMAC.new(@os_account_meta_temp_url_key, OpenSSL::Digest::SHA1.new) signature= hmac.update(string_to_sign).hexdigest else @@ -247,7 +251,17 @@ module Fog end # generate the temp url using the signature and expiry - "#{scheme}://#{@host}#{encoded_path}?temp_url_sig=#{signature}&temp_url_expires=#{expires}" + temp_url_options = { + :scheme => scheme, + :host => host, + :port => port, + :path => encoded_path, + :query => URI.encode_www_form( + :temp_url_sig => signature, + :temp_url_expires => expires + ) + } + URI::Generic.build(temp_url_options).to_s end end diff --git a/lib/fog/openstack/requests/storage/get_object_https_url.rb b/lib/fog/openstack/requests/storage/get_object_https_url.rb index 999b2ae6d..0d51f3320 100644 --- a/lib/fog/openstack/requests/storage/get_object_https_url.rb +++ b/lib/fog/openstack/requests/storage/get_object_https_url.rb @@ -23,8 +23,10 @@ module Fog # * object<~String> - Name of object to get expiring url for # * expires<~Time> - An expiry time for this url # * method<~String> - The method to use for accessing the object (GET, PUT, HEAD) - # * scheme<~String> - The scheme to use (http, https) # * options<~Hash> - An optional options hash + # * 'scheme'<~String> - The scheme to use (http, https) + # * 'host'<~String> - The host to use + # * 'port'<~Integer> - The port to use # # ==== Returns # * response<~Excon::Response>: @@ -37,6 +39,8 @@ module Fog raise ArgumentError, "Storage must be instantiated with the :openstack_temp_url_key option" if @openstack_temp_url_key.nil? scheme = options[:scheme] || @scheme + host = options[:host] || @host + port = options[:port] || @port # POST not allowed allowed_methods = %w{GET PUT HEAD} @@ -54,8 +58,8 @@ module Fog temp_url_options = { :scheme => scheme, - :host => @host, - :port => @port, + :host => host, + :port => port, :path => object_path_escaped, :query => URI.encode_www_form( :temp_url_sig => sig, From 1fad5024e376bb679dbde4316480c8b2631ddafe Mon Sep 17 00:00:00 2001 From: biomancer Date: Fri, 3 Apr 2015 21:52:49 +0300 Subject: [PATCH 2/5] Fix hp storage tests --- lib/fog/hp/storage.rb | 9 +++++++++ tests/helpers/mock_helper.rb | 1 + 2 files changed, 10 insertions(+) diff --git a/lib/fog/hp/storage.rb b/lib/fog/hp/storage.rb index 8613f77d1..6dd8bb30f 100644 --- a/lib/fog/hp/storage.rb +++ b/lib/fog/hp/storage.rb @@ -300,6 +300,15 @@ module Fog @hp_secret_key = options[:hp_secret_key] @hp_tenant_id = options[:hp_tenant_id] @os_account_meta_temp_url_key = options[:os_account_meta_temp_url_key] + + @hp_storage_uri = options[:hp_auth_uri] + + uri = URI.parse(@hp_storage_uri) + @host = uri.host + @path = uri.path + @persistent = options[:persistent] || false + @port = uri.port + @scheme = uri.scheme end def data diff --git a/tests/helpers/mock_helper.rb b/tests/helpers/mock_helper.rb index 9f40c7eb9..3ec2a00d9 100644 --- a/tests/helpers/mock_helper.rb +++ b/tests/helpers/mock_helper.rb @@ -40,6 +40,7 @@ if Fog.mock? :hp_secret_key => 'hp_secret_key', :hp_tenant_id => 'hp_tenant_id', :hp_avl_zone => 'hp_avl_zone', + :hp_auth_uri => 'http://hp/v2.0/tokens', :os_account_meta_temp_url_key => 'os_account_meta_temp_url_key', :ibm_username => 'ibm_username', :ibm_password => 'ibm_password', From 5048fbc6cb00d578ceb3e414be818e22e4294b29 Mon Sep 17 00:00:00 2001 From: biomancer Date: Fri, 3 Apr 2015 21:54:02 +0300 Subject: [PATCH 3/5] Use sane default ports for get_object_http(s)_url --- lib/fog/hp/storage.rb | 4 ++-- lib/fog/openstack/requests/storage/get_object_http_url.rb | 2 +- lib/fog/openstack/requests/storage/get_object_https_url.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fog/hp/storage.rb b/lib/fog/hp/storage.rb index 6dd8bb30f..94bb4cd14 100644 --- a/lib/fog/hp/storage.rb +++ b/lib/fog/hp/storage.rb @@ -158,7 +158,7 @@ module Fog # * response<~Excon::Response>: # * body<~String> - url for object def get_object_https_url(container, object, expires, options = {}) - create_temp_url(container, object, expires, "GET", options.merge(:scheme => "https")) + create_temp_url(container, object, expires, "GET", options.merge(:scheme => "https", :port => 443)) end # Get an expiring object http url @@ -172,7 +172,7 @@ module Fog # * response<~Excon::Response>: # * body<~String> - url for object def get_object_http_url(container, object, expires, options = {}) - create_temp_url(container, object, expires, "GET", options.merge(:scheme => "http")) + create_temp_url(container, object, expires, "GET", options.merge(:scheme => "http", :port => 80)) end # Get an object http url expiring in the given amount of seconds diff --git a/lib/fog/openstack/requests/storage/get_object_http_url.rb b/lib/fog/openstack/requests/storage/get_object_http_url.rb index d21c86e22..2ea680de7 100644 --- a/lib/fog/openstack/requests/storage/get_object_http_url.rb +++ b/lib/fog/openstack/requests/storage/get_object_http_url.rb @@ -13,7 +13,7 @@ module Fog # * response<~Excon::Response>: # * body<~String> - url for object def get_object_http_url(container, object, expires, options = {}) - create_temp_url(container, object, expires, "GET", options.merge(:scheme => "http")) + create_temp_url(container, object, expires, "GET", options.merge(:scheme => "http", :port => 80)) end end end diff --git a/lib/fog/openstack/requests/storage/get_object_https_url.rb b/lib/fog/openstack/requests/storage/get_object_https_url.rb index 0d51f3320..71fc1dbc0 100644 --- a/lib/fog/openstack/requests/storage/get_object_https_url.rb +++ b/lib/fog/openstack/requests/storage/get_object_https_url.rb @@ -13,7 +13,7 @@ module Fog # * response<~Excon::Response>: # * body<~String> - url for object def get_object_https_url(container, object, expires, options = {}) - create_temp_url(container, object, expires, "GET", options.merge(:scheme => "https")) + create_temp_url(container, object, expires, "GET", options.merge(:scheme => "https", :port => 443)) end # creates a temporary url From e6cc425b272501270373f25256707221cac6337d Mon Sep 17 00:00:00 2001 From: biomancer Date: Fri, 3 Apr 2015 21:59:37 +0300 Subject: [PATCH 4/5] Compatibility fix for ruby 1.8.7 that does not have URI.encode_www_form method --- lib/fog/hp/storage.rb | 5 +---- lib/fog/openstack/requests/storage/get_object_https_url.rb | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/fog/hp/storage.rb b/lib/fog/hp/storage.rb index 94bb4cd14..f22603f9d 100644 --- a/lib/fog/hp/storage.rb +++ b/lib/fog/hp/storage.rb @@ -256,10 +256,7 @@ module Fog :host => host, :port => port, :path => encoded_path, - :query => URI.encode_www_form( - :temp_url_sig => signature, - :temp_url_expires => expires - ) + :query => "temp_url_sig=#{signature}&temp_url_expires=#{expires}" } URI::Generic.build(temp_url_options).to_s end diff --git a/lib/fog/openstack/requests/storage/get_object_https_url.rb b/lib/fog/openstack/requests/storage/get_object_https_url.rb index 71fc1dbc0..de80c0559 100644 --- a/lib/fog/openstack/requests/storage/get_object_https_url.rb +++ b/lib/fog/openstack/requests/storage/get_object_https_url.rb @@ -61,10 +61,7 @@ module Fog :host => host, :port => port, :path => object_path_escaped, - :query => URI.encode_www_form( - :temp_url_sig => sig, - :temp_url_expires => expires - ) + :query => "temp_url_sig=#{sig}&temp_url_expires=#{expires}" } URI::Generic.build(temp_url_options).to_s end From b6b246c7c3bca6e3cb36989e42567a5303672ec6 Mon Sep 17 00:00:00 2001 From: biomancer Date: Fri, 3 Apr 2015 22:10:46 +0300 Subject: [PATCH 5/5] Make port option overridable for get_object_http(s)_url --- lib/fog/hp/storage.rb | 4 ++-- lib/fog/openstack/requests/storage/get_object_http_url.rb | 2 +- lib/fog/openstack/requests/storage/get_object_https_url.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fog/hp/storage.rb b/lib/fog/hp/storage.rb index f22603f9d..25d22e5b7 100644 --- a/lib/fog/hp/storage.rb +++ b/lib/fog/hp/storage.rb @@ -158,7 +158,7 @@ module Fog # * response<~Excon::Response>: # * body<~String> - url for object def get_object_https_url(container, object, expires, options = {}) - create_temp_url(container, object, expires, "GET", options.merge(:scheme => "https", :port => 443)) + create_temp_url(container, object, expires, "GET", {:port => 443}.merge(options).merge(:scheme => "https")) end # Get an expiring object http url @@ -172,7 +172,7 @@ module Fog # * response<~Excon::Response>: # * body<~String> - url for object def get_object_http_url(container, object, expires, options = {}) - create_temp_url(container, object, expires, "GET", options.merge(:scheme => "http", :port => 80)) + create_temp_url(container, object, expires, "GET", {:port => 80}.merge(options).merge(:scheme => "http")) end # Get an object http url expiring in the given amount of seconds diff --git a/lib/fog/openstack/requests/storage/get_object_http_url.rb b/lib/fog/openstack/requests/storage/get_object_http_url.rb index 2ea680de7..0e8582417 100644 --- a/lib/fog/openstack/requests/storage/get_object_http_url.rb +++ b/lib/fog/openstack/requests/storage/get_object_http_url.rb @@ -13,7 +13,7 @@ module Fog # * response<~Excon::Response>: # * body<~String> - url for object def get_object_http_url(container, object, expires, options = {}) - create_temp_url(container, object, expires, "GET", options.merge(:scheme => "http", :port => 80)) + create_temp_url(container, object, expires, "GET", {:port => 80}.merge(options).merge(:scheme => "http")) end end end diff --git a/lib/fog/openstack/requests/storage/get_object_https_url.rb b/lib/fog/openstack/requests/storage/get_object_https_url.rb index de80c0559..0f611be9a 100644 --- a/lib/fog/openstack/requests/storage/get_object_https_url.rb +++ b/lib/fog/openstack/requests/storage/get_object_https_url.rb @@ -13,7 +13,7 @@ module Fog # * response<~Excon::Response>: # * body<~String> - url for object def get_object_https_url(container, object, expires, options = {}) - create_temp_url(container, object, expires, "GET", options.merge(:scheme => "https", :port => 443)) + create_temp_url(container, object, expires, "GET", {:port => 443}.merge(options).merge(:scheme => "https")) end # creates a temporary url