{ACR} az acr check-health: fix check-health command by removing outdated API version gate for CMK check#33117
{ACR} az acr check-health: fix check-health command by removing outdated API version gate for CMK check#33117
Conversation
…ted API version gate for CMK check
|
Validation for Azure CLI Full Test Starting...
Thanks for your contribution! |
|
Validation for Breaking Change Starting...
Thanks for your contribution! |
There was a problem hiding this comment.
Pull request overview
Fixes az acr check-health crashing when supported_api_version(...) attempts to compare a None API version against a version string, by removing the outdated API-version gate around the CMK (customer-managed key) identity validation.
Changes:
- Removed
cmd.supported_api_version(min_api='2020-11-01-preview', ...)gating that crashes when the profile API version isNone. - Made CMK managed-identity validation run unconditionally (but still guarded by presence of encryption/KeyVault properties).
- Removed now-unneeded
ResourceTypeimport.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if registry and registry.encryption and registry.encryption.key_vault_properties: # pylint: disable=too-many-nested-blocks | ||
| client_id = registry.encryption.key_vault_properties.identity |
There was a problem hiding this comment.
After removing the API-version gate, this code path can run under profiles/SDK shapes where the registry model may not define an encryption attribute. Accessing registry.encryption directly would then raise AttributeError and reintroduce a crash in check-health. To make this robust across model versions, use attribute-safe access (e.g., getattr(registry, 'encryption', None) and similar for key_vault_properties) before dereferencing nested properties.
| if registry and registry.encryption and registry.encryption.key_vault_properties: # pylint: disable=too-many-nested-blocks | |
| client_id = registry.encryption.key_vault_properties.identity | |
| encryption = getattr(registry, 'encryption', None) if registry is not None else None | |
| key_vault_properties = getattr(encryption, 'key_vault_properties', None) if encryption is not None else None | |
| if registry and key_vault_properties: # pylint: disable=too-many-nested-blocks | |
| client_id = key_vault_properties.identity |
| for k, v in registry.identity.user_assigned_identities.items(): | ||
| if v.client_id == client_id: | ||
| from azure.core.exceptions import HttpResponseError | ||
| try: | ||
| valid_identity = resolve_identity_client_id(cmd.cli_ctx, k) == client_id | ||
| except HttpResponseError: | ||
| pass |
There was a problem hiding this comment.
Importing HttpResponseError inside the loop is unnecessary repeated work and makes the control flow harder to read. Import it once at function scope (or at least before the loop) and keep the loop focused on the identity resolution logic.
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
Related command
az acr check-healthDescription
PR #33017 set MGMT_CONTAINERREGISTRY's API version to None in the profile, but check_health.py still calls
cmd.supported_api_version(min_api='2020-11-01-preview', resource_type=ResourceType.MGMT_CONTAINERREGISTRY)which tries to compare None against a version string, causing the 'NoneType' object has no attribute 'split' crash.This PR removed the
cmd.supported_api_version(min_api='2020-11-01-preview', ...)check — the 2020-11-01-preview feature (CMK) has been GA for years, so no need to guard itTesting Guide
Before:
After:
History Notes
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.