Skip to content
Open
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 @@ -13,6 +13,7 @@ Release History
* `az acr task logs`: Align log streaming with the default TLS behavior used by the rest of Azure CLI commands (#33486)
* `az acr run/build`: Align log streaming with the default TLS behavior used by the rest of Azure CLI commands (#33486)
* `az acr login`: Harden binary resolution and credential passing (#33373)
* `az acr network-rule list/add/remove`: Fix `virtualNetworkRules` entries returning `virtualNetworkResourceId` as null and surface the `virtualNetworkSubnetResourceId` field (#33660)

**AKS**

Expand Down
25 changes: 22 additions & 3 deletions src/azure-cli/azure/cli/command_modules/acr/network_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,31 @@ def _update_registry(cli_ctx, resource_group_name, registry_name, update_payload
return response.json()


def _format_virtual_network_rule(rule):
"""Normalize a single virtual network rule from the REST response.

The registry REST API returns the subnet resource ID under the
``virtualNetworkSubnetResourceId`` key (confirmed on both the pinned
``2021-08-01-preview`` and the ``2026-03-01-preview`` API). Older response
shapes used ``id``, so fall back to it for compatibility. Both
``virtualNetworkResourceId`` (kept for backward compatibility) and
``virtualNetworkSubnetResourceId`` are surfaced in the output.
"""
subnet_id = rule.get('virtualNetworkSubnetResourceId') or rule.get('id')
return {
'virtualNetworkResourceId': subnet_id,
'virtualNetworkSubnetResourceId': subnet_id,
'action': rule.get('action', 'Allow'),
}


def _format_registry_response(response):
"""Format the registry REST response for CLI output."""
properties = response.get('properties', {})
network_rule_set = properties.get('networkRuleSet', {})

virtual_network_rules = [
{'virtualNetworkResourceId': rule.get('id'), 'action': rule.get('action', 'Allow')}
_format_virtual_network_rule(rule)
for rule in (network_rule_set.get('virtualNetworkRules') or [])
]
ip_rules = [
Expand Down Expand Up @@ -93,7 +111,7 @@ def acr_network_rule_add(cmd,
if subnet or vnet_name:
virtual_network_rules = list(rules.get('virtualNetworkRules') or [])
subnet_id = _validate_subnet(cmd.cli_ctx, subnet, vnet_name, resource_group_name)
virtual_network_rules.append({'id': subnet_id, 'action': 'Allow'})
virtual_network_rules.append({'virtualNetworkSubnetResourceId': subnet_id, 'action': 'Allow'})
rules['virtualNetworkRules'] = virtual_network_rules

if ip_address:
Expand Down Expand Up @@ -122,7 +140,8 @@ def acr_network_rule_remove(cmd,
virtual_network_rules = list(rules.get('virtualNetworkRules') or [])
subnet_id = _validate_subnet(cmd.cli_ctx, subnet, vnet_name, resource_group_name).lower()
rules['virtualNetworkRules'] = [
x for x in virtual_network_rules if x.get('id', '').lower() != subnet_id
x for x in virtual_network_rules
if (x.get('virtualNetworkSubnetResourceId') or x.get('id') or '').lower() != subnet_id
]

if ip_address:
Expand Down
Loading
Loading