simplify endpoint lookups

We only need to check if the endpoint namespace hash contains a uri key in
one place. It makes sense to leave that check in 'uri_from_hash' and
remove it from 'endpoint'. This just makes following the logic a tiny
bit easier and removes redundant code.

Change-Id: Ie8e66ae3ab4204b2e96e8cba68f7294df8bd571b
This commit is contained in:
Darren Birkett
2014-04-09 10:48:37 +01:00
parent adbc887b5e
commit 0ebb6ed364
2 changed files with 8 additions and 11 deletions

View File

@@ -22,17 +22,14 @@
require 'uri'
module ::Openstack # rubocop:disable Documentation
# Shortcut to get the full URI for an endpoint. If the 'uri' key isn't
# set in the endpoint hash, we use the ::Openstack.get_uri_from_mash
# library routine from the openstack-common cookbook to grab a URI object
# and construct the URI object from the endpoint parts.
# Shortcut to get the full URI for an endpoint, and return it as a URI object
# First we get the attribute hash for the endpoint, using endpoint_for().
# Then we call uri_from_hash(). If the hash has a 'uri' key,
# this gets converted to a URI object and returned. If not, a URI object is
# constructed from the endpoint parts in the endpoint hash, and returned
def endpoint(name)
ep = endpoint_for name
if ep && ep['uri']
::URI.parse ::URI.encode(ep['uri'])
elsif ep
uri_from_hash ep
end
ep = endpoint_for(name)
uri_from_hash(ep) if ep
end
# Useful for iterating over the OpenStack endpoints

View File

@@ -35,7 +35,7 @@ module ::Openstack # rubocop:disable Documentation
# 'host' keys are nil).
def uri_from_hash(hash)
if hash['uri']
::URI.parse hash['uri']
::URI.parse ::URI.encode(hash['uri'])
else
host = address hash
return nil unless host