Skip to content

Commit 4048e12

Browse files
AntonioVTCopilot
andcommitted
Fix lint errors and add re.IGNORECASE to identity validation
- Fix trailing whitespace in cache.py and _validators.py - Break long lines to stay under 120 char limit - Add pylint disable for unused-argument on acr_cache_update_get - Add re.IGNORECASE flag to identity resource ID regex match Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 071ed10 commit 4048e12

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

src/azure-cli/azure/cli/command_modules/acr/_validators.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,20 +202,26 @@ def validate_cache_credentials(namespace):
202202

203203
if has_remove_cred_set and (has_identity or has_cred_set):
204204
raise InvalidArgumentValueError(
205-
"Cannot specify --remove-cred-set with other credential options. Use --remove-cred-set alone to remove credentials."
205+
"Cannot specify --remove-cred-set with other credential options. "
206+
"Use --remove-cred-set alone to remove credentials."
206207
)
207-
208+
208209
# Validate identity format if provided
209210
if has_identity:
210-
identity_pattern = r'^/subscriptions/[^/]+/resource[Gg]roups/[^/]+/providers/Microsoft\.ManagedIdentity/userAssignedIdentities/[^/]+$'
211-
212-
if not re.match(identity_pattern, namespace.identity):
211+
identity_pattern = (
212+
r'^/subscriptions/[^/]+/resource[Gg]roups/[^/]+'
213+
r'/providers/Microsoft\.ManagedIdentity'
214+
r'/userAssignedIdentities/[^/]+$'
215+
)
216+
217+
if not re.match(identity_pattern, namespace.identity, re.IGNORECASE):
213218
example_format = USER_ASSIGNED_IDENTITY_RESOURCE_ID_TEMPLATE.format(
214219
sub_id='{subscriptionId}',
215220
rg='{resourceGroupName}',
216221
identity_name='{identityName}'
217222
)
218223
raise InvalidArgumentValueError(
219-
f"The --identity parameter must be a valid ARM resource ID for a user-assigned managed identity. "
224+
f"The --identity parameter must be a valid ARM resource ID "
225+
f"for a user-assigned managed identity. "
220226
f"Format: {example_format}"
221227
)

src/azure-cli/azure/cli/command_modules/acr/cache.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def acr_cache_create(cmd,
6666
identity=None):
6767

6868
rg = get_resource_group_name_by_registry_name(cmd.cli_ctx, registry_name, resource_group_name)
69-
69+
7070
# Handle credential set
7171
if cred_set:
7272
sub_id = get_subscription_id(cmd.cli_ctx)
@@ -79,7 +79,7 @@ def acr_cache_create(cmd,
7979
)
8080
else:
8181
cred_set_id = AzureCoreNull
82-
82+
8383
# Handle identity
8484
identity_properties = None
8585
if identity:
@@ -121,13 +121,16 @@ def acr_cache_update_custom(cmd,
121121
# Check if any update parameters are provided
122122
has_cred_update = cred_set is not None or remove_cred_set
123123
has_identity_update = identity is not None
124-
124+
125125
if not has_cred_update and not has_identity_update:
126-
raise InvalidArgumentValueError("You must provide at least one parameter to update (credential set, identity, or removal flag).")
126+
raise InvalidArgumentValueError(
127+
"You must provide at least one parameter to update "
128+
"(credential set, identity, or removal flag)."
129+
)
127130

128131
# initialize properties if not already set
129132
if instance.properties is None:
130-
instance.properties = CacheRuleUpdateProperties()
133+
instance.properties = CacheRuleUpdateProperties()
131134

132135
# Handle credential set updates
133136
if has_cred_update:
@@ -144,7 +147,7 @@ def acr_cache_update_custom(cmd,
144147
cred_set_name=cred_set
145148
)
146149
instance.properties.credential_set_resource_id = cred_set_id
147-
150+
148151
# Handle identity updates
149152
if has_identity_update and identity:
150153
# Create IdentityProperties with UserAssigned type
@@ -159,7 +162,7 @@ def acr_cache_update_custom(cmd,
159162
return instance
160163

161164

162-
def acr_cache_update_get(cmd):
165+
def acr_cache_update_get(cmd): # pylint: disable=unused-argument
163166
"""Returns an empty CacheRuleUpdateParameters object.
164167
"""
165168

0 commit comments

Comments
 (0)