Skip to content

Commit

Permalink
role-assignment-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
jiasli committed Dec 5, 2024
1 parent f92f723 commit c9a98c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/role/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class PrincipalType(str, Enum):
'JSON description.')

with self.argument_context('role assignment delete') as c:
c.argument('yes', options_list=['--yes', '-y'], action='store_true', help='Continue to delete all assignments under the subscription')
c.argument('yes', options_list=['--yes', '-y'], action='store_true', help='Currently no-op.')

with self.argument_context('role definition') as c:
c.argument('role_definition_id', options_list=['--name', '-n'], help='the role definition name')
Expand Down
17 changes: 9 additions & 8 deletions src/azure-cli/azure/cli/command_modules/role/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

from azure.cli.core.profiles import ResourceType
from azure.cli.core.util import get_file_json, shell_safe_json_parse, is_guid
from azure.cli.core.azclierror import ArgumentUsageError

from ._client_factory import _auth_client_factory, _graph_client_factory
from ._multi_api_adaptor import MultiAPIAdaptor
from ._msgrpah import GraphError, set_object_properties
Expand Down Expand Up @@ -501,7 +503,13 @@ def _get_displayable_name(graph_object):


def delete_role_assignments(cmd, ids=None, assignee=None, role=None, resource_group_name=None,
scope=None, include_inherited=False, yes=None):
scope=None, include_inherited=False,
yes=None): # pylint: disable=unused-argument
# yes is currently a no-op
if not any((ids, assignee, role, resource_group_name, scope)):
raise ArgumentUsageError('Please provide at least one of these arguments: '
'--ids, --assignee, --role, --resource-group, --scope')

factory = _auth_client_factory(cmd.cli_ctx, scope)
assignments_client = factory.role_assignments
definitions_client = factory.role_definitions
Expand All @@ -528,11 +536,6 @@ def delete_role_assignments(cmd, ids=None, assignee=None, role=None, resource_gr
for i in ids:
assignments_client.delete_by_id(i)
return
if not any([ids, assignee, role, resource_group_name, scope, assignee, yes]):
from knack.prompting import prompt_y_n
msg = 'This will delete all role assignments under the subscription. Are you sure?'
if not prompt_y_n(msg, default="n"):
return

scope = _build_role_scope(resource_group_name, scope,
assignments_client._config.subscription_id)
Expand Down Expand Up @@ -895,7 +898,6 @@ def add_permission(client, identifier, api, api_permissions):
try:
access_id, access_type = e.split('=')
except ValueError as ex:
from azure.cli.core.azclierror import ArgumentUsageError
raise ArgumentUsageError('Usage error: Please provide both permission id and type, such as '
'`--api-permissions e1fe6dd8-ba31-4d61-89e7-88639da4683d=Scope`') from ex
resource_access = {
Expand Down Expand Up @@ -1174,7 +1176,6 @@ def create_service_principal_for_rbac(
import time

if role and not scopes or not role and scopes:
from azure.cli.core.azclierror import ArgumentUsageError
raise ArgumentUsageError("Usage error: To create role assignments, specify both --role and --scopes.")

graph_client = _graph_client_factory(cmd.cli_ctx)
Expand Down

0 comments on commit c9a98c5

Please sign in to comment.