[aws&google|storage] make signature public method
supports some edge case caching stuff closes #155
This commit is contained in:
parent
db6801f9cd
commit
5d8fec1501
|
@ -286,26 +286,6 @@ module Fog
|
||||||
@connection.reset
|
@connection.reset
|
||||||
end
|
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)
|
def signature(params)
|
||||||
string_to_sign =
|
string_to_sign =
|
||||||
<<-DATA
|
<<-DATA
|
||||||
|
@ -356,6 +336,27 @@ DATA
|
||||||
signed_string = @hmac.sign(string_to_sign)
|
signed_string = @hmac.sign(string_to_sign)
|
||||||
signature = Base64.encode64(signed_string).chomp!
|
signature = Base64.encode64(signed_string).chomp!
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -209,17 +209,6 @@ module Fog
|
||||||
@connection.reset
|
@connection.reset
|
||||||
end
|
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)
|
def signature(params)
|
||||||
string_to_sign =
|
string_to_sign =
|
||||||
<<-DATA
|
<<-DATA
|
||||||
|
@ -271,6 +260,18 @@ DATA
|
||||||
signed_string = @hmac.sign(string_to_sign)
|
signed_string = @hmac.sign(string_to_sign)
|
||||||
signature = Base64.encode64(signed_string).chomp!
|
signature = Base64.encode64(signed_string).chomp!
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue