Merge branch 'pull_auth' of https://github.com/hibooboo2/docker-py into hibooboo2-pull_auth

This commit is contained in:
Joffrey F 2015-04-22 11:18:46 -07:00
commit 1445956010
2 changed files with 16 additions and 10 deletions

View File

@ -746,7 +746,7 @@ class Client(requests.Session):
return h_ports
def pull(self, repository, tag=None, stream=False,
insecure_registry=False):
insecure_registry=False, auth_config=None):
if not tag:
repository, tag = utils.parse_repository_tag(repository)
registry, repo_name = auth.resolve_repository_name(
@ -764,15 +764,20 @@ class Client(requests.Session):
if utils.compare_version('1.5', self._version) >= 0:
# If we don't have any auth data so far, try reloading the config
# file one more time in case anything showed up in there.
if not self._auth_configs:
self._auth_configs = auth.load_config()
authcfg = auth.resolve_authconfig(self._auth_configs, registry)
# Do not fail here if no authentication exists for this specific
# registry as we can have a readonly pull. Just put the header if
# we can.
if authcfg:
headers['X-Registry-Auth'] = auth.encode_header(authcfg)
if auth_config is None:
if not self._auth_configs:
self._auth_configs = auth.load_config()
authcfg = auth.resolve_authconfig(self._auth_configs, registry)
# Do not fail here if no authentication exists for this
# specific registry as we can have a readonly pull. Just
# put the header if we can.
if authcfg:
# auth_config needs to be a dict in the format used by
# auth.py username , password, serveraddress, email
headers['X-Registry-Auth'] = auth.encode_header(
auth_config)
else:
headers['X-Registry-Auth'] = auth.encode_header(auth_config)
response = self._post(self._url('/images/create'), params=params,
headers=headers, stream=stream, timeout=None)

View File

@ -502,6 +502,7 @@ Identical to the `docker pull` command.
* tag (str): The tag to pull
* stream (bool): Stream the output as a generator
* insecure_registry (bool): Use an insecure registry
* auth_config (dict): Override the credentials that Client.login has set for this request
**Returns** (generator or str): The output