@@ -234,7 +234,8 @@ def _create_role_assignment(cli_ctx, role, assignee, resource_group_name=None, s
234234
235235def list_role_assignments (cmd , assignee = None , role = None , resource_group_name = None ,
236236 scope = None , include_inherited = False ,
237- show_all = False , include_groups = False , include_classic_administrators = False ):
237+ show_all = False , include_groups = False , include_classic_administrators = False ,
238+ fill_principal_name = True ):
238239 '''
239240 :param include_groups: include extra assignments to the groups of which the user is a
240241 member(transitively).
@@ -282,22 +283,23 @@ def list_role_assignments(cmd, assignee=None, role=None, resource_group_name=Non
282283 i ['roleDefinitionName' ] = None # the role definition might have been deleted
283284
284285 # fill in principal names
285- principal_ids = set (worker .get_role_property (i , 'principalId' )
286- for i in results if worker .get_role_property (i , 'principalId' ))
286+ if fill_principal_name :
287+ principal_ids = set (worker .get_role_property (i , 'principalId' )
288+ for i in results if worker .get_role_property (i , 'principalId' ))
287289
288- if principal_ids :
289- try :
290- principals = _get_object_stubs (graph_client , principal_ids )
291- principal_dics = {i [ID ]: _get_displayable_name (i ) for i in principals }
292-
293- for i in [r for r in results if not r .get ('principalName' )]:
294- i ['principalName' ] = ''
295- if principal_dics .get (worker .get_role_property (i , 'principalId' )):
296- worker .set_role_property (i , 'principalName' ,
297- principal_dics [worker .get_role_property (i , 'principalId' )])
298- except (HttpResponseError , GraphError ) as ex :
299- # failure on resolving principal due to graph permission should not fail the whole thing
300- logger .info ("Failed to resolve graph object information per error '%s'" , ex )
290+ if principal_ids :
291+ try :
292+ principals = _get_object_stubs (graph_client , principal_ids )
293+ principal_dics = {i [ID ]: _get_displayable_name (i ) for i in principals }
294+
295+ for i in [r for r in results if not r .get ('principalName' )]:
296+ i ['principalName' ] = ''
297+ if principal_dics .get (worker .get_role_property (i , 'principalId' )):
298+ worker .set_role_property (i , 'principalName' ,
299+ principal_dics [worker .get_role_property (i , 'principalId' )])
300+ except (HttpResponseError , GraphError ) as ex :
301+ # failure on resolving principal due to graph permission should not fail the whole thing
302+ logger .info ("Failed to resolve graph object information per error '%s'" , ex )
301303
302304 for r in results :
303305 if not r .get ('additionalProperties' ): # remove the useless "additionalProperties"
0 commit comments