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

[openstack] Modify authentication process

This commit is contained in:
Philip Mark Deazeta 2012-03-03 21:32:05 +08:00 committed by Nelvin Driz
parent 6ed8588a9f
commit df3c374e33
4 changed files with 28 additions and 20 deletions

View file

@ -65,7 +65,6 @@ module Fog
:token => response.headers['X-Auth-Token'],
:server_management_url => response.headers['X-Server-Management-Url']
}
end
# Keystone Style Auth
@ -74,8 +73,9 @@ module Fog
connection = Fog::Connection.new(uri.to_s, false, connection_options)
@openstack_api_key = options[:openstack_api_key]
@openstack_username = options[:openstack_username]
@openstack_tenant = options[:openstack_tenant] || 'admin'
@compute_service_name = options[:openstack_compute_service_name]
@openstack_tenant = options[:openstack_tenant]
@service_name = options[:openstack_service_name]
@identity_service_name = options[:openstack_identity_service_name]
@endpoint_type = options[:openstack_endpoint_type] || 'publicURL'
req_body= {
@ -90,7 +90,9 @@ module Fog
body = retrieve_tokens_v2(connection, req_body, uri)
svc = body['access']['serviceCatalog'].
detect{|x| @compute_service_name.include?(x['type']) }
detect{|x| @service_name.include?(x['type']) }
identity_svc = body['access']['serviceCatalog'].
detect{|x| @identity_service_name.include?(x['type']) } if @identity_service_name
unless svc
unless @openstack_tenant
@ -100,7 +102,8 @@ module Fog
'X-Auth-Token' => body['access']['token']['id']},
:host => uri.host,
:method => 'GET',
:path => '/v2.0/tenants'
:path => '/v2.0/tenants',
:port => '5000'
})
body = MultiJson.decode(response.body)
@ -113,10 +116,12 @@ module Fog
end
mgmt_url = svc['endpoints'].detect{|x| x[@endpoint_type]}[@endpoint_type]
identity_url = identity_svc['endpoints'].detect{|x| x['publicURL']}['publicURL']
token = body['access']['token']['id']
{ :token => token,
:server_management_url => mgmt_url }
{ :token => token,
:server_management_url => mgmt_url,
:identity_public_endpoint => identity_url }
end
def self.retrieve_tokens_v2(connection, request_body, uri)

View file

@ -8,7 +8,7 @@ module Fog
requires :openstack_api_key, :openstack_username, :openstack_auth_url
recognizes :openstack_auth_token, :openstack_management_url,
:persistent, :openstack_compute_service_name, :openstack_tenant
:persistent, :openstack_service_name, :openstack_tenant
## MODELS
#
@ -197,7 +197,8 @@ module Fog
@openstack_auth_token = options[:openstack_auth_token]
@openstack_management_url = options[:openstack_management_url]
@openstack_must_reauthenticate = false
@openstack_compute_service_name = options[:openstack_compute_service_name] || ['nova', 'compute']
@openstack_service_name = options[:openstack_service_name] || ['nova', 'compute']
@openstack_identity_service_name = options[:openstack_identity_service_name] || 'identity'
@connection_options = options[:connection_options] || {}
@ -205,9 +206,6 @@ module Fog
@persistent = options[:persistent] || false
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
@identity_connection = Fog::Connection.new(
"#{@openstack_auth_uri.scheme}://#{@openstack_auth_uri.host}:#{@openstack_auth_uri.port}",
false, @connection_options)
end
def reload
@ -258,7 +256,8 @@ module Fog
:openstack_username => @openstack_username,
:openstack_auth_uri => @openstack_auth_uri,
:openstack_tenant => @openstack_tenant,
:openstack_compute_service_name => @openstack_compute_service_name
:openstack_service_name => @openstack_service_name,
:openstack_identity_service_name => @openstack_identity_service_name
}
if @openstack_auth_uri.path =~ /\/v2.0\//
@ -268,8 +267,9 @@ module Fog
end
@openstack_must_reauthenticate = false
@auth_token = credentials[:token]
@auth_token = credentials[:token]
@openstack_management_url = credentials[:server_management_url]
@openstack_identity_public_endpoint = credentials[:identity_public_endpoint]
uri = URI.parse(@openstack_management_url)
else
@auth_token = @openstack_auth_token
@ -280,6 +280,9 @@ module Fog
@path, @tenant_id = uri.path.scan(/(\/.*)\/(.*)/).flatten
@port = uri.port
@scheme = uri.scheme
@identity_connection = Fog::Connection.new(
@openstack_identity_public_endpoint,
false, @connection_options)
true
end

View file

@ -7,7 +7,7 @@ module Fog
requires :openstack_api_key, :openstack_username, :openstack_auth_url
recognizes :openstack_auth_token, :openstack_management_url, :persistent,
:openstack_compute_service_name, :openstack_tenant
:openstack_service_name, :openstack_tenant
model_path 'fog/openstack/models/identity'
model :tenant
@ -91,7 +91,7 @@ module Fog
@openstack_auth_token = options[:openstack_auth_token]
@openstack_management_url = options[:openstack_management_url]
@openstack_must_reauthenticate = false
@openstack_compute_service_name = options[:openstack_compute_service_name] || ['identity']
@openstack_service_name = options[:openstack_service_name] || ['identity']
@connection_options = options[:connection_options] || {}
@ -148,7 +148,7 @@ module Fog
:openstack_username => @openstack_username,
:openstack_auth_uri => @openstack_auth_uri,
:openstack_tenant => @openstack_tenant,
:openstack_compute_service_name => @openstack_compute_service_name,
:openstack_service_name => @openstack_service_name,
:openstack_endpoint_type => 'adminURL'
}

View file

@ -7,7 +7,7 @@ module Fog
requires :openstack_api_key, :openstack_username, :openstack_auth_url
recognizes :openstack_auth_token, :openstack_management_url, :persistent,
:openstack_compute_service_name, :openstack_tenant
:openstack_service_name, :openstack_tenant
model_path 'fog/openstack/models/image'
@ -69,7 +69,7 @@ module Fog
@openstack_auth_token = options[:openstack_auth_token]
@openstack_management_url = options[:openstack_management_url]
@openstack_must_reauthenticate = false
@openstack_compute_service_name = options[:openstack_compute_service_name] || ['image']
@openstack_service_name = options[:openstack_service_name] || ['image']
@connection_options = options[:connection_options] || {}
@ -125,7 +125,7 @@ module Fog
:openstack_api_key => @openstack_api_key,
:openstack_username => @openstack_username,
:openstack_auth_uri => @openstack_auth_uri,
:openstack_compute_service_name => @openstack_compute_service_name,
:openstack_service_name => @openstack_service_name,
:openstack_endpoint_type => 'adminURL'
}