Skip to content

Commit

Permalink
Return current context instead of default on get_context with no name
Browse files Browse the repository at this point in the history
Signed-off-by: Anca Iordache <anca.iordache@docker.com>
  • Loading branch information
aiordache committed Feb 3, 2020
1 parent 0125e06 commit 10a9437
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

11 changes: 6 additions & 5 deletions docker/context/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ def create_context(
return ctx

@classmethod
def get_context(cls, name="default"):
def get_context(cls, name=None):
"""Retrieves a context object.
Args:
name (str): The name of the context
Example:
>>> from docker.context import ContextAPI
>>> ctx = ContextAPI..get_context(name='test')
>>> ctx = ContextAPI.get_context(name='test')
>>> print(ctx.Metadata)
{
"Name": "test",
Expand All @@ -90,7 +90,9 @@ def get_context(cls, name="default"):
}
}
"""
if not name or name == "default":
if not name:
name = get_current_context_name()
if name == "default":
return ContextAPI.DEFAULT_CONTEXT
return Context.load_context(name)

Expand Down Expand Up @@ -127,8 +129,7 @@ def get_current_context(cls):
Returns:
(Context): current context object.
"""
name = get_current_context_name()
return ContextAPI.get_context(name)
return ContextAPI.get_context()

@classmethod
def set_current_context(cls, name="default"):
Expand Down
8 changes: 4 additions & 4 deletions docker/context/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ def inspect(self):

@classmethod
def load_context(cls, name):
name, orchestrator, endpoints = Context.load_meta(name)
name, orchestrator, endpoints = Context._load_meta(name)
if name:
instance = cls(name, orchestrator, endpoints=endpoints)
instance.load_certs()
instance._load_certs()
instance.meta_path = get_meta_dir(name)
return instance
return None

@classmethod
def load_meta(cls, name):
def _load_meta(cls, name):
metadata = {}
meta_file = get_meta_file(name)
if os.path.isfile(meta_file):
Expand All @@ -88,7 +88,7 @@ def load_meta(cls, name):
metadata["Endpoints"])
return None, None, None

def load_certs(self):
def _load_certs(self):
certs = {}
tls_dir = get_tls_dir(self.name)
for endpoint in self.endpoints.keys():
Expand Down

0 comments on commit 10a9437

Please sign in to comment.