mirror of https://github.com/docker/docker-py.git
Merge pull request #1119 from Mobelux/fix-build-with-auth
Pass X-Registry-Auth when building an image
This commit is contained in:
commit
1f34b4896a
|
|
@ -18,7 +18,8 @@ class BuildApiMixin(object):
|
||||||
custom_context=False, encoding=None, pull=False,
|
custom_context=False, encoding=None, pull=False,
|
||||||
forcerm=False, dockerfile=None, container_limits=None,
|
forcerm=False, dockerfile=None, container_limits=None,
|
||||||
decode=False, buildargs=None, gzip=False):
|
decode=False, buildargs=None, gzip=False):
|
||||||
remote = context = headers = None
|
remote = context = None
|
||||||
|
headers = {}
|
||||||
container_limits = container_limits or {}
|
container_limits = container_limits or {}
|
||||||
if path is None and fileobj is None:
|
if path is None and fileobj is None:
|
||||||
raise TypeError("Either path or fileobj needs to be provided.")
|
raise TypeError("Either path or fileobj needs to be provided.")
|
||||||
|
|
@ -134,8 +135,7 @@ class BuildApiMixin(object):
|
||||||
', '.join(repr(k) for k in self._auth_configs.keys())
|
', '.join(repr(k) for k in self._auth_configs.keys())
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if headers is None:
|
|
||||||
headers = {}
|
|
||||||
if utils.compare_version('1.19', self._version) >= 0:
|
if utils.compare_version('1.19', self._version) >= 0:
|
||||||
headers['X-Registry-Config'] = auth.encode_header(
|
headers['X-Registry-Config'] = auth.encode_header(
|
||||||
self._auth_configs
|
self._auth_configs
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@ import gzip
|
||||||
import io
|
import io
|
||||||
|
|
||||||
import docker
|
import docker
|
||||||
|
from docker import auth
|
||||||
|
|
||||||
from .api_test import DockerClientTest
|
from .api_test import DockerClientTest, fake_request, url_prefix
|
||||||
|
|
||||||
|
|
||||||
class BuildTest(DockerClientTest):
|
class BuildTest(DockerClientTest):
|
||||||
|
|
@ -83,8 +84,25 @@ class BuildTest(DockerClientTest):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expected_params = {'t': None, 'q': False, 'dockerfile': None,
|
||||||
|
'rm': False, 'nocache': False, 'pull': False,
|
||||||
|
'forcerm': False,
|
||||||
|
'remote': 'https://github.com/docker-library/mongo'}
|
||||||
|
expected_headers = {
|
||||||
|
'X-Registry-Config': auth.encode_header(self.client._auth_configs)}
|
||||||
|
|
||||||
self.client.build(path='https://github.com/docker-library/mongo')
|
self.client.build(path='https://github.com/docker-library/mongo')
|
||||||
|
|
||||||
|
fake_request.assert_called_with(
|
||||||
|
'POST',
|
||||||
|
url_prefix + 'build',
|
||||||
|
stream=True,
|
||||||
|
data=None,
|
||||||
|
headers=expected_headers,
|
||||||
|
params=expected_params,
|
||||||
|
timeout=None
|
||||||
|
)
|
||||||
|
|
||||||
def test_build_container_with_named_dockerfile(self):
|
def test_build_container_with_named_dockerfile(self):
|
||||||
self.client.build('.', dockerfile='nameddockerfile')
|
self.client.build('.', dockerfile='nameddockerfile')
|
||||||
|
|
||||||
|
|
@ -103,3 +121,44 @@ class BuildTest(DockerClientTest):
|
||||||
'foo': 'bar'
|
'foo': 'bar'
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_set_auth_headers_with_empty_dict_and_auth_configs(self):
|
||||||
|
self.client._auth_configs = {
|
||||||
|
'https://example.com': {
|
||||||
|
'user': 'example',
|
||||||
|
'password': 'example',
|
||||||
|
'email': 'example@example.com'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
headers = {}
|
||||||
|
expected_headers = {
|
||||||
|
'X-Registry-Config': auth.encode_header(self.client._auth_configs)}
|
||||||
|
self.client._set_auth_headers(headers)
|
||||||
|
self.assertEqual(headers, expected_headers)
|
||||||
|
|
||||||
|
def test_set_auth_headers_with_dict_and_auth_configs(self):
|
||||||
|
self.client._auth_configs = {
|
||||||
|
'https://example.com': {
|
||||||
|
'user': 'example',
|
||||||
|
'password': 'example',
|
||||||
|
'email': 'example@example.com'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
headers = {'foo': 'bar'}
|
||||||
|
expected_headers = {
|
||||||
|
'foo': 'bar',
|
||||||
|
'X-Registry-Config': auth.encode_header(self.client._auth_configs)}
|
||||||
|
|
||||||
|
self.client._set_auth_headers(headers)
|
||||||
|
self.assertEqual(headers, expected_headers)
|
||||||
|
|
||||||
|
def test_set_auth_headers_with_dict_and_no_auth_configs(self):
|
||||||
|
headers = {'foo': 'bar'}
|
||||||
|
expected_headers = {
|
||||||
|
'foo': 'bar'
|
||||||
|
}
|
||||||
|
|
||||||
|
self.client._set_auth_headers(headers)
|
||||||
|
self.assertEqual(headers, expected_headers)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue