diff options
author | Masanori Itoh <itoumsn@nttdata.co.jp> | 2011-05-09 22:06:38 +0000 |
---|---|---|
committer | Tarmac <> | 2011-05-09 22:06:38 +0000 |
commit | 21f18f77e7d729107742fa9157b531ce56f3272a (patch) | |
tree | 6dd216b080221b643584d95e5f03a89eaf4e7b06 /nova/utils.py | |
parent | 6f547c6977d3a200f3799067c68dafd24144be0d (diff) | |
parent | d65d689539b1219e5107ba332a5d3569937aeb1f (diff) | |
download | nova-21f18f77e7d729107742fa9157b531ce56f3272a.tar.gz nova-21f18f77e7d729107742fa9157b531ce56f3272a.tar.xz nova-21f18f77e7d729107742fa9157b531ce56f3272a.zip |
Enable RightAWS style signature checking using server_string without port number, add test cases for authenticate() and a new helper routine, and fix lp753660.
Diffstat (limited to 'nova/utils.py')
-rw-r--r-- | nova/utils.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py index bfcf79216..80bf1197f 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -709,3 +709,33 @@ def check_isinstance(obj, cls): raise Exception(_('Expected object of type: %s') % (str(cls))) # TODO(justinsb): Can we make this better?? return cls() # Ugly PyLint hack + + +def parse_server_string(server_str): + """ + Parses the given server_string and returns a list of host and port. + If it's not a combination of host part and port, the port element + is a null string. If the input is invalid expression, return a null + list. + """ + try: + # First of all, exclude pure IPv6 address (w/o port). + if netaddr.valid_ipv6(server_str): + return (server_str, '') + + # Next, check if this is IPv6 address with a port number combination. + if server_str.find("]:") != -1: + (address, port) = server_str.replace('[', '', 1).split(']:') + return (address, port) + + # Third, check if this is a combination of an address and a port + if server_str.find(':') == -1: + return (server_str, '') + + # This must be a combination of an address and a port + (address, port) = server_str.split(':') + return (address, port) + + except: + LOG.debug(_('Invalid server_string: %s' % server_str)) + return ('', '') |