diff options
author | Joffrey F <joffrey@docker.com> | 2018-11-30 13:51:01 -0800 |
---|---|---|
committer | Joffrey F <joffrey@docker.com> | 2018-11-30 13:51:01 -0800 |
commit | 01ccaa6af2106f01b9804177782622f12525b8a5 (patch) | |
tree | 529eec6486a6dadb26ee86cc79f0e399e618733a | |
parent | bc5d7c8cb676d54ad00b8cd8e731a9db049c392c (diff) | |
download | docker-py-01ccaa6af2106f01b9804177782622f12525b8a5.tar.gz |
Make AuthConfig a dict subclass for backward-compatibility
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r-- | docker/auth.py | 18 | ||||
-rw-r--r-- | tests/unit/auth_test.py | 4 |
2 files changed, 13 insertions, 9 deletions
diff --git a/docker/auth.py b/docker/auth.py index a6c8ae1..462390b 100644 --- a/docker/auth.py +++ b/docker/auth.py @@ -43,7 +43,7 @@ def get_config_header(client, registry): log.debug( "No auth config in memory - loading from filesystem" ) - client._auth_configs = load_config() + client._auth_configs = load_config(credstore_env=client.credstore_env) authcfg = resolve_authconfig( client._auth_configs, registry, credstore_env=client.credstore_env ) @@ -70,14 +70,16 @@ def split_repo_name(repo_name): def get_credential_store(authconfig, registry): + if not isinstance(authconfig, AuthConfig): + authconfig = AuthConfig(authconfig) return authconfig.get_credential_store(registry) -class AuthConfig(object): +class AuthConfig(dict): def __init__(self, dct, credstore_env=None): if 'auths' not in dct: dct['auths'] = {} - self._dct = dct + self.update(dct) self._credstore_env = credstore_env self._stores = {} @@ -200,15 +202,15 @@ class AuthConfig(object): @property def auths(self): - return self._dct.get('auths', {}) + return self.get('auths', {}) @property def creds_store(self): - return self._dct.get('credsStore', None) + return self.get('credsStore', None) @property def cred_helpers(self): - return self._dct.get('credHelpers', {}) + return self.get('credHelpers', {}) def resolve_authconfig(self, registry=None): """ @@ -305,10 +307,12 @@ class AuthConfig(object): return auth_data def add_auth(self, reg, data): - self._dct['auths'][reg] = data + self['auths'][reg] = data def resolve_authconfig(authconfig, registry=None, credstore_env=None): + if not isinstance(authconfig, AuthConfig): + authconfig = AuthConfig(authconfig, credstore_env) return authconfig.resolve_authconfig(registry) diff --git a/tests/unit/auth_test.py b/tests/unit/auth_test.py index 4ad74d5..d3c8eee 100644 --- a/tests/unit/auth_test.py +++ b/tests/unit/auth_test.py @@ -466,7 +466,7 @@ class LoadConfigTest(unittest.TestCase): json.dump(config, f) cfg = auth.load_config(dockercfg_path) - assert cfg._dct == {'auths': {}} + assert dict(cfg) == {'auths': {}} def test_load_config_invalid_auth_dict(self): folder = tempfile.mkdtemp() @@ -481,7 +481,7 @@ class LoadConfigTest(unittest.TestCase): json.dump(config, f) cfg = auth.load_config(dockercfg_path) - assert cfg._dct == {'auths': {'scarlet.net': {}}} + assert dict(cfg) == {'auths': {'scarlet.net': {}}} def test_load_config_identity_token(self): folder = tempfile.mkdtemp() |