Removed logger dependency (no warnings) + do not break push for API versions < 1.5

This commit is contained in:
shin- 2013-09-30 19:57:10 +02:00
parent b2c2a1b87f
commit 6c55b63f22
2 changed files with 8 additions and 19 deletions

View File

@ -3,7 +3,7 @@ ChangeLog
0.2.2 0.2.2
----- -----
* Authorize but warn anonym push/pull * Allow anonymous push/pull (no authconfig detected)
0.2.1 0.2.1
----- -----

View File

@ -19,16 +19,12 @@ import shlex
import requests import requests
import requests.exceptions import requests.exceptions
import six import six
import logging
import auth import auth
import unixconn import unixconn
import utils import utils
logger = logging.getLogger('docker-py')
class APIError(requests.exceptions.HTTPError): class APIError(requests.exceptions.HTTPError):
def __init__(self, message, response, explanation=None): def __init__(self, message, response, explanation=None):
super(APIError, self).__init__(message, response=response) super(APIError, self).__init__(message, response=response)
@ -393,11 +389,7 @@ class Client(requests.Session):
authcfg = auth.resolve_authconfig(self._cfg, registry) authcfg = auth.resolve_authconfig(self._cfg, registry)
# do not fail if no atuhentication exists # do not fail if no atuhentication exists
# for this specific registry as we can have a readonly pull # for this specific registry as we can have a readonly pull
if not authcfg: if authcfg:
logger.warn(
'No authentication bits found for {0}'.format(
registry))
else:
headers['X-Registry-Auth'] = auth.encode_header(authcfg) headers['X-Registry-Auth'] = auth.encode_header(authcfg)
u = self._url("/images/create") u = self._url("/images/create")
return self._result(self.post(u, params=params, headers=headers)) return self._result(self.post(u, params=params, headers=headers))
@ -406,19 +398,16 @@ class Client(requests.Session):
registry, repository = auth.resolve_repository_name(repository) registry, repository = auth.resolve_repository_name(repository)
u = self._url("/images/{0}/push".format(repository)) u = self._url("/images/{0}/push".format(repository))
headers = {} headers = {}
if getattr(self, '_cfg', None) is None:
self._cfg = auth.load_config()
authcfg = auth.resolve_authconfig(self._cfg, registry)
if utils.compare_version('1.5', self._version) >= 0: if utils.compare_version('1.5', self._version) >= 0:
if getattr(self, '_cfg', None) is None:
self._cfg = auth.load_config()
authcfg = auth.resolve_authconfig(self._cfg, registry)
# do not fail if no atuhentication exists # do not fail if no atuhentication exists
# for this specific registry as we can have an anon push # for this specific registry as we can have an anon push
if not authcfg: if authcfg:
logger.warn(
'No authentication bits found for {0}'.format(
registry))
else:
headers['X-Registry-Auth'] = auth.encode_header(authcfg) headers['X-Registry-Auth'] = auth.encode_header(authcfg)
return self._result(self._post_json(u, None, headers=headers)) return self._result(self._post_json(u, None, headers=headers))
return self._result(self._post_json(u, authcfg))
def remove_container(self, container, v=False): def remove_container(self, container, v=False):
if isinstance(container, dict): if isinstance(container, dict):