integ/docker/python-docker/centos/patches/0002-Add-auth_config-to-api.image.inspect_distribution.patch
Thiago Brito 3c49987fba 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
2021-07-07 15:39:05 +00:00

62 lines
2.1 KiB
Diff

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