Kaydet (Commit) b6f6e727 authored tarafından Joffrey F's avatar Joffrey F

Add registry auth header to inspect_distribution requests

Update docstring for auth_config parameter in pull, push, and
inspect_distribution
Signed-off-by: 's avatarJoffrey F <joffrey@docker.com>
üst 28c9100a
...@@ -247,12 +247,15 @@ class ImageApiMixin(object): ...@@ -247,12 +247,15 @@ class ImageApiMixin(object):
@utils.minimum_version('1.30') @utils.minimum_version('1.30')
@utils.check_resource('image') @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. Get image digest and platform information by contacting the registry.
Args: Args:
image (str): The image name to inspect 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: Returns:
(dict): A dict containing distribution data (dict): A dict containing distribution data
...@@ -261,9 +264,21 @@ class ImageApiMixin(object): ...@@ -261,9 +264,21 @@ class ImageApiMixin(object):
:py:class:`docker.errors.APIError` :py:class:`docker.errors.APIError`
If the server returns an error. 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( 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): def load_image(self, data, quiet=None):
...@@ -336,10 +351,9 @@ class ImageApiMixin(object): ...@@ -336,10 +351,9 @@ class ImageApiMixin(object):
tag (str): The tag to pull tag (str): The tag to pull
stream (bool): Stream the output as a generator. Make sure to stream (bool): Stream the output as a generator. Make sure to
consume the generator, otherwise pull might get cancelled. consume the generator, otherwise pull might get cancelled.
auth_config (dict): Override the credentials that auth_config (dict): Override the credentials that are found in the
:py:meth:`~docker.api.daemon.DaemonApiMixin.login` has set for config for this request. ``auth_config`` should contain the
this request. ``auth_config`` should contain the ``username`` ``username`` and ``password`` keys to be valid.
and ``password`` keys to be valid.
decode (bool): Decode the JSON data from the server into dicts. decode (bool): Decode the JSON data from the server into dicts.
Only applies with ``stream=True`` Only applies with ``stream=True``
platform (str): Platform in the format ``os[/arch[/variant]]`` platform (str): Platform in the format ``os[/arch[/variant]]``
...@@ -414,10 +428,9 @@ class ImageApiMixin(object): ...@@ -414,10 +428,9 @@ class ImageApiMixin(object):
repository (str): The repository to push to repository (str): The repository to push to
tag (str): An optional tag to push tag (str): An optional tag to push
stream (bool): Stream the output as a blocking generator stream (bool): Stream the output as a blocking generator
auth_config (dict): Override the credentials that auth_config (dict): Override the credentials that are found in the
:py:meth:`~docker.api.daemon.DaemonApiMixin.login` has set for config for this request. ``auth_config`` should contain the
this request. ``auth_config`` should contain the ``username`` ``username`` and ``password`` keys to be valid.
and ``password`` keys to be valid.
decode (bool): Decode the JSON data from the server into dicts. decode (bool): Decode the JSON data from the server into dicts.
Only applies with ``stream=True`` Only applies with ``stream=True``
......
...@@ -315,22 +315,26 @@ class ImageCollection(Collection): ...@@ -315,22 +315,26 @@ class ImageCollection(Collection):
""" """
return self.prepare_model(self.client.api.inspect_image(name)) return self.prepare_model(self.client.api.inspect_image(name))
def get_registry_data(self, name): def get_registry_data(self, name, auth_config=None):
""" """
Gets the registry data for an image. Gets the registry data for an image.
Args: Args:
name (str): The name of the image. name (str): The name of the image.
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: Returns:
(:py:class:`RegistryData`): The data object. (:py:class:`RegistryData`): The data object.
Raises: Raises:
:py:class:`docker.errors.APIError` :py:class:`docker.errors.APIError`
If the server returns an error. If the server returns an error.
""" """
return RegistryData( return RegistryData(
image_name=name, image_name=name,
attrs=self.client.api.inspect_distribution(name), attrs=self.client.api.inspect_distribution(name, auth_config),
client=self.client, client=self.client,
collection=self, collection=self,
) )
...@@ -404,10 +408,9 @@ class ImageCollection(Collection): ...@@ -404,10 +408,9 @@ class ImageCollection(Collection):
Args: Args:
repository (str): The repository to pull repository (str): The repository to pull
tag (str): The tag to pull tag (str): The tag to pull
auth_config (dict): Override the credentials that auth_config (dict): Override the credentials that are found in the
:py:meth:`~docker.client.DockerClient.login` has set for config for this request. ``auth_config`` should contain the
this request. ``auth_config`` should contain the ``username`` ``username`` and ``password`` keys to be valid.
and ``password`` keys to be valid.
platform (str): Platform in the format ``os[/arch[/variant]]`` platform (str): Platform in the format ``os[/arch[/variant]]``
Returns: Returns:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment