mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2281 from burns/aws_storage_connection
[aws|storage] ensure connection uses correct scheme, host and port
This commit is contained in:
commit
be6a5955f0
1 changed files with 23 additions and 9 deletions
|
@ -184,9 +184,9 @@ module Fog
|
||||||
|
|
||||||
if params[:scheme]
|
if params[:scheme]
|
||||||
scheme = params[:scheme]
|
scheme = params[:scheme]
|
||||||
port = params[:port]
|
port = params[:port] || DEFAULT_SCHEME_PORT[scheme]
|
||||||
else
|
else
|
||||||
scheme = @scheme || DEFAULT_SCHEME
|
scheme = @scheme
|
||||||
port = @port
|
port = @port
|
||||||
end
|
end
|
||||||
if DEFAULT_SCHEME_PORT[scheme] == port
|
if DEFAULT_SCHEME_PORT[scheme] == port
|
||||||
|
@ -225,7 +225,7 @@ module Fog
|
||||||
:host => host,
|
:host => host,
|
||||||
:port => port,
|
:port => port,
|
||||||
:path => path,
|
:path => path,
|
||||||
:headers => headers,
|
:headers => headers
|
||||||
})
|
})
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -418,12 +418,10 @@ module Fog
|
||||||
@port = options[:port] || DEFAULT_SCHEME_PORT[@scheme]
|
@port = options[:port] || DEFAULT_SCHEME_PORT[@scheme]
|
||||||
@path_style = options[:path_style] || false
|
@path_style = options[:path_style] || false
|
||||||
end
|
end
|
||||||
|
|
||||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def reload
|
def reload
|
||||||
@connection.reset
|
@connection.reset if @connection
|
||||||
end
|
end
|
||||||
|
|
||||||
def signature(params, expires)
|
def signature(params, expires)
|
||||||
|
@ -493,6 +491,20 @@ DATA
|
||||||
@hmac = Fog::HMAC.new('sha1', @aws_secret_access_key)
|
@hmac = Fog::HMAC.new('sha1', @aws_secret_access_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def connection(scheme, host, port)
|
||||||
|
uri = "#{scheme}://#{host}:#{port}"
|
||||||
|
if @persistent
|
||||||
|
unless uri == @connection_uri
|
||||||
|
@connection_uri = uri
|
||||||
|
reload
|
||||||
|
@connection = nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@connection = nil
|
||||||
|
end
|
||||||
|
@connection ||= Fog::Connection.new(uri, @persistent, @connection_options)
|
||||||
|
end
|
||||||
|
|
||||||
def request(params, &block)
|
def request(params, &block)
|
||||||
refresh_credentials_if_expired
|
refresh_credentials_if_expired
|
||||||
|
|
||||||
|
@ -502,7 +514,9 @@ DATA
|
||||||
signature = signature(params, expires)
|
signature = signature(params, expires)
|
||||||
|
|
||||||
params = request_params(params)
|
params = request_params(params)
|
||||||
params.delete(:port) unless params[:port]
|
scheme = params.delete(:scheme)
|
||||||
|
host = params.delete(:host)
|
||||||
|
port = params.delete(:port) || DEFAULT_SCHEME_PORT[scheme]
|
||||||
|
|
||||||
params[:headers]['Date'] = expires
|
params[:headers]['Date'] = expires
|
||||||
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature}"
|
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature}"
|
||||||
|
@ -510,12 +524,12 @@ DATA
|
||||||
original_params = params.dup
|
original_params = params.dup
|
||||||
|
|
||||||
begin
|
begin
|
||||||
response = @connection.request(params, &block)
|
response = connection(scheme, host, port).request(params, &block)
|
||||||
rescue Excon::Errors::TemporaryRedirect => error
|
rescue Excon::Errors::TemporaryRedirect => error
|
||||||
headers = (error.response.is_a?(Hash) ? error.response[:headers] : error.response.headers)
|
headers = (error.response.is_a?(Hash) ? error.response[:headers] : error.response.headers)
|
||||||
uri = URI.parse(headers['Location'])
|
uri = URI.parse(headers['Location'])
|
||||||
Fog::Logger.warning("fog: followed redirect to #{uri.host}, connecting to the matching region will be more performant")
|
Fog::Logger.warning("fog: followed redirect to #{uri.host}, connecting to the matching region will be more performant")
|
||||||
response = Fog::Connection.new("#{@scheme}://#{uri.host}:#{@port}", false, @connection_options).request(original_params, &block)
|
response = Fog::Connection.new("#{uri.scheme}://#{uri.host}:#{uri.port}", false, @connection_options).request(original_params, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
response
|
response
|
||||||
|
|
Loading…
Reference in a new issue