Skip to content

[Role] az role assignment delete: If --ids is provided, ignore other arguments, instead of raising error - #24362

Merged
Jiashuo Li (jiasli) merged 4 commits into
Azure:devfrom
jiasli:assignment-delete
Oct 27, 2022
Merged

Jiashuo Li (jiasli) merged 4 commits into
Azure:devfrom
jiasli:assignment-delete

Conversation

@jiasli

Copy link
Copy Markdown
Contributor

Fix IcM 341728422

Related command
az role assignment delete

Description
If defaults.group config option is set via:

az config set defaults.group=testrg

az role assignment delete --ids fails:

> az role assignment delete --ids /subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/providers/Microsoft.Authorization/roleAssignments/54df05ac-c9d3-4b71-a005-dec43d813f87
When assignment ids are used, other parameter values are not required

Root Cause
This command disallows using --ids with other arguments:

if ids:
if assignee or role or resource_group_name or scope or include_inherited:
raise CLIError('When assignment ids are used, other parameter values are not required')

Argument resource_group_name is registered at

c.argument('resource_group_name', resource_group_name_type)

resource_group_name_type has a configured_default:

When defaults.group config option is set, resource_group_name variable will be populated, causing this failure.

Proposed solution
Removing the configured default value for --resource-group in az role assignment delete will be a BREAKING CHANGE and will break customers who rely on --resource-group's configured default value.

Therefore, this PR changes the behavior so that if --ids is provided, it ignores other arguments, instead of raising error.

Testing Guide

az role assignment delete --ids {id} --assignee test --role test --resource-group test --scope test --include-inherit

@ghost
ghost requested a review from Yong Zhang (yonzhan) October 24, 2022 08:04
@ghost ghost added the Auto-Assign Auto assign by bot label Oct 24, 2022
@ghost ghost added this to the Nov 2022 (2022-12-06) milestone Oct 24, 2022
@ghost ghost added the RBAC az role label Oct 24, 2022
@ghost ghost added the Portal az portal label Oct 24, 2022
Comment on lines +343 to +344
self.cmd('role assignment delete --ids {id} '
'--assignee test --role test --resource-group test --scope test --include-inherit')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will refine the test after #24324 is merged.

Comment on lines +498 to +502
ids_override_args = ['assignee', 'role', 'resource_group_name', 'scope', 'include_inherited']
for arg in ids_override_args:
if locals()[arg]:
logger.warning("option '%s' will be ignored due to use of '--ids'.",
cmd.arguments[arg].type.settings['options_list'][0])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mimics the behavior of core for --ids handling:

for _, data in other_values.items():
if data['value'] and not getattr(data['value'], 'is_default', None):
logger.warning("option '%s' will be ignored due to use of '--ids'.",
data['arg'].type.settings['options_list'][0])

A difference is that core doesn't show warning if default value is used, but we do here. I feel being explicit is better than being implicit.

@yonzhan

Copy link
Copy Markdown
Collaborator

Role

@jiasli
Jiashuo Li (jiasli) merged commit e14c60f into Azure:dev Oct 27, 2022
@jiasli
Jiashuo Li (jiasli) deleted the assignment-delete branch December 8, 2022 08:29
avgale pushed a commit to avgale/azure-cli that referenced this pull request Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot Portal az portal RBAC az role

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants