mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace] created auth_token method in service that will return a token defined in the @auth_token variable to the identity service to reduce the chance that token might not be set; improved token tests
This commit is contained in:
parent
88beffdf64
commit
d93d3c350b
7 changed files with 44 additions and 18 deletions
|
@ -106,7 +106,7 @@ module Fog
|
|||
@rackspace_auth_url = options[:rackspace_auth_url]
|
||||
@rackspace_cdn_url = options[:rackspace_cdn_url]
|
||||
@rackspace_region = options[:rackspace_region] || :dfw
|
||||
@auth_token = authenticate(options)
|
||||
authenticate(options)
|
||||
@enabled = false
|
||||
@persistent = options[:persistent] || false
|
||||
|
||||
|
@ -138,7 +138,7 @@ module Fog
|
|||
response = @connection.request(params.merge!({
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Auth-Token' => @auth_token
|
||||
'X-Auth-Token' => auth_token
|
||||
}.merge!(params[:headers] || {}),
|
||||
:host => endpoint_uri.host,
|
||||
:path => "#{endpoint_uri.path}/#{params[:path]}",
|
||||
|
@ -162,7 +162,7 @@ module Fog
|
|||
def authenticate_v1(options)
|
||||
credentials = Fog::Rackspace.authenticate(options, @connection_options)
|
||||
endpoint_uri credentials['X-CDN-Management-Url']
|
||||
credentials['X-Auth-Token']
|
||||
@auth_token = credentials['X-Auth-Token']
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -130,7 +130,7 @@ module Fog
|
|||
response = @connection.request(params.merge!({
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Auth-Token' => @auth_token
|
||||
'X-Auth-Token' => auth_token
|
||||
}.merge!(params[:headers] || {}),
|
||||
:host => @uri.host,
|
||||
:path => "#{endpoint_uri.path}/#{params[:path]}"
|
||||
|
@ -161,7 +161,7 @@ module Fog
|
|||
:rackspace_username => @rackspace_username,
|
||||
:rackspace_auth_url => @rackspace_auth_url
|
||||
}
|
||||
@auth_token = super(options)
|
||||
super(options)
|
||||
end
|
||||
|
||||
def service_name
|
||||
|
@ -189,7 +189,7 @@ module Fog
|
|||
def authenticate_v1(options)
|
||||
credentials = Fog::Rackspace.authenticate(options, @connection_options)
|
||||
setup_endpoint credentials
|
||||
credentials['X-Auth-Token']
|
||||
@auth_token = credentials['X-Auth-Token']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,7 +57,7 @@ module Fog
|
|||
}
|
||||
|
||||
@identity_service = Fog::Rackspace::Identity.new(hash)
|
||||
@identity_service.auth_token
|
||||
@auth_token = @identity_service.auth_token
|
||||
end
|
||||
|
||||
def authenticate_v1(options)
|
||||
|
@ -65,7 +65,11 @@ module Fog
|
|||
end
|
||||
|
||||
def endpoint_uri_v2
|
||||
@auth_token = @identity_service.service_catalog.get_endpoint(service_name, region)
|
||||
@uri = @identity_service.service_catalog.get_endpoint(service_name, region)
|
||||
end
|
||||
|
||||
def auth_token
|
||||
@auth_token || @identity_service.auth_token
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -109,7 +109,7 @@ module Fog
|
|||
@rackspace_must_reauthenticate = false
|
||||
@connection_options = options[:connection_options] || {}
|
||||
|
||||
@auth_token = authenticate
|
||||
authenticate
|
||||
@persistent = options[:persistent] || false
|
||||
Excon.defaults[:ssl_verify_peer] = false if service_net?
|
||||
@connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
|
||||
|
@ -133,7 +133,7 @@ module Fog
|
|||
response = @connection.request(params.merge({
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Auth-Token' => @auth_token
|
||||
'X-Auth-Token' => auth_token
|
||||
}.merge!(params[:headers] || {}),
|
||||
:host => endpoint_uri.host,
|
||||
:path => "#{endpoint_uri.path}/#{params[:path]}",
|
||||
|
@ -171,7 +171,7 @@ module Fog
|
|||
:rackspace_username => @rackspace_username,
|
||||
:rackspace_auth_url => @rackspace_auth_url
|
||||
}
|
||||
@auth_token = super(options)
|
||||
super(options)
|
||||
else
|
||||
@auth_token = @rackspace_auth_token
|
||||
@uri = URI.parse(@rackspace_storage_url)
|
||||
|
@ -197,7 +197,7 @@ module Fog
|
|||
def authenticate_v1(options)
|
||||
credentials = Fog::Rackspace.authenticate(options, @connection_options)
|
||||
endpoint_uri credentials['X-Storage-Url']
|
||||
credentials['X-Auth-Token']
|
||||
@auth_token = credentials['X-Auth-Token']
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -26,13 +26,14 @@ Shindo.tests('Fog::CDN::Rackspace', ['rackspace']) do
|
|||
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
|
||||
|
||||
tests('variables populated') do
|
||||
returns(false, "auth token populated") { @service.instance_variable_get("@auth_token").nil? }
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(false, "path populated") { @service.instance_variable_get("@uri").path.nil? }
|
||||
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
|
||||
end
|
||||
tests('custom endpoint') do
|
||||
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0',
|
||||
:rackspace_cdn_url => 'https://my-custom-cdn-endpoint.com'
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-cdn-endpoint\.com/) != nil }
|
||||
end
|
||||
end
|
||||
|
@ -42,21 +43,24 @@ Shindo.tests('Fog::CDN::Rackspace', ['rackspace']) do
|
|||
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
|
||||
|
||||
tests('variables populated') do
|
||||
returns(false, "auth token populated") { @service.instance_variable_get("@auth_token").nil? }
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(false, "path populated") { @service.instance_variable_get("@uri").path.nil? }
|
||||
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
|
||||
end
|
||||
tests('dfw region') do
|
||||
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :dfw
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /cdn1/) != nil }
|
||||
end
|
||||
tests('ord region') do
|
||||
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :ord
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /cdn2/) != nil }
|
||||
end
|
||||
tests('custom endpoint') do
|
||||
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
|
||||
:rackspace_cdn_url => 'https://my-custom-cdn-endpoint.com'
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-cdn-endpoint\.com/) != nil }
|
||||
end
|
||||
end
|
||||
|
@ -66,16 +70,19 @@ Shindo.tests('Fog::CDN::Rackspace', ['rackspace']) do
|
|||
|
||||
tests('no params') do
|
||||
@service = Fog::CDN::Rackspace.new
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses DFW") { (@service.instance_variable_get("@uri").host =~ /cdn1/) != nil }
|
||||
end
|
||||
|
||||
tests('specify region') do
|
||||
@service = Fog::CDN::Rackspace.new :rackspace_region => :ord
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /cdn2/) != nil }
|
||||
end
|
||||
|
||||
tests('custom endpoint') do
|
||||
@service = Fog::CDN::Rackspace.new :rackspace_cdn_url => 'https://my-custom-cdn-endpoint.com'
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-cdn-endpoint\.com/) != nil }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ Shindo.tests('Fog::Compute::RackspaceV2', ['rackspace']) do
|
|||
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
|
||||
|
||||
tests('variables populated') do
|
||||
returns(false, "auth token populated") { @service.instance_variable_get("@auth_token").nil? }
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(false, "path populated") { @service.instance_variable_get("@uri").path.nil? }
|
||||
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
|
||||
end
|
||||
|
@ -36,6 +36,7 @@ Shindo.tests('Fog::Compute::RackspaceV2', ['rackspace']) do
|
|||
tests('custom endpoint') do
|
||||
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0',
|
||||
:rackspace_compute_url => 'https://my-custom-endpoint.com'
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
|
||||
end
|
||||
end
|
||||
|
@ -45,21 +46,24 @@ Shindo.tests('Fog::Compute::RackspaceV2', ['rackspace']) do
|
|||
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
|
||||
|
||||
tests('variables populated') do
|
||||
returns(false, "auth token populated") { @service.instance_variable_get("@auth_token").nil? }
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(false, "path populated") { @service.instance_variable_get("@uri").host.nil? }
|
||||
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
|
||||
end
|
||||
tests('dfw region') do
|
||||
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :dfw
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
|
||||
end
|
||||
tests('ord region') do
|
||||
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :ord
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/) != nil }
|
||||
end
|
||||
tests('custom endpoint') do
|
||||
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
|
||||
:rackspace_compute_url => 'https://my-custom-endpoint.com'
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
|
||||
end
|
||||
end
|
||||
|
@ -69,14 +73,17 @@ Shindo.tests('Fog::Compute::RackspaceV2', ['rackspace']) do
|
|||
|
||||
tests('no params') do
|
||||
@service = Fog::Compute::RackspaceV2.new
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
|
||||
end
|
||||
tests('specify region') do
|
||||
@service = Fog::Compute::RackspaceV2.new :rackspace_region => :ord
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/ ) != nil }
|
||||
end
|
||||
tests('custom endpoint') do
|
||||
@service = Fog::Compute::RackspaceV2.new :rackspace_compute_url => 'https://my-custom-endpoint.com'
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,13 +26,14 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
|
|||
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
|
||||
|
||||
tests('variables populated') do
|
||||
returns(false, "auth token populated") { @service.instance_variable_get("@auth_token").nil? }
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(false, "path populated") { @service.instance_variable_get("@uri").nil? }
|
||||
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
|
||||
end
|
||||
tests('custom endpoint') do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0',
|
||||
:rackspace_storage_url => 'https://my-custom-endpoint.com'
|
||||
returns(false, "auth token populated") { @service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
|
||||
end
|
||||
end
|
||||
|
@ -42,21 +43,24 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
|
|||
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
|
||||
|
||||
tests('variables populated') do
|
||||
returns(false, "auth token populated") { @service.instance_variable_get("@auth_token").nil? }
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(false, "path populated") { @service.instance_variable_get("@uri").nil? }
|
||||
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
|
||||
end
|
||||
tests('dfw region') do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :dfw
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw\d/) != nil }
|
||||
end
|
||||
tests('ord region') do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :ord
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord\d/) != nil }
|
||||
end
|
||||
tests('custom endpoint') do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
|
||||
:rackspace_storage_url => 'https://my-custom-endpoint.com'
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
|
||||
end
|
||||
end
|
||||
|
@ -66,18 +70,22 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
|
|||
|
||||
tests('no params') do
|
||||
@service = Fog::Storage::Rackspace.new
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw\d/) != nil }
|
||||
end
|
||||
tests('specify region') do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_region => :ord
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord\d/ ) != nil }
|
||||
end
|
||||
tests('custom endpoint') do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_storage_url => 'https://my-custom-endpoint.com'
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
|
||||
end
|
||||
tests('rackspace_servicenet') do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_servicenet => true
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /snet-/) != nil }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue