diff options
author | Steven Pisarski <s.pisarski@cablelabs.com> | 2017-08-09 20:23:13 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-08-09 20:23:13 +0000 |
commit | 430905e7f76e4a074167a49ca2bfbf727eebcefd (patch) | |
tree | 70d7fd725de448b9f1ab9ac51811062d600dbe45 /snaps/openstack/os_credentials.py | |
parent | adefc2a958feaac406f0ac9a775bca87f488514b (diff) | |
parent | ce19be8891ef3f3e24800924a40f4480dec24bec (diff) |
Merge "Reformat auth_url based on the ID API version."
Diffstat (limited to 'snaps/openstack/os_credentials.py')
-rw-r--r-- | snaps/openstack/os_credentials.py | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/snaps/openstack/os_credentials.py b/snaps/openstack/os_credentials.py index d612e05..bb68215 100644 --- a/snaps/openstack/os_credentials.py +++ b/snaps/openstack/os_credentials.py @@ -128,13 +128,34 @@ class OSCreds: raise OSCredsError('username, password, auth_url, and project_name' ' are required') - auth_url_tokens = self.auth_url.split('/') + self.auth_url = self.__scrub_auth_url() + + def __scrub_auth_url(self): + """ + As the Python APIs are have more stringent requirements around how the + auth_url is formed than the CLI, this method will scrub any version + from the end of + :return: + """ + auth_url_tokens = self.auth_url.rstrip('/').split('/') last_token = auth_url_tokens[len(auth_url_tokens) - 1] - if len(last_token) == 0: - last_token = auth_url_tokens[len(auth_url_tokens) - 2] + token_iters = len(auth_url_tokens) + if last_token.startswith('v'): + token_iters -= 1 + if self.identity_api_version == keystone_utils.V2_VERSION_NUM: + last_token = keystone_utils.V2_VERSION_STR + else: + last_token = 'v' + str(int(self.identity_api_version)) + + new_url = None + for ctr in range(0, token_iters): + if new_url: + new_url += '/' + auth_url_tokens[ctr] + else: + new_url = auth_url_tokens[ctr] + new_url += '/' + last_token - if not last_token.startswith('v'): - raise OSCredsError('auth_url last toke must start with \'v\'') + return new_url @property def __str__(self): |