Skip to content

Commit 1d63a5f

Browse files
committed
assignee_object_id
1 parent f92f723 commit 1d63a5f

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

src/azure-cli/azure/cli/command_modules/role/_params.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,12 @@ def load_arguments(self, _):
312312
c.argument('include_inherited', action='store_true', help='include assignments applied on parent scopes')
313313
c.argument('can_delegate', action='store_true', help='when set, the assignee will be able to create further role assignments to the same role')
314314
c.argument('assignee', help='represent a user, group, or service principal. supported format: object id, user sign-in name, or service principal name')
315-
c.argument('assignee_object_id', help="Use this parameter instead of '--assignee' to bypass Graph API invocation in case of insufficient privileges. "
316-
"This parameter only works with object ids for users, groups, service principals, and "
317-
"managed identities. For managed identities use the principal id. For service principals, "
318-
"use the object id and not the app id.")
315+
c.argument('assignee_object_id',
316+
help="Use this parameter instead of '--assignee' to bypass Microsoft Graph API invocation in case "
317+
"you do not have sufficient privileges or network connections to Microsoft Graph API. "
318+
"This parameter only works with object ids for users, groups, service principals, and "
319+
"managed identities. For managed identities, use the principal id. For service principals, "
320+
"use the object id and not the app id.")
319321
c.argument('ids', nargs='+', help='space-separated role assignment ids')
320322
c.argument('include_classic_administrators', arg_type=get_three_state_flag(),
321323
help='list default role assignments for subscription classic administrators, aka co-admins',

src/azure-cli/azure/cli/command_modules/role/custom.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,14 @@ def _create_role_assignment(cli_ctx, role, assignee, resource_group_name=None, s
212212
condition=condition, condition_version=condition_version)
213213

214214

215-
def list_role_assignments(cmd, assignee=None, role=None, resource_group_name=None,
215+
def list_role_assignments(cmd,
216+
assignee=None, assignee_object_id=None,
217+
role=None, resource_group_name=None,
216218
scope=None, include_inherited=False,
217219
show_all=False, include_groups=False, include_classic_administrators=False):
218-
'''
219-
:param include_groups: include extra assignments to the groups of which the user is a
220-
member(transitively).
221-
'''
220+
# include_groups: include extra assignments to the groups of which the user is a member(transitively).
221+
assignee_object_id = _resolve_assignee(cmd.cli_ctx, assignee, assignee_object_id)
222+
222223
if include_classic_administrators:
223224
logger.warning(CLASSIC_ADMINISTRATOR_WARNING)
224225

@@ -236,7 +237,7 @@ def list_role_assignments(cmd, assignee=None, role=None, resource_group_name=Non
236237
definitions_client._config.subscription_id)
237238

238239
assignments = _search_role_assignments(cmd.cli_ctx, assignments_client, definitions_client,
239-
scope, assignee, role,
240+
scope, assignee_object_id, role,
240241
include_inherited, include_groups)
241242

242243
results = todict(assignments) if assignments else []
@@ -500,8 +501,12 @@ def _get_displayable_name(graph_object):
500501
return graph_object['displayName'] or ''
501502

502503

503-
def delete_role_assignments(cmd, ids=None, assignee=None, role=None, resource_group_name=None,
504+
def delete_role_assignments(cmd, ids=None,
505+
assignee=None, assignee_object_id=None,
506+
role=None, resource_group_name=None,
504507
scope=None, include_inherited=False, yes=None):
508+
assignee_object_id = _resolve_assignee(cmd.cli_ctx, assignee, assignee_object_id)
509+
505510
factory = _auth_client_factory(cmd.cli_ctx, scope)
506511
assignments_client = factory.role_assignments
507512
definitions_client = factory.role_definitions
@@ -548,11 +553,7 @@ def delete_role_assignments(cmd, ids=None, assignee=None, role=None, resource_gr
548553

549554

550555
def _search_role_assignments(cli_ctx, assignments_client, definitions_client,
551-
scope, assignee, role, include_inherited, include_groups):
552-
assignee_object_id = None
553-
if assignee:
554-
assignee_object_id = _resolve_object_id(cli_ctx, assignee, fallback_to_object_id=True)
555-
556+
scope, assignee_object_id, role, include_inherited, include_groups):
556557
# https://learn.microsoft.com/en-us/azure/role-based-access-control/role-assignments-list-rest
557558
# "atScope()" and "principalId eq '{value}'" query cannot be used together (API limitation).
558559
# always use "scope" if provided, so we can get assignments beyond subscription e.g. management groups
@@ -590,6 +591,15 @@ def _search_role_assignments(cli_ctx, assignments_client, definitions_client,
590591
return assignments
591592

592593

594+
def _resolve_assignee(cli_ctx, assignee, assignee_object_id):
595+
if assignee and assignee_object_id:
596+
raise CLIError('Usage error: Please provide only one of --assignee or --assignee-object-id.')
597+
if assignee_object_id:
598+
return assignee_object_id
599+
if assignee:
600+
return _resolve_object_id(cli_ctx, assignee, fallback_to_object_id=True)
601+
602+
593603
def _build_role_scope(resource_group_name, scope, subscription_id):
594604
subscription_scope = '/subscriptions/' + subscription_id
595605
if scope:

0 commit comments

Comments
 (0)