diff --git a/src/azure-cli/azure/cli/command_modules/acr/_constants.py b/src/azure-cli/azure/cli/command_modules/acr/_constants.py index 7f6d69c033c..c1ce1a7a065 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_constants.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_constants.py @@ -30,6 +30,8 @@ ALLOWED_TASK_FILE_TYPES = ('.yaml', '.yml', '.toml', '.json', '.sh', '.bash', '.zsh', '.ps1', '.ps', '.cmd', '.bat', '.ts', '.js', '.php', '.py', '.rb', '.lua') +REF_KEY = "referrers" + def get_classic_sku(cmd): SkuName = cmd.get_models('SkuName') diff --git a/src/azure-cli/azure/cli/command_modules/acr/_format.py b/src/azure-cli/azure/cli/command_modules/acr/_format.py index 0552cecca9e..3ecea58fb06 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_format.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_format.py @@ -6,7 +6,9 @@ from collections import OrderedDict from datetime import datetime from knack.log import get_logger - +from ._constants import ( + REF_KEY +) logger = get_logger(__name__) @@ -132,7 +134,7 @@ def connected_registry_list_output_format(result): def list_referrers_output_format(result): manifests = [] - for manifest in result['references']: + for manifest in result[REF_KEY]: manifests.append(OrderedDict([ ('Digest', _get_value(manifest, 'digest')), ('ArtifactType', _get_value(manifest, 'artifactType')), diff --git a/src/azure-cli/azure/cli/command_modules/acr/manifest.py b/src/azure-cli/azure/cli/command_modules/acr/manifest.py index e3a6a78fb88..23eb4333fd6 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/manifest.py +++ b/src/azure-cli/azure/cli/command_modules/acr/manifest.py @@ -32,6 +32,9 @@ BAD_REPO_FQDN ) +from ._constants import ( + REF_KEY +) logger = get_logger(__name__) ORDERBY_PARAMS = { @@ -39,7 +42,6 @@ 'time_desc': 'timedesc' } DEFAULT_PAGINATION = 100 - BAD_ARGS_ERROR_REPO = "You must provide either a fully qualified repository specifier such as"\ " 'MyRegistry.azurecr.io/hello-world' as a positional parameter or"\ " provide '-r MyRegistry -n hello-world' argument values." @@ -52,8 +54,8 @@ def _get_v2_manifest_path(repository, manifest): return '/v2/{}/manifests/{}'.format(repository, manifest) -def _get_referrers_path(repository, manifest): - return '/oras/artifacts/v1/{}/manifests/{}/referrers'.format(repository, manifest) +def _get_referrers_path(repository): + return '/v2/{}/_oras/artifacts/referrers'.format(repository) def _obtain_manifest_from_registry(login_server, @@ -78,12 +80,14 @@ def _obtain_referrers_from_registry(login_server, path, username, password, + digest, artifact_type=None): - result_list = {'references': []} + result_list = {REF_KEY: []} execute_next_http_call = True params = { + 'digest': digest, 'artifactType': artifact_type } @@ -100,7 +104,7 @@ def _obtain_referrers_from_registry(login_server, params=params) if result: - result_list['references'].extend(result['references']) + result_list[REF_KEY].extend(result[REF_KEY]) if next_link: # The registry is telling us there's more items in the list, @@ -268,22 +272,23 @@ def acr_manifest_list_referrers(cmd, raw_result = _obtain_referrers_from_registry( login_server=login_server, - path=_get_referrers_path(repository, manifest), + path=_get_referrers_path(repository), username=username, password=password, - artifact_type=artifact_type) + artifact_type=artifact_type, + digest=manifest) - ref_key = "references" if recursive: - for referrers_obj in raw_result[ref_key]: + for referrers_obj in raw_result[REF_KEY]: internal_referrers_obj = _obtain_referrers_from_registry( login_server=login_server, - path=_get_referrers_path(repository, referrers_obj["digest"]), + path=_get_referrers_path(repository), username=username, - password=password) + password=password, + digest=referrers_obj["digest"]) - for ref in internal_referrers_obj[ref_key]: - raw_result[ref_key].append(ref) + for ref in internal_referrers_obj[REF_KEY]: + raw_result[REF_KEY].append(ref) return raw_result diff --git a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py index 77a9114ae3d..ceb641fd6f5 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py +++ b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py @@ -551,9 +551,12 @@ def test_manifest_list_referrers(self, mock_requests_get, mock_get_manifest_dige manifest_spec='testrepository:testtag') mock_requests_get.assert_called_with( method='get', - url='https://testregistry.azurecr.io/oras/artifacts/v1/testrepository/manifests/sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7/referrers', + url='https://testregistry.azurecr.io/v2/testrepository/_oras/artifacts/referrers', headers=get_authorization_header('username', 'password'), - params={'artifactType': None}, + params={ + 'digest': 'sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7', + 'artifactType': None + }, json=None, timeout=300, verify=mock.ANY) @@ -564,9 +567,12 @@ def test_manifest_list_referrers(self, mock_requests_get, mock_get_manifest_dige manifest_spec='testrepository@sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7') mock_requests_get.assert_called_with( method='get', - url='https://testregistry.azurecr.io/oras/artifacts/v1/testrepository/manifests/sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7/referrers', + url='https://testregistry.azurecr.io/v2/testrepository/_oras/artifacts/referrers', headers=get_authorization_header('username', 'password'), - params={'artifactType': None}, + params={ + 'digest': 'sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7', + 'artifactType': None + }, json=None, timeout=300, verify=mock.ANY) @@ -577,9 +583,12 @@ def test_manifest_list_referrers(self, mock_requests_get, mock_get_manifest_dige artifact_type='sbom/example') mock_requests_get.assert_called_with( method='get', - url='https://testregistry.azurecr.io/oras/artifacts/v1/testrepository/manifests/sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7/referrers', + url='https://testregistry.azurecr.io/v2/testrepository/_oras/artifacts/referrers', headers=get_authorization_header('username', 'password'), - params={'artifactType': 'sbom/example'}, + params={ + 'digest': 'sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7', + 'artifactType': 'sbom/example' + }, json=None, timeout=300, verify=mock.ANY)