Permalink
Browse files

Merge pull request #1912 from anynines/master

OpenStack Temp URL Support and AWS::File compatibility
  • Loading branch information...
2 parents 8c87f82 + 90e50e5 commit 6f254b3fdddb717c9059fc119cef0e3c0a5a5210 @geemus geemus committed Jun 27, 2013
Showing with 26 additions and 9 deletions.
  1. +26 −9 lib/fog/hp/storage.rb
View
@@ -10,8 +10,11 @@ class HP < Fog::Service
recognizes :persistent, :connection_options
recognizes :hp_use_upass_auth_style, :hp_auth_version, :user_agent
recognizes :hp_access_key, :hp_account_id # :hp_account_id is deprecated use hp_access_key instead
+
+ # :os_account_meta_temp_url_key is an OpenStack specific setting used to generate temporary urls.
+ recognizes :os_account_meta_temp_url_key
- secrets :hp_secret_key
+ secrets :hp_secret_key, :os_account_meta_temp_url_key
model_path 'fog/hp/models/storage'
model :directory
@@ -167,14 +170,26 @@ def generate_object_temp_url(container, object, expires_secs, method)
encoded_path = "#{path}/#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}"
string_to_sign = "#{method}\n#{expires}\n#{sig_path}"
- # Only works with 1.9+ Not compatible with 1.8.7
- #signed_string = Digest::HMAC.hexdigest(string_to_sign, @hp_secret_key, Digest::SHA1)
- # Compatible with 1.8.7 onwards
- hmac = OpenSSL::HMAC.new(@hp_secret_key, OpenSSL::Digest::SHA1.new)
- signed_string = hmac.update(string_to_sign).hexdigest
-
- signature = @hp_tenant_id.to_s + ":" + @hp_access_key.to_s + ":" + signed_string
- signature = Fog::HP.escape(signature)
+
+ signature = nil
+
+ # 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
+ hmac = OpenSSL::HMAC.new(@os_account_meta_temp_url_key, OpenSSL::Digest::SHA1.new)
+ signature= hmac.update(string_to_sign).hexdigest
+ else
+ # Only works with 1.9+ Not compatible with 1.8.7
+ #signed_string = Digest::HMAC.hexdigest(string_to_sign, @hp_secret_key, Digest::SHA1)
+
+ # Compatible with 1.8.7 onwards
+ hmac = OpenSSL::HMAC.new(@hp_secret_key, OpenSSL::Digest::SHA1.new)
+ signed_string = hmac.update(string_to_sign).hexdigest
+
+ signature = @hp_tenant_id.to_s + ":" + @hp_access_key.to_s + ":" + signed_string
+ signature = Fog::HP.escape(signature)
+ end
# generate the temp url using the signature and expiry
"#{scheme}://#{host}:#{port}#{encoded_path}?temp_url_sig=#{signature}&temp_url_expires=#{expires}"
@@ -217,6 +232,7 @@ def initialize(options={})
end
@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]
end
def data
@@ -254,6 +270,7 @@ def initialize(options={})
options[:hp_service_type] = "Object Storage"
@hp_tenant_id = options[:hp_tenant_id]
@hp_avl_zone = options[:hp_avl_zone]
+ @os_account_meta_temp_url_key = options[:os_account_meta_temp_url_key]
### Make the authentication call
if (auth_version == :v2)

0 comments on commit 6f254b3

Please sign in to comment.