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.

Test scenario:

- Generated a new build with this change
- Installed the platform without errors
- Installed stx-openstack without errors
- Changed the docker-registry url and called a sm-restart for
sysinv-conductor to force the upgrade-static-images.yml to run
- Log: http://paste.openstack.org/show/807236/

Partial-Bug: #1934397
Signed-off-by: Thiago Brito <thiago.brito@windriver.com>
Change-Id: I35325ea579c53abbfaa96ed8de5417d32aba0578
This commit is contained in:
Thiago Brito 2021-07-06 15:51:21 -03:00 committed by Thiago Paiva Brito
parent 145e0d5756
commit 3c49987fba
2 changed files with 72 additions and 9 deletions

View File

@ -4,32 +4,34 @@ Date: Wed, 7 Aug 2019 15:01:11 -0400
Subject: [PATCH 1/1] Update-spec-include-stx-patches
---
SPECS/python-docker.spec | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
SPECS/python-docker.spec | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/SPECS/python-docker.spec b/SPECS/python-docker.spec
index 92420e3..9a05819 100644
--- a/SPECS/python-docker.spec
+++ b/SPECS/python-docker.spec
@@ -29,6 +29,7 @@ Source0: https://files.pythonhosted.org/packages/source/d/%{srcname}/%{sr
@@ -29,6 +29,8 @@ Source0: https://files.pythonhosted.org/packages/source/d/%{srcname}/%{sr
# work in RHEL. This patch converts those environment markers into simple if
# statements.
Patch1: remove-environment-markers.patch
+Patch2: 0001-Update-client-close-socket.patch
+Patch3: 0002-Add-auth_config-to-api.image.inspect_distribution.patch
BuildArch: noarch
@@ -138,7 +139,9 @@ run containers, manage containers, manage Swarms, etc.
@@ -138,7 +139,10 @@ run containers, manage containers, manage Swarms, etc.
%endif # with_python3
%prep
-%autosetup -n %{srcname}-%{version} -p 1
+%setup -q -n %{srcname}-%{version}
+%patch2 -p1
+%patch3 -p2
+
rm -fr docker.egg-info
%build
--
--
1.8.3.1

View File

@ -0,0 +1,61 @@
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.
Signed-off-by: Thiago Brito <thiago.brito@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