From 0f843414e5b4ba4c2344abb8bf3489eedba055d3 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Tue, 2 May 2017 14:38:07 -0500 Subject: [PATCH 1/2] Add a reload_config function to the DaemonApiMixin This allows the client to reload the config.json for an existing APIClient instance. Signed-off-by: Erik Johnson --- docker/api/daemon.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docker/api/daemon.py b/docker/api/daemon.py index 91c777f092..aa93643679 100644 --- a/docker/api/daemon.py +++ b/docker/api/daemon.py @@ -123,9 +123,9 @@ def login(self, username, password=None, email=None, registry=None, # If dockercfg_path is passed check to see if the config file exists, # if so load that config. if dockercfg_path and os.path.exists(dockercfg_path): - self._auth_configs = auth.load_config(dockercfg_path) + self._auth_configs = self.reload_config(dockercfg_path) elif not self._auth_configs: - self._auth_configs = auth.load_config() + self._auth_configs = self.reload_config() authcfg = auth.resolve_authconfig(self._auth_configs, registry) # If we found an existing auth config for this registry and username @@ -174,3 +174,17 @@ def version(self, api_version=True): """ url = self._url("/version", versioned_api=api_version) return self._result(self._get(url), json=True) + + def reload_config(self, dockercfg_path=None): + """ + Forces a reload of the auth configuration + + Args: + dockercfg_path (str): Use a custom path for the Docker config file + (default ``$HOME/.docker/config.json`` if present, + otherwise``$HOME/.dockercfg``) + + Returns: + None + """ + self._auth_configs = auth.load_config(dockercfg_path) From 550c31e2b701ddaa275f5b260e702987638467dc Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Tue, 2 May 2017 16:23:41 -0500 Subject: [PATCH 2/2] Move reload_config func into the APIClient Also revert an incorrect change in the DaemonApiMixin's login func Signed-off-by: Erik Johnson --- docker/api/client.py | 14 ++++++++++++++ docker/api/daemon.py | 18 ++---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docker/api/client.py b/docker/api/client.py index 749b061dce..54ec6abb45 100644 --- a/docker/api/client.py +++ b/docker/api/client.py @@ -433,3 +433,17 @@ def get_adapter(self, url): @property def api_version(self): return self._version + + def reload_config(self, dockercfg_path=None): + """ + Force a reload of the auth configuration + + Args: + dockercfg_path (str): Use a custom path for the Docker config file + (default ``$HOME/.docker/config.json`` if present, + otherwise``$HOME/.dockercfg``) + + Returns: + None + """ + self._auth_configs = auth.load_config(dockercfg_path) diff --git a/docker/api/daemon.py b/docker/api/daemon.py index aa93643679..91c777f092 100644 --- a/docker/api/daemon.py +++ b/docker/api/daemon.py @@ -123,9 +123,9 @@ def login(self, username, password=None, email=None, registry=None, # If dockercfg_path is passed check to see if the config file exists, # if so load that config. if dockercfg_path and os.path.exists(dockercfg_path): - self._auth_configs = self.reload_config(dockercfg_path) + self._auth_configs = auth.load_config(dockercfg_path) elif not self._auth_configs: - self._auth_configs = self.reload_config() + self._auth_configs = auth.load_config() authcfg = auth.resolve_authconfig(self._auth_configs, registry) # If we found an existing auth config for this registry and username @@ -174,17 +174,3 @@ def version(self, api_version=True): """ url = self._url("/version", versioned_api=api_version) return self._result(self._get(url), json=True) - - def reload_config(self, dockercfg_path=None): - """ - Forces a reload of the auth configuration - - Args: - dockercfg_path (str): Use a custom path for the Docker config file - (default ``$HOME/.docker/config.json`` if present, - otherwise``$HOME/.dockercfg``) - - Returns: - None - """ - self._auth_configs = auth.load_config(dockercfg_path)