Use urlunparse to reconstruct base_url

Using string replace to replace the new path back onto the old path
fails when there is no path setup in the catalog initially. Instead of
this lets use the inverse to the urlparse previously performed.

Change-Id: I931f0c558aafc8dfaa5519744c6e4e7fcffc3205
Closes-Bug: #1552475
This commit is contained in:
Jamie Lennox 2016-03-02 18:33:24 -06:00
parent 22dd1c9d94
commit 823a00433f
1 changed files with 28 additions and 6 deletions

View File

@ -325,13 +325,24 @@ class KeystoneV2AuthProvider(KeystoneAuthProvider):
parts = urlparse.urlparse(_base_url)
if filters.get('api_version', None) is not None:
version_path = '/%s' % filters['api_version']
path = re.sub(r'(^|/)+v\d+(?:\.\d+)?',
'/' + filters['api_version'],
version_path,
parts.path,
count=1)
_base_url = _base_url.replace(parts.path, path)
_base_url = urlparse.urlunparse((parts.scheme,
parts.netloc,
path or version_path,
parts.params,
parts.query,
parts.fragment))
if filters.get('skip_path', None) is not None and parts.path != '':
_base_url = _base_url.replace(parts.path, "/")
_base_url = urlparse.urlunparse((parts.scheme,
parts.netloc,
'/',
parts.params,
parts.query,
parts.fragment))
return _base_url
@ -447,13 +458,24 @@ class KeystoneV3AuthProvider(KeystoneAuthProvider):
parts = urlparse.urlparse(_base_url)
if filters.get('api_version', None) is not None:
version_path = '/%s' % filters['api_version']
path = re.sub(r'(^|/)+v\d+(?:\.\d+)?',
'/' + filters['api_version'],
version_path,
parts.path,
count=1)
_base_url = _base_url.replace(parts.path, path)
_base_url = urlparse.urlunparse((parts.scheme,
parts.netloc,
path or version_path,
parts.params,
parts.query,
parts.fragment))
if filters.get('skip_path', None) is not None:
_base_url = _base_url.replace(parts.path, "/")
_base_url = urlparse.urlunparse((parts.scheme,
parts.netloc,
'/',
parts.params,
parts.query,
parts.fragment))
return _base_url