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 tag crashed when the parameter --ids passed in is resource group ID #11859

Merged
merged 4 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
2 changes: 1 addition & 1 deletion src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Release History
* Azure Stack: surface commands under the profile of 2019-03-01-hybrid

**ARM**

* Fix issue #10246: `az resource tag` crashes when the parameter `--ids` passed in is resource group ID
* Fix issue #11658: `az group export` command does not support `--query` and `--output` parameters

**IoT Central**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@
az resource tag --tags vmlist=vm1 -g MyResourceGroup -n MyVm --resource-type "Microsoft.Compute/virtualMachines"
- name: Tag a web app with the key 'vmlist' and value 'vm1', using a resource identifier.
text: >
az resource tag --tags vmlist=vm1 --id /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/Microsoft.Web/sites/{WebApp}
az resource tag --tags vmlist=vm1 --ids /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/Microsoft.Web/sites/{WebApp}
- name: Tag a resource. (autogenerated)
text: az resource tag --ids /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/Microsoft.Web/sites/{WebApp} --tags vmlist=vm1
crafted: true
Expand Down
11 changes: 9 additions & 2 deletions src/azure-cli/azure/cli/command_modules/resource/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from azure.cli.core.parser import IncorrectUsageError
from azure.cli.core.util import get_file_json, read_file_content, shell_safe_json_parse, sdk_no_wait
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.cli.core.profiles import ResourceType, get_sdk, get_api_version
from azure.cli.core.profiles import ResourceType, get_sdk, get_api_version, AZURE_API_PROFILES

from azure.cli.command_modules.resource._client_factory import (
_resource_client_factory, _resource_policy_client_factory, _resource_lock_client_factory,
Expand Down Expand Up @@ -2143,7 +2143,7 @@ def tag(self, tags):
# please add the service type that needs to be requested with PATCH type here
# for example: the properties of RecoveryServices/vaults must be filled, and a PUT request that passes back
# to properties will fail due to the lack of properties, so the PATCH type should be used
need_patch_service = ['Microsoft.RecoveryServices/vaults']
need_patch_service = ['Microsoft.RecoveryServices/vaults', 'Microsoft.Resources/resourceGroups']

if resource is not None and resource.type in need_patch_service:
parameters = GenericResource(tags=tags)
Expand Down Expand Up @@ -2269,6 +2269,13 @@ def resolve_api_version(rcf, resource_provider_namespace, parent_resource_path,
@staticmethod
def _resolve_api_version_by_id(rcf, resource_id):
parts = parse_resource_id(resource_id)

if len(parts) == 2 and parts['subscription'] is not None and parts['resource_group'] is not None:
return AZURE_API_PROFILES['latest'][ResourceType.MGMT_RESOURCE_RESOURCES]
jiasli marked this conversation as resolved.
Show resolved Hide resolved

if 'namespace' not in parts:
raise CLIError('The type of value entered by --ids parameter is not supported.')

namespace = parts.get('child_namespace_1', parts['namespace'])
if parts.get('child_type_2'):
parent = (parts['type'] + '/' + parts['name'] + '/' +
Expand Down
Loading