Skip to content

Commit

Permalink
[openstack] Re-record VCRs, plus some light refactoring
Browse files Browse the repository at this point in the history
Also, the bug in webmock 1.22.1 is now fixed, so enforce webmock  1.22.2 or higher
  • Loading branch information
dhague committed Oct 29, 2015
1 parent 64c8a5e commit 4d52870
Show file tree
Hide file tree
Showing 35 changed files with 4,649 additions and 3,879 deletions.
2 changes: 1 addition & 1 deletion fog.gemspec
Expand Up @@ -93,7 +93,7 @@ Gem::Specification.new do |s|
s.add_development_dependency("rspec-core")
s.add_development_dependency("rspec-expectations")
s.add_development_dependency("vcr")
s.add_development_dependency("webmock")
s.add_development_dependency("webmock","~>1.22.2")

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {spec,tests}/*`.split("\n")
Expand Down
20 changes: 9 additions & 11 deletions lib/fog/openstack/core.rb
Expand Up @@ -154,17 +154,16 @@ def authenticate
@port = @openstack_management_uri.port
@scheme = @openstack_management_uri.scheme

# Not all implementations have identity service in the catalog
if @openstack_identity_public_endpoint || @openstack_management_url
@identity_connection = Fog::Core::Connection.new(
@openstack_identity_public_endpoint || @openstack_management_url,
false, @connection_options)
end

true
end
end

@@token_cache = {}

def self.clear_token_cache
@@token_cache.clear
end

def self.authenticate(options, connection_options = {})
case options[:openstack_auth_uri].path
when /v1(\.\d+)?/
Expand Down Expand Up @@ -410,7 +409,7 @@ def self.retrieve_tokens_v2(options, connection_options = {})
auth_token = options[:openstack_auth_token] || options[:unscoped_token]
uri = options[:openstack_auth_uri]

connection = Fog::Core::Connection.new(uri.to_s, false, connection_options)
@identity_connection = Fog::Core::Connection.new(uri.to_s, false, connection_options)

This comment has been minimized.

Copy link
@dLobatog

dLobatog Nov 18, 2015

Contributor

Instance variables should not be created within class methods like this one. It was fine where it was before. Now calls like this one https://github.com/fog/fog/blob/master/lib/fog/openstack/requests/compute/list_tenants.rb are not possible to make.

This comment has been minimized.

Copy link
@dhague

dhague Nov 26, 2015

Author Contributor

Good catch - thanks. I'll fix this later today.

(Sorry for the late reply, BTW)

request_body = {:auth => Hash.new}

if auth_token
Expand All @@ -425,7 +424,7 @@ def self.retrieve_tokens_v2(options, connection_options = {})
end
request_body[:auth][:tenantName] = tenant_name if tenant_name

response = connection.request({
response = @identity_connection.request({
:expects => [200, 204],
:headers => {'Content-Type' => 'application/json'},
:body => Fog::JSON.encode(request_body),
Expand Down Expand Up @@ -506,15 +505,14 @@ def self.retrieve_tokens_v3(options, connection_options = {})

path = (uri.path and not uri.path.empty?) ? uri.path : 'v3'

@@token_cache ||= {}
response, expires = @@token_cache[{body: request_body, path: path}]

unless response && expires > Time.now
response = connection.request({ :expects => [201],
:headers => {'Content-Type' => 'application/json'},
:body => Fog::JSON.encode(request_body),
:method => 'POST',
:path => (uri.path and not uri.path.empty?) ? uri.path : 'v3'
:path => path
})
@@token_cache[{body: request_body, path: path}] = response, Time.now + 30 # 30-second TTL, enough for most requests
end
Expand Down
36 changes: 18 additions & 18 deletions spec/fog/openstack/identity_v3/authv3_a.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 18 additions & 18 deletions spec/fog/openstack/identity_v3/authv3_b.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4d52870

Please sign in to comment.