Skip to content

Commit 0b1d2bc

Browse files
use get_by_id
1 parent b80218e commit 0b1d2bc

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -738,26 +738,21 @@ def is_ampls_scoped_exist(cmd, ampls_resource_id, scoped_resource_id):
738738
# Get the resources client (same as used elsewhere in this file)
739739
resources = get_resources_client(cmd.cli_ctx, subscription_id)
740740

741-
# Use the resources client to list scoped resources
742-
# This is the proper SDK way to make the API call
743-
scoped_resources_list_id = f"{ampls_resource_id}/scopedResources"
744-
745741
try:
746-
# Use the resources client's list method
747-
scoped_resources = resources.list_by_id(scoped_resources_list_id, "2019-10-17-preview")
742+
# Use resources.get_by_id() to get the AMPLS resource with scoped resources
743+
ampls_resource = resources.get_by_id(ampls_resource_id, "2019-10-17-preview")
748744

749-
# Iterate through the scoped resources
750-
for scoped_resource in scoped_resources:
751-
if hasattr(scoped_resource, 'properties') and hasattr(scoped_resource.properties, 'linked_resource_id'):
752-
linked_resource_id = scoped_resource.properties.linked_resource_id
753-
scoped_resource_name = getattr(scoped_resource, 'name', 'unknown')
754-
745+
# Check if the AMPLS has any scoped resources property
746+
if hasattr(ampls_resource, 'properties') and hasattr(ampls_resource.properties, 'scoped_resources'):
747+
scoped_resources = ampls_resource.properties.scoped_resources
748+
749+
for scoped_resource in scoped_resources:
750+
linked_resource_id = scoped_resource.get('linkedResourceId', '')
755751
print(f"DEBUG: Found linked resource: {linked_resource_id}")
756752

757-
# Compare case-insensitively since Azure resource IDs can have case variations
758753
if linked_resource_id.lower() == scoped_resource_id.lower():
759754
print(f"DEBUG: MATCH FOUND!")
760-
logger.info("Resource already scoped in AMPLS. Scoped resource name: %s, LinkedResourceId: %s", scoped_resource_name, linked_resource_id)
755+
logger.info("Resource already scoped in AMPLS. LinkedResourceId: %s", linked_resource_id)
761756
return True
762757

763758
except HttpResponseError as e:

0 commit comments

Comments
 (0)