Skip to content

Commit

Permalink
Merge pull request fog#559 from xtoddx/osauth
Browse files Browse the repository at this point in the history
[OpenStack|compute] fix v2.0 auth endpoints
  • Loading branch information
geemus committed Oct 11, 2011
2 parents 1901b68 + e3d4f33 commit 2acb300
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
7 changes: 4 additions & 3 deletions lib/fog/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ def self.authenticate_v2(options, connection_options = {})

response = connection.request({
:expects => [200, 204],
:body => req_body,
:headers => {'Content-Type' => 'application/json'},
:body => MultiJson.encode(req_body),
:host => uri.host,
:method => 'GET',
:method => 'POST',
:path => (uri.path and not uri.path.empty?) ? uri.path : 'v2.0'
})
body=response.body
body=MultiJson.decode(response.body)

if body['auth']['serviceCatalog'] and body['auth']['serviceCatalog'][@compute_service_name] and body['auth']['serviceCatalog'][@compute_service_name][0] then
mgmt_url = body['auth']['serviceCatalog'][@compute_service_name][0]['publicURL']
Expand Down
13 changes: 8 additions & 5 deletions lib/fog/openstack/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module Fog
module Compute
class OpenStack < Fog::Service

requires :openstack_api_key, :openstack_username, :openstack_auth_url, :openstack_tenant
recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_compute_service_name
requires :openstack_api_key, :openstack_username, :openstack_auth_url
recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_compute_service_name, :openstack_tenant

model_path 'fog/openstack/models/compute'
model :flavor
Expand Down Expand Up @@ -167,7 +167,7 @@ def authenticate
:openstack_tenant => @openstack_tenant,
:openstack_compute_service_name => @openstack_compute_service_name
}
if @openstack_auth_url =~ /.*v2.0\/?$/
if @openstack_auth_url =~ /\/v2.0\//
credentials = Fog::OpenStack.authenticate_v2(options, @connection_options)
else
credentials = Fog::OpenStack.authenticate_v1(options, @connection_options)
Expand All @@ -181,8 +181,11 @@ def authenticate
end
@host = uri.host
@path = uri.path
# Force URL into v1.1 namespace (what this binding supports)
@path.sub!(/\/.*\/?/, '/v1.1/')
@path.sub!(/\/$/, '')
unless @path.match(/1\.1/)
raise Fog::Compute::OpenStack::ServiceUnavailable.new(
"OpenStack binding only supports version 1.1")
end
# Add tenant
@path += @openstack_tenant if @openstack_tenant
@port = uri.port
Expand Down

0 comments on commit 2acb300

Please sign in to comment.