[aws&google|storage] make signature public method

supports some edge case caching stuff
closes #155
This commit is contained in:
geemus 2011-02-08 10:06:44 -08:00
parent db6801f9cd
commit 5d8fec1501
2 changed files with 33 additions and 31 deletions

View File

@ -286,26 +286,6 @@ module Fog
@connection.reset
end
private
def request(params, &block)
params[:headers]['Date'] = Fog::Time.now.to_date_header
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature(params)}"
params[:expects] = [307, *params[:expects]].flatten
# FIXME: ToHashParser should make this not needed
original_params = params.dup
response = @connection.request(params, &block)
if response.status == 307
uri = URI.parse(response.headers['Location'])
Formatador.display_line("[yellow][WARN] fog: followed redirect to #{uri.host}, connecting to the matching region will be more performant[/]")
response = Fog::Connection.new("#{@scheme}://#{uri.host}:#{@port}", false).request(original_params, &block)
end
response
end
def signature(params)
string_to_sign =
<<-DATA
@ -356,6 +336,27 @@ DATA
signed_string = @hmac.sign(string_to_sign)
signature = Base64.encode64(signed_string).chomp!
end
private
def request(params, &block)
params[:headers]['Date'] = Fog::Time.now.to_date_header
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature(params)}"
params[:expects] = [307, *params[:expects]].flatten
# FIXME: ToHashParser should make this not needed
original_params = params.dup
response = @connection.request(params, &block)
if response.status == 307
uri = URI.parse(response.headers['Location'])
Formatador.display_line("[yellow][WARN] fog: followed redirect to #{uri.host}, connecting to the matching region will be more performant[/]")
response = Fog::Connection.new("#{@scheme}://#{uri.host}:#{@port}", false).request(original_params, &block)
end
response
end
end
end
end

View File

@ -209,17 +209,6 @@ module Fog
@connection.reset
end
private
def request(params, &block)
params[:headers]['Date'] = Fog::Time.now.to_date_header
params[:headers]['Authorization'] = "GOOG1 #{@google_storage_access_key_id}:#{signature(params)}"
response = @connection.request(params, &block)
response
end
def signature(params)
string_to_sign =
<<-DATA
@ -271,6 +260,18 @@ DATA
signed_string = @hmac.sign(string_to_sign)
signature = Base64.encode64(signed_string).chomp!
end
private
def request(params, &block)
params[:headers]['Date'] = Fog::Time.now.to_date_header
params[:headers]['Authorization'] = "GOOG1 #{@google_storage_access_key_id}:#{signature(params)}"
response = @connection.request(params, &block)
response
end
end
end
end