mirror of https://github.com/docker/compose.git
Merge pull request #3830 from shin-/3534-machine-config-args
Remove surrounding quotes from TLS paths, if present
This commit is contained in:
commit
3dec600d82
|
@ -11,15 +11,16 @@ from docker.utils import kwargs_from_env
|
|||
from ..const import HTTP_TIMEOUT
|
||||
from .errors import UserError
|
||||
from .utils import generate_user_agent
|
||||
from .utils import unquote_path
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def tls_config_from_options(options):
|
||||
tls = options.get('--tls', False)
|
||||
ca_cert = options.get('--tlscacert')
|
||||
cert = options.get('--tlscert')
|
||||
key = options.get('--tlskey')
|
||||
ca_cert = unquote_path(options.get('--tlscacert'))
|
||||
cert = unquote_path(options.get('--tlscert'))
|
||||
key = unquote_path(options.get('--tlskey'))
|
||||
verify = options.get('--tlsverify')
|
||||
skip_hostname_check = options.get('--skip-hostname-check', False)
|
||||
|
||||
|
|
|
@ -122,3 +122,11 @@ def generate_user_agent():
|
|||
else:
|
||||
parts.append("{}/{}".format(p_system, p_release))
|
||||
return " ".join(parts)
|
||||
|
||||
|
||||
def unquote_path(s):
|
||||
if not s:
|
||||
return s
|
||||
if s[0] == '"' and s[-1] == '"':
|
||||
return s[1:-1]
|
||||
return s
|
||||
|
|
|
@ -144,3 +144,16 @@ class TLSConfigTestCase(unittest.TestCase):
|
|||
result = tls_config_from_options(options)
|
||||
assert isinstance(result, docker.tls.TLSConfig)
|
||||
assert result.assert_hostname is False
|
||||
|
||||
def test_tls_client_and_ca_quoted_paths(self):
|
||||
options = {
|
||||
'--tlscacert': '"{0}"'.format(self.ca_cert),
|
||||
'--tlscert': '"{0}"'.format(self.client_cert),
|
||||
'--tlskey': '"{0}"'.format(self.key),
|
||||
'--tlsverify': True
|
||||
}
|
||||
result = tls_config_from_options(options)
|
||||
assert isinstance(result, docker.tls.TLSConfig)
|
||||
assert result.cert == (self.client_cert, self.key)
|
||||
assert result.ca_cert == self.ca_cert
|
||||
assert result.verify is True
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
|
||||
from compose.cli.utils import unquote_path
|
||||
|
||||
|
||||
class UnquotePathTest(unittest.TestCase):
|
||||
def test_no_quotes(self):
|
||||
assert unquote_path('hello') == 'hello'
|
||||
|
||||
def test_simple_quotes(self):
|
||||
assert unquote_path('"hello"') == 'hello'
|
||||
|
||||
def test_uneven_quotes(self):
|
||||
assert unquote_path('"hello') == '"hello'
|
||||
assert unquote_path('hello"') == 'hello"'
|
||||
|
||||
def test_nested_quotes(self):
|
||||
assert unquote_path('""hello""') == '"hello"'
|
||||
assert unquote_path('"hel"lo"') == 'hel"lo'
|
||||
assert unquote_path('"hello""') == 'hello"'
|
Loading…
Reference in New Issue