Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ARM] Fix az resource list cannot use tag when there is a default location #11787

Merged
merged 8 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Release History

* Fix issue #11658: `az group export` command does not support `--query` and `--output` parameters
* Fix issue #10279: The exit code of `az group deployment validate` is 0 when the verification fails
* Fix issue #9916: Improve the error message of the conflict between tag and other filter conditions for `az resource list` command

**IoT Central**

Expand Down
17 changes: 14 additions & 3 deletions src/azure-cli/azure/cli/command_modules/resource/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,20 @@ def _deploy_arm_template_subscription_scope(cli_ctx,
def _list_resources_odata_filter_builder(resource_group_name=None, resource_provider_namespace=None,
resource_type=None, name=None, tag=None, location=None):
"""Build up OData filter string from parameters """
if tag is not None:
if resource_group_name:
raise IncorrectUsageError('you cannot use \'--tag\' with \'--resource-group\''
'(If the default value for resource group is set, please use \'az configure --defaults group=""\' command to clear it first)')
if resource_provider_namespace:
raise IncorrectUsageError('you cannot use \'--tag\' with \'--namespace\'')
if resource_type:
raise IncorrectUsageError('you cannot use \'--tag\' with \'--resource-type\'')
if name:
raise IncorrectUsageError('you cannot use \'--tag\' with \'--name\'')
if location:
raise IncorrectUsageError('you cannot use \'--tag\' with \'--location\''
'(If the default value for location is set, please use \'az configure --defaults location=""\' command to clear it first)')

filters = []

if resource_group_name:
Expand Down Expand Up @@ -537,9 +551,6 @@ def _list_resources_odata_filter_builder(resource_group_name=None, resource_prov
raise CLIError('--namespace also requires --resource-type')

if tag:
if name or location:
raise IncorrectUsageError('you cannot use the tag filter with other filters')

tag_name = list(tag.keys())[0] if isinstance(tag, dict) else tag
tag_value = tag[tag_name] if isinstance(tag, dict) else ''
if tag_name:
Expand Down
Loading