diff --git a/src/acrcache/azext_acrcache/cache.py b/src/acrcache/azext_acrcache/cache.py index d2eb2f89fb3..12ec883c44c 100644 --- a/src/acrcache/azext_acrcache/cache.py +++ b/src/acrcache/azext_acrcache/cache.py @@ -6,11 +6,14 @@ from azure.cli.core.util import user_confirmation +from azure.cli.core.commands.client_factory import get_subscription_id from azure.core.serialization import NULL as AzureCoreNull from azure.cli.command_modules.acr._utils import get_resource_group_name_by_registry_name, get_registry_by_name from .vendored_sdks.containerregistry.v2023_11_01_preview.models._models_py3 import CacheRule, ArtifactSyncScopeFilterProperties, CacheRuleUpdateParameters, ImportSource, ImportImageParameters +CREDENTIAL_SET_RESOURCE_ID_TEMPLATE = '/subscriptions/{sub_id}/resourceGroups/{rg}/providers/Microsoft.ContainerRegistry/registries/{reg_name}/credentialSets/{cred_set_name}' + def _create_kql(starts_with=None, ends_with=None, contains=None): if not starts_with and not ends_with and not contains: return "Tags" @@ -100,10 +103,21 @@ def acr_cache_create(cmd, dry_run=False, yes=False): - registry, rg = get_registry_by_name(cmd.cli_ctx, registry_name, resource_group_name) + rg = get_resource_group_name_by_registry_name(cmd.cli_ctx, registry_name, resource_group_name) + if cred_set: + sub_id = get_subscription_id(cmd.cli_ctx) + # Format the credential set ID using subscription ID, resource group, registry name, and credential set name + cred_set_id = CREDENTIAL_SET_RESOURCE_ID_TEMPLATE.format( + sub_id=sub_id, + rg=rg, + reg_name=registry_name, + cred_set_name=cred_set + ) + else: + cred_set_id = AzureCoreNull sync_str = "Active" if sync else "Inactive" - cred_set_id = AzureCoreNull if not cred_set else f'{registry.id}/credentialSets/{cred_set}' + tag = None if ':' in source_repo: tag = source_repo.split(':')[1]