summaryrefslogtreecommitdiff
path: root/glanceclient/shell.py
diff options
context:
space:
mode:
authorFlavio Percoco <flaper87@gmail.com>2015-09-02 14:58:59 +0200
committerFlavio Percoco <flaper87@gmail.com>2015-09-04 13:31:55 +0200
commit1322fbc5d8323ff605c8b399fe0e1cb904b44f4e (patch)
tree573086673e60fad34f2dc52137fc93e80569bc3a /glanceclient/shell.py
parent47423ebbb2dfcb0d63aefcb87a9bec85420a7a99 (diff)
downloadpython-glanceclient-1322fbc5d8323ff605c8b399fe0e1cb904b44f4e.tar.gz
Consider `--os-token` when using v2
The `_cache_schemas` call currently forces authentication even when the `auth_token` and `os_image_url` are passed. Instead of handling forced authentications, let the client use the passed arguments and authenticate only once if needed. This was not caught by the existing tests because the call to `_cache_schemas` was mocked. Change-Id: I93cec9a68cafc0992d14dab38114d03e25f1e5da Closes-bug: #1490462
Diffstat (limited to 'glanceclient/shell.py')
-rwxr-xr-xglanceclient/shell.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/glanceclient/shell.py b/glanceclient/shell.py
index 0c134a4..3c1aaf2 100755
--- a/glanceclient/shell.py
+++ b/glanceclient/shell.py
@@ -442,12 +442,13 @@ class OpenStackImagesShell(object):
ks_session.auth = auth
return ks_session
- def _get_endpoint_and_token(self, args, force_auth=False):
+ def _get_endpoint_and_token(self, args):
image_url = self._get_image_url(args)
auth_token = args.os_auth_token
- auth_reqd = force_auth or (utils.is_authentication_required(args.func)
- and not (auth_token and image_url))
+ auth_reqd = (not (auth_token and image_url) or
+ (hasattr(args, 'func') and
+ utils.is_authentication_required(args.func)))
if not auth_reqd:
endpoint = image_url
@@ -537,9 +538,8 @@ class OpenStackImagesShell(object):
return endpoint, token
- def _get_versioned_client(self, api_version, args, force_auth=False):
- endpoint, token = self._get_endpoint_and_token(args,
- force_auth=force_auth)
+ def _get_versioned_client(self, api_version, args):
+ endpoint, token = self._get_endpoint_and_token(args)
kwargs = {
'token': token,
@@ -621,8 +621,7 @@ class OpenStackImagesShell(object):
if not options.os_image_api_version and api_version == 2:
switch_version = True
- client = self._get_versioned_client('2', options,
- force_auth=True)
+ client = self._get_versioned_client('2', options)
resp, body = client.http_client.get('/versions')
@@ -690,8 +689,7 @@ class OpenStackImagesShell(object):
if profile:
osprofiler_profiler.init(options.profile)
- client = self._get_versioned_client(api_version, args,
- force_auth=False)
+ client = self._get_versioned_client(api_version, args)
try:
args.func(client, args)