Skip to content

Commit

Permalink
Support id
Browse files Browse the repository at this point in the history
  • Loading branch information
jiasli committed Dec 30, 2024
1 parent d49dd06 commit c34504d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/azure-cli/azure/cli/command_modules/role/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,8 @@
examples:
- name: Show the 'Reader' role definition.
text: az role definition show --scope /subscriptions/00000000-0000-0000-0000-000000000000 --name acdd72a7-3385-48ef-bd42-f606fba81ae7
- name: Show the 'Reader' role definition with its resource ID.
text: az role definition show --id /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7
"""

helps['role definition update'] = """
Expand Down
6 changes: 6 additions & 0 deletions src/azure-cli/azure/cli/command_modules/role/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ class PrincipalType(str, Enum):

with self.argument_context('role definition') as c:
c.argument('role_definition_id', options_list=['--name', '-n'], help='the role definition name')
c.argument('role_id', options_list=['--id'],
help='The fully qualified role definition ID. Use the format, '
'/subscriptions/{guid}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionId} '
'for subscription level role definitions, or '
'/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionId} '
'for tenant level role definitions.')
c.argument('custom_role_only', arg_type=get_three_state_flag(), help='custom roles only(vs. build-in ones)')
c.argument('role_definition', help="json formatted content which defines the new role.")
c.argument('name', arg_type=name_arg_type, completer=get_role_definition_name_completion_list, help="the role's name")
11 changes: 10 additions & 1 deletion src/azure-cli/azure/cli/command_modules/role/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ def list_role_definitions(cmd, name=None, resource_group_name=None, scope=None,
return _search_role_definitions(cmd.cli_ctx, definitions_client, name, [scope], custom_role_only)


def show_role_definition(cmd, scope, name):
def show_role_definition(cmd, scope=None, name=None, role_id=None):
if not any((scope, name, role_id)):
raise CLIError('Usage error: Provide --scope and --name, or --id')
if not role_id and not (name and scope):
raise CLIError('Usage error: Provide both --scope and --name')

definitions_client = _auth_client_factory(cmd.cli_ctx, scope).role_definitions
# https://learn.microsoft.com/en-us/rest/api/authorization/role-definitions/get-by-id?view=rest-authorization-2022-04-01&tabs=HTTP
if role_id:
return definitions_client.get_by_id(role_id)
# https://learn.microsoft.com/en-us/rest/api/authorization/role-definitions/get?view=rest-authorization-2022-04-01&tabs=HTTP
return definitions_client.get(scope, name)


Expand Down

0 comments on commit c34504d

Please sign in to comment.