Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions docker/api/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,15 @@ def inspect_image(self, image):

@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
Expand All @@ -261,9 +264,21 @@ def inspect_distribution(self, image):
: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):
Expand Down Expand Up @@ -336,10 +351,9 @@ def pull(self, repository, tag=None, stream=False, auth_config=None,
tag (str): The tag to pull
stream (bool): Stream the output as a generator. Make sure to
consume the generator, otherwise pull might get cancelled.
auth_config (dict): Override the credentials that
:py:meth:`~docker.api.daemon.DaemonApiMixin.login` has set for
this request. ``auth_config`` should contain the ``username``
and ``password`` keys to be valid.
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.
decode (bool): Decode the JSON data from the server into dicts.
Only applies with ``stream=True``
platform (str): Platform in the format ``os[/arch[/variant]]``
Expand Down Expand Up @@ -414,10 +428,9 @@ def push(self, repository, tag=None, stream=False, auth_config=None,
repository (str): The repository to push to
tag (str): An optional tag to push
stream (bool): Stream the output as a blocking generator
auth_config (dict): Override the credentials that
:py:meth:`~docker.api.daemon.DaemonApiMixin.login` has set for
this request. ``auth_config`` should contain the ``username``
and ``password`` keys to be valid.
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.
decode (bool): Decode the JSON data from the server into dicts.
Only applies with ``stream=True``

Expand Down
15 changes: 9 additions & 6 deletions docker/models/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,26 @@ def get(self, 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.

Args:
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:
(:py:class:`RegistryData`): The data object.

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
return RegistryData(
image_name=name,
attrs=self.client.api.inspect_distribution(name),
attrs=self.client.api.inspect_distribution(name, auth_config),
client=self.client,
collection=self,
)
Expand Down Expand Up @@ -404,10 +408,9 @@ def pull(self, repository, tag=None, **kwargs):
Args:
repository (str): The repository to pull
tag (str): The tag to pull
auth_config (dict): Override the credentials that
:py:meth:`~docker.client.DockerClient.login` has set for
this request. ``auth_config`` should contain the ``username``
and ``password`` keys to be valid.
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.
platform (str): Platform in the format ``os[/arch[/variant]]``

Returns:
Expand Down