3737logging .basicConfig (level = logging .INFO , format = "%(levelname)s: %(message)s" )
3838logger = logging .getLogger ("docker-export" )
3939logging .getLogger ("urllib3" ).setLevel (logging .WARNING )
40+ CT_DOCKER_MANIFEST_LIST = "application/vnd.docker.distribution.manifest.list.v2+json"
41+ CT_DOCKER_MANIFEST = "application/vnd.docker.distribution.manifest.v2+json"
42+ CT_OCI_INDEXES = "application/vnd.oci.image.index.v1+json"
43+ CT_OCI_MANIFEST = "application/vnd.oci.image.manifest.v1+json"
44+ CT_OCI_IMAGE_CONFIG = "application/vnd.oci.image.config.v1+json"
45+ CT_OCI_EMPTY = "application/vnd.oci.image.config.v1+json"
46+ CT_OCI_LAYERS = (
47+ "application/vnd.oci.image.layer.v1.tar,application/vnd.oci.image.layer.v1.tar+gzip"
48+ )
4049
4150
4251class ImageNotFoundError (Exception ): ...
@@ -384,7 +393,7 @@ def get_manifests(image: Image, auth: RegistryAuth):
384393 f"/manifests/{ image .reference } " ,
385394 headers = dict (
386395 ** auth .headers ,
387- ** {"Accept" : "application/vnd.docker.distribution.manifest.list.v2+json" },
396+ ** {"Accept" : ", " . join ([ CT_DOCKER_MANIFEST_LIST , CT_OCI_INDEXES ]) },
388397 ),
389398 timeout = REQUEST_TIMEOUT ,
390399 )
@@ -415,13 +424,12 @@ def get_layers_manifest_for(
415424 f"/manifests/{ reference } " ,
416425 headers = dict (
417426 ** auth .headers ,
418- ** {"Accept" : "application/vnd.docker.distribution.manifest.v2+json" },
427+ ** {"Accept" : ", " . join ([ CT_DOCKER_MANIFEST , CT_OCI_MANIFEST ]) },
419428 ),
420429 timeout = REQUEST_TIMEOUT ,
421430 )
422431 if resp .status_code != http .HTTPStatus .OK :
423- raise OSError ("HTTP {resp.status_code}: {resp.reason} -- {resp.text}" )
424-
432+ raise OSError (f"HTTP { resp .status_code } : { resp .reason } -- { resp .text } " )
425433 return resp .json ()
426434
427435
@@ -438,7 +446,7 @@ def get_layers_from_v1_manifest(
438446 )
439447
440448 return {
441- "mediaType" : "application/vnd.docker.distribution.manifest.v2+json" ,
449+ "mediaType" : CT_DOCKER_MANIFEST ,
442450 "schemaVersion" : 2 ,
443451 "config" : {
444452 "mediaType" : "application/vnd.docker.container.image.v1+json" ,
@@ -447,7 +455,7 @@ def get_layers_from_v1_manifest(
447455 },
448456 "layers" : [
449457 {
450- "mediaType" : "application/vnd.docker.distribution.manifest.v2+json" ,
458+ "mediaType" : CT_DOCKER_MANIFEST ,
451459 "digest" : layer ["blobSum" ],
452460 # "size": None,
453461 "platform" : {"architecture" : architecture , "os" : os },
@@ -524,7 +532,7 @@ def download_layer_blob(
524532 f"https://{ image .registry } /v2/{ image .fullname } /blobs/{ layer_digest } " ,
525533 headers = dict (
526534 ** auth .headers ,
527- ** {"Accept" : "application/vnd.docker.distribution.manifest.v2+json" },
535+ ** {"Accept" : CT_DOCKER_MANIFEST },
528536 ),
529537 stream = True ,
530538 timeout = REQUEST_TIMEOUT ,
@@ -536,7 +544,7 @@ def download_layer_blob(
536544 layer ["urls" ][0 ],
537545 headers = dict (
538546 ** auth .headers ,
539- ** {"Accept" : "application/vnd.docker.distribution.manifest.v2+json" },
547+ ** {"Accept" : CT_DOCKER_MANIFEST },
540548 ),
541549 stream = True ,
542550 timeout = REQUEST_TIMEOUT ,
0 commit comments