mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Allow auth tokens to be shared among connections to rackspace api.
This commit is contained in:
parent
d1dc40cc8e
commit
852ee37f85
1 changed files with 18 additions and 8 deletions
|
@ -4,6 +4,7 @@ module Fog
|
||||||
|
|
||||||
requires :rackspace_api_key, :rackspace_username
|
requires :rackspace_api_key, :rackspace_username
|
||||||
recognizes :rackspace_auth_url, :rackspace_servicenet, :persistent
|
recognizes :rackspace_auth_url, :rackspace_servicenet, :persistent
|
||||||
|
recognizes :rackspace_auth_token, :rackspace_management_url
|
||||||
|
|
||||||
model_path 'fog/compute/models/rackspace'
|
model_path 'fog/compute/models/rackspace'
|
||||||
model :flavor
|
model :flavor
|
||||||
|
@ -78,6 +79,9 @@ module Fog
|
||||||
@rackspace_username = options[:rackspace_username]
|
@rackspace_username = options[:rackspace_username]
|
||||||
@rackspace_auth_url = options[:rackspace_auth_url]
|
@rackspace_auth_url = options[:rackspace_auth_url]
|
||||||
@rackspace_servicenet = options[:rackspace_servicenet]
|
@rackspace_servicenet = options[:rackspace_servicenet]
|
||||||
|
@rackspace_auth_token = options[:rackspace_auth_token]
|
||||||
|
@rackspace_management_url = options[:rackspace_management_url]
|
||||||
|
@rackspace_must_reauthenticate = false
|
||||||
authenticate
|
authenticate
|
||||||
Excon.ssl_verify_peer = false if options[:rackspace_servicenet] == true
|
Excon.ssl_verify_peer = false if options[:rackspace_servicenet] == true
|
||||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
||||||
|
@ -100,6 +104,7 @@ module Fog
|
||||||
}))
|
}))
|
||||||
rescue Excon::Errors::Unauthorized => error
|
rescue Excon::Errors::Unauthorized => error
|
||||||
if JSON.parse(response.body)['unauthorized']['message'] == 'Invalid authentication token. Please renew.'
|
if JSON.parse(response.body)['unauthorized']['message'] == 'Invalid authentication token. Please renew.'
|
||||||
|
@rackspace_must_reauthenticate = true
|
||||||
authenticate
|
authenticate
|
||||||
retry
|
retry
|
||||||
else
|
else
|
||||||
|
@ -122,14 +127,19 @@ module Fog
|
||||||
private
|
private
|
||||||
|
|
||||||
def authenticate
|
def authenticate
|
||||||
options = {
|
if @rackspace_must_reauthenticate or @rackspace_auth_token.empty?
|
||||||
:rackspace_api_key => @rackspace_api_key,
|
options = {
|
||||||
:rackspace_username => @rackspace_username,
|
:rackspace_api_key => @rackspace_api_key,
|
||||||
:rackspace_auth_url => @rackspace_auth_url
|
:rackspace_username => @rackspace_username,
|
||||||
}
|
:rackspace_auth_url => @rackspace_auth_url
|
||||||
credentials = Fog::Rackspace.authenticate(options)
|
}
|
||||||
@auth_token = credentials['X-Auth-Token']
|
credentials = Fog::Rackspace.authenticate(options)
|
||||||
uri = URI.parse(credentials['X-Server-Management-Url'])
|
@auth_token = credentials['X-Auth-Token']
|
||||||
|
uri = URI.parse(credentials['X-Server-Management-Url'])
|
||||||
|
else
|
||||||
|
@auth_token = @rackspace_auth_token
|
||||||
|
uri = URI.parse(@rackspace_management_url)
|
||||||
|
end
|
||||||
@host = @rackspace_servicenet == true ? "snet-#{uri.host}" : uri.host
|
@host = @rackspace_servicenet == true ? "snet-#{uri.host}" : uri.host
|
||||||
@path = uri.path
|
@path = uri.path
|
||||||
@port = uri.port
|
@port = uri.port
|
||||||
|
|
Loading…
Reference in a new issue