Skip to content

Commit

Permalink
Simplify manifest fetching by sending all supported types in a single…
Browse files Browse the repository at this point in the history
… request
  • Loading branch information
AdamOlech committed Feb 3, 2023
1 parent c78f8d8 commit 7adb76f
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions dockersave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,22 @@ def get_manifest(image, tag, token, registry_url):
]

supported_manifests = [
'application/vnd.docker.distribution.manifest.v2+json',
'application/vnd.oci.image.manifest.v1+json',
'application/vnd.docker.distribution.manifest.v2+json',
'application/vnd.docker.distribution.manifest.v1+prettyjws',
'application/vnd.docker.distribution.manifest.v1+json',
]

for manifest_type in supported_manifests+supported_fat_manifests:
r = requests.get(
request_url,
headers={
'Authorization':'Bearer {}'.format(token),
'Accept': manifest_type
}
)
r = requests.get(
request_url,
headers={
'Authorization':'Bearer {}'.format(token),
'Accept': ", ".join(supported_manifests+supported_fat_manifests)
}
)

# Image does not exist or unsupported manifest type.
if r.status_code == 404:
continue
elif r.headers["content-type"] in supported_fat_manifests:
return get_manifest(image, r.json()['manifests'][0]["digest"], token, registry_url)
else:
break
if r.headers["content-type"] in supported_fat_manifests:
return get_manifest(image, r.json()['manifests'][0]["digest"], token, registry_url)

r.raise_for_status()
return r
Expand Down

0 comments on commit 7adb76f

Please sign in to comment.