Przeglądaj źródła

Remove surrounding quotes from TLS paths, if present

Signed-off-by: Joffrey F <[email protected]>
Joffrey F 9 lat temu
rodzic
commit
c0305024f5

+ 4 - 3
compose/cli/docker_client.py

@@ -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)
 

+ 8 - 0
compose/cli/utils.py

@@ -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

+ 13 - 0
tests/unit/cli/docker_client_test.py

@@ -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

+ 23 - 0
tests/unit/cli/utils_test.py

@@ -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"'