Fix module-list failing with AccessInfoV2 error
Due to recent changes (not sure what) the trove module-list command now fails while trying to determine if the client is being run as an admin user. The error looks like the following: DEBUG (shell:752) 'AccessInfoV2' object has no attribute '__getitem__' Traceback (most recent call last): File "/opt/python-troveclient/python-troveclient/troveclient/shell.py", line 747, in main sys.argv[1:])) File "/opt/python-troveclient/python-troveclient/troveclient/shell.py", line 562, in main args.func(self.cs, args) File "/opt/python-troveclient/python-troveclient/troveclient/v1/shell.py", line 1552, in do_module_list roles = cs.client.auth.auth_ref['user']['roles'] TypeError: 'AccessInfoV2' object has no attribute '__getitem__' ERROR: 'AccessInfoV2' object has no attribute '__getitem__' The code was changed so that it doesn't fail even if the structure of the access object changes. Change-Id: Ib0a7de0b8df359c9ad5a582bbe7afcff56d332f8 Closes-Bug: #1607428
This commit is contained in:
@@ -1548,10 +1548,17 @@ def do_module_list(cs, args):
|
||||
field_list = ['id', 'name', 'type', 'datastore',
|
||||
'datastore_version', 'auto_apply', 'tenant', 'visible']
|
||||
is_admin = False
|
||||
if hasattr(cs.client, 'auth'):
|
||||
roles = cs.client.auth.auth_ref['user']['roles']
|
||||
try:
|
||||
try:
|
||||
roles = cs.client.auth.auth_ref['user']['roles']
|
||||
except TypeError:
|
||||
roles = cs.client.auth.auth_ref._data['access']['user']['roles']
|
||||
role_names = [role['name'] for role in roles]
|
||||
is_admin = 'admin' in role_names
|
||||
except TypeError:
|
||||
pass
|
||||
except AttributeError:
|
||||
pass
|
||||
if not is_admin:
|
||||
field_list = field_list[:-2]
|
||||
utils.print_list(
|
||||
|
Reference in New Issue
Block a user