python-docker: Add auth_config to api.image.inspect_distribution

This is an excerpt from docker-py 4.4.4 needed to check if a given image
exists in an authenticated registry.

Story: 2009305
Task: 43677

Signed-off-by: Jackie Huang <jackie.huang@windriver.com>
Change-Id: Id7de52e3faa79e559d1957bf7a635152b5e775cb
This commit is contained in:
Jackie Huang 2021-11-23 16:32:01 +08:00 committed by Jackie_Huang
parent 638cf9f03d
commit 35ce190b76
2 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,64 @@
From 55dc1d720418c552657160d1165e2be7e0a80069 Mon Sep 17 00:00:00 2001
From: Thiago Brito <thiago.brito@windriver.com>
Date: Tue, 6 Jul 2021 15:41:06 -0300
Subject: [PATCH 2/2] Add auth_config to api.image.inspect_distribution
This is an excerpt from docker-py 4.4.4 needed to check if a given image
exists in an authenticated registry.
Upstream-Status: Backport
Signed-off-by: Thiago Brito <thiago.brito@windriver.com>
Signed-off-by: Jackie Huang <jackie.huang@windriver.com>
---
docker/api/image.py | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/docker/api/image.py b/docker/api/image.py
index 5f05d88..8fc9164 100644
--- a/docker/api/image.py
+++ b/docker/api/image.py
@@ -247,23 +247,35 @@ class ImageApiMixin(object):
@utils.minimum_version('1.30')
@utils.check_resource('image')
- def inspect_distribution(self, image):
+ def inspect_distribution(self, image, auth_config=None):
"""
Get image digest and platform information by contacting the registry.
-
Args:
image (str): The image name to inspect
-
+ auth_config (dict): Override the credentials that are found in the
+ config for this request. ``auth_config`` should contain the
+ ``username`` and ``password`` keys to be valid.
Returns:
(dict): A dict containing distribution data
-
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
+ registry, _ = auth.resolve_repository_name(image)
+
+ headers = {}
+ if auth_config is None:
+ header = auth.get_config_header(self, registry)
+ if header:
+ headers['X-Registry-Auth'] = header
+ else:
+ log.debug('Sending supplied auth config')
+ headers['X-Registry-Auth'] = auth.encode_header(auth_config)
+
+ url = self._url("/distribution/{0}/json", image)
return self._result(
- self._get(self._url("/distribution/{0}/json", image)), True
+ self._get(url, headers=headers), True
)
def load_image(self, data, quiet=None):
--
2.17.1

View File

@ -5,6 +5,10 @@ SECTION = "devel/python"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=34f3846f940453127309b920eeb89660"
SRC_URI += "\
file://0001-Add-auth_config-to-api.image.inspect_distribution.patch \
"
SRC_URI[md5sum] = "660c3c0c3776cb88f34fc549d7c89ed2"
SRC_URI[sha256sum] = "dc5cc0971a0d36fe94c5ce89bd4adb6c892713500af7b0818708229c3199911a"