mirror of https://github.com/docker/docker-py.git
Specify when to use `tls` on Context constructor
Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
parent
9b59e49113
commit
105efa02a9
|
|
@ -73,8 +73,8 @@ def get_tls_dir(name=None, endpoint=""):
|
||||||
return os.path.join(context_dir, "tls")
|
return os.path.join(context_dir, "tls")
|
||||||
|
|
||||||
|
|
||||||
def get_context_host(path=None):
|
def get_context_host(path=None, tls=False):
|
||||||
host = utils.parse_host(path, IS_WINDOWS_PLATFORM)
|
host = utils.parse_host(path, IS_WINDOWS_PLATFORM, tls)
|
||||||
if host == DEFAULT_UNIX_SOCKET:
|
if host == DEFAULT_UNIX_SOCKET:
|
||||||
# remove http+ from default docker socket url
|
# remove http+ from default docker socket url
|
||||||
return host.strip("http+")
|
return host.strip("http+")
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ from docker.context.config import get_context_host
|
||||||
|
|
||||||
class Context:
|
class Context:
|
||||||
"""A context."""
|
"""A context."""
|
||||||
def __init__(self, name, orchestrator="swarm", host=None, endpoints=None):
|
def __init__(self, name, orchestrator="swarm", host=None, endpoints=None,
|
||||||
|
tls=False):
|
||||||
if not name:
|
if not name:
|
||||||
raise Exception("Name not provided")
|
raise Exception("Name not provided")
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
@ -22,8 +23,8 @@ class Context:
|
||||||
) else orchestrator
|
) else orchestrator
|
||||||
self.endpoints = {
|
self.endpoints = {
|
||||||
default_endpoint: {
|
default_endpoint: {
|
||||||
"Host": get_context_host(host),
|
"Host": get_context_host(host, tls),
|
||||||
"SkipTLSVerify": False
|
"SkipTLSVerify": not tls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
|
@ -44,7 +45,7 @@ class Context:
|
||||||
self, name="docker", host=None, tls_cfg=None,
|
self, name="docker", host=None, tls_cfg=None,
|
||||||
skip_tls_verify=False, def_namespace=None):
|
skip_tls_verify=False, def_namespace=None):
|
||||||
self.endpoints[name] = {
|
self.endpoints[name] = {
|
||||||
"Host": get_context_host(host),
|
"Host": get_context_host(host, not skip_tls_verify),
|
||||||
"SkipTLSVerify": skip_tls_verify
|
"SkipTLSVerify": skip_tls_verify
|
||||||
}
|
}
|
||||||
if def_namespace:
|
if def_namespace:
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,10 @@ class BaseContextTest(unittest.TestCase):
|
||||||
def test_get_current_context(self):
|
def test_get_current_context(self):
|
||||||
assert ContextAPI.get_current_context().Name == "default"
|
assert ContextAPI.get_current_context().Name == "default"
|
||||||
|
|
||||||
|
def test_https_host(self):
|
||||||
|
c = Context("test", host="tcp://testdomain:8080", tls=True)
|
||||||
|
assert c.Host == "https://testdomain:8080"
|
||||||
|
|
||||||
def test_context_inspect_without_params(self):
|
def test_context_inspect_without_params(self):
|
||||||
ctx = ContextAPI.inspect_context()
|
ctx = ContextAPI.inspect_context()
|
||||||
assert ctx["Name"] == "default"
|
assert ctx["Name"] == "default"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue