Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACR] BREAKING CHANGE: Update manifest list-referrers to comply with RC1 ORAS spec #23132

Merged
merged 9 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acr/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 4 additions & 2 deletions src/azure-cli/azure/cli/command_modules/acr/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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')),
Expand Down
31 changes: 18 additions & 13 deletions src/azure-cli/azure/cli/command_modules/acr/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@
BAD_REPO_FQDN
)

from ._constants import (
REF_KEY
)
logger = get_logger(__name__)

ORDERBY_PARAMS = {
'time_asc': 'timeasc',
'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."
Expand All @@ -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,
Expand All @@ -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
}

Expand All @@ -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,
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down