1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Allow v1 auth for OpenStack

This commit is contained in:
Yauheni Kryudziuk 2013-08-15 08:48:13 +02:00
parent a86ae31029
commit 3ae372d847
3 changed files with 40 additions and 9 deletions

View file

@ -49,6 +49,15 @@ module Fog
service(:volume, 'openstack/volume', 'Volume')
service(:metering, 'openstack/metering', 'Metering')
def self.authenticate(options, connection_options = {})
case options[:openstack_auth_uri].path
when /v1(\.\d+)?/
authenticate_v1(options, connection_options)
else
authenticate_v2(options, connection_options)
end
end
# legacy v1.0 style auth
def self.authenticate_v1(options, connection_options = {})
uri = options[:openstack_auth_uri]
@ -69,7 +78,7 @@ module Fog
return {
:token => response.headers['X-Auth-Token'],
:server_management_url => response.headers['X-Server-Management-Url'],
:server_management_url => response.headers['X-Server-Management-Url'] || response.headers['X-Storage-Url'],
:identity_public_endpoint => response.headers['X-Keystone']
}
end

View file

@ -188,7 +188,7 @@ module Fog
:openstack_endpoint_type => 'publicURL'
}
credentials = Fog::OpenStack.authenticate_v2(options, @connection_options)
credentials = Fog::OpenStack.authenticate(options, @connection_options)
@current_user = credentials[:user]
@current_tenant = credentials[:tenant]

View file

@ -134,6 +134,28 @@ Shindo.tests('OpenStack | authenticate', ['openstack']) do
end
tests("legacy v1 auth") do
headers = {
"X-Storage-Url" => "https://swift.myhost.com/v1/AUTH_tenant",
"X-Auth-Token" => "AUTH_yui193bdc00c1c46c5858788yuio0e1e2p",
"X-Trans-Id" => "iu99nm9999f9b999c9b999dad9cd999e99",
"Content-Length" => "0",
"Date" => "Wed, 07 Aug 2013 11:11:11 GMT"
}
Excon.stub({:method => 'GET', :path => "/auth/v1.0"},
{:status => 200, :body => "", :headers => headers})
returns("https://swift.myhost.com/v1/AUTH_tenant") do
Fog::OpenStack.authenticate_v1(
:openstack_auth_uri => URI('https://swift.myhost.com/auth/v1.0'),
:openstack_username => 'tenant:dev',
:openstack_api_key => 'secret_key',
:openstack_service_type => %w[storage])[:server_management_url]
end
end
ensure
Excon.stubs.clear
Excon.defaults[:mock] = @old_mock_value