mirror of https://github.com/docker/compose.git
Add user agent to API calls
Signed-off-by: Ben Firshman <ben@firshman.co.uk>
This commit is contained in:
parent
5f0186e008
commit
1877a41b92
|
@ -10,6 +10,7 @@ from docker.utils import kwargs_from_env
|
|||
|
||||
from ..const import HTTP_TIMEOUT
|
||||
from .errors import UserError
|
||||
from .utils import generate_user_agent
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -67,4 +68,6 @@ def docker_client(environment, version=None, tls_config=None, host=None,
|
|||
else:
|
||||
kwargs['timeout'] = HTTP_TIMEOUT
|
||||
|
||||
kwargs['user_agent'] = generate_user_agent()
|
||||
|
||||
return Client(**kwargs)
|
||||
|
|
|
@ -107,3 +107,18 @@ def get_build_version():
|
|||
|
||||
def is_docker_for_mac_installed():
|
||||
return is_mac() and os.path.isdir('/Applications/Docker.app')
|
||||
|
||||
|
||||
def generate_user_agent():
|
||||
parts = [
|
||||
"docker-compose/{}".format(compose.__version__),
|
||||
"docker-py/{}".format(docker.__version__),
|
||||
]
|
||||
try:
|
||||
p_system = platform.system()
|
||||
p_release = platform.release()
|
||||
except IOError:
|
||||
pass
|
||||
else:
|
||||
parts.append("{}/{}".format(p_system, p_release))
|
||||
return " ".join(parts)
|
||||
|
|
|
@ -2,10 +2,12 @@ from __future__ import absolute_import
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import platform
|
||||
|
||||
import docker
|
||||
import pytest
|
||||
|
||||
import compose
|
||||
from compose.cli import errors
|
||||
from compose.cli.docker_client import docker_client
|
||||
from compose.cli.docker_client import tls_config_from_options
|
||||
|
@ -40,6 +42,16 @@ class DockerClientTestCase(unittest.TestCase):
|
|||
assert fake_log.error.call_count == 1
|
||||
assert '123' in fake_log.error.call_args[0][0]
|
||||
|
||||
def test_user_agent(self):
|
||||
client = docker_client(os.environ)
|
||||
expected = "docker-compose/{0} docker-py/{1} {2}/{3}".format(
|
||||
compose.__version__,
|
||||
docker.__version__,
|
||||
platform.system(),
|
||||
platform.release()
|
||||
)
|
||||
self.assertEqual(client.headers['User-Agent'], expected)
|
||||
|
||||
|
||||
class TLSConfigTestCase(unittest.TestCase):
|
||||
ca_cert = 'tests/fixtures/tls/ca.pem'
|
||||
|
|
Loading…
Reference in New Issue