|
22 | 22 | from cliff import lister |
23 | 23 | from cliff import show |
24 | 24 |
|
| 25 | +from keystoneclient.openstack.common.apiclient import exceptions as ksc_exc |
25 | 26 | from openstackclient.common import utils |
26 | 27 |
|
27 | 28 |
|
@@ -347,20 +348,37 @@ def take_action(self, parsed_args): |
347 | 348 | self.log.debug('take_action(%s)', parsed_args) |
348 | 349 | identity_client = self.app.client_manager.identity |
349 | 350 |
|
350 | | - user = utils.find_resource( |
351 | | - identity_client.users, |
352 | | - parsed_args.user, |
353 | | - ) |
| 351 | + info = {} |
| 352 | + try: |
| 353 | + user = utils.find_resource( |
| 354 | + identity_client.users, |
| 355 | + parsed_args.user, |
| 356 | + ) |
| 357 | + info.update(user._info) |
| 358 | + except ksc_exc.Forbidden as e: |
| 359 | + auth_ref = self.app.client_manager.auth_ref |
| 360 | + if ( |
| 361 | + parsed_args.user == auth_ref.user_id or |
| 362 | + parsed_args.user == auth_ref.username |
| 363 | + ): |
| 364 | + # Ask for currently auth'ed project so return it |
| 365 | + info = { |
| 366 | + 'id': auth_ref.user_id, |
| 367 | + 'name': auth_ref.username, |
| 368 | + 'project_id': auth_ref.project_id, |
| 369 | + # True because we don't get this far if it is disabled |
| 370 | + 'enabled': True, |
| 371 | + } |
| 372 | + else: |
| 373 | + raise e |
354 | 374 |
|
355 | | - if 'tenantId' in user._info: |
356 | | - user._info.update( |
357 | | - {'project_id': user._info.pop('tenantId')} |
| 375 | + if 'tenantId' in info: |
| 376 | + info.update( |
| 377 | + {'project_id': info.pop('tenantId')} |
358 | 378 | ) |
359 | | - if 'tenant_id' in user._info: |
360 | | - user._info.update( |
361 | | - {'project_id': user._info.pop('tenant_id')} |
| 379 | + if 'tenant_id' in info: |
| 380 | + info.update( |
| 381 | + {'project_id': info.pop('tenant_id')} |
362 | 382 | ) |
363 | 383 |
|
364 | | - info = {} |
365 | | - info.update(user._info) |
366 | 384 | return zip(*sorted(six.iteritems(info))) |
0 commit comments