Kaydet (Commit) 01ccaa6a authored tarafından Joffrey F's avatar Joffrey F

Make AuthConfig a dict subclass for backward-compatibility

Signed-off-by: 's avatarJoffrey F <joffrey@docker.com>
üst bc5d7c8c
...@@ -43,7 +43,7 @@ def get_config_header(client, registry): ...@@ -43,7 +43,7 @@ def get_config_header(client, registry):
log.debug( log.debug(
"No auth config in memory - loading from filesystem" "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( authcfg = resolve_authconfig(
client._auth_configs, registry, credstore_env=client.credstore_env client._auth_configs, registry, credstore_env=client.credstore_env
) )
...@@ -70,14 +70,16 @@ def split_repo_name(repo_name): ...@@ -70,14 +70,16 @@ def split_repo_name(repo_name):
def get_credential_store(authconfig, registry): def get_credential_store(authconfig, registry):
if not isinstance(authconfig, AuthConfig):
authconfig = AuthConfig(authconfig)
return authconfig.get_credential_store(registry) return authconfig.get_credential_store(registry)
class AuthConfig(object): class AuthConfig(dict):
def __init__(self, dct, credstore_env=None): def __init__(self, dct, credstore_env=None):
if 'auths' not in dct: if 'auths' not in dct:
dct['auths'] = {} dct['auths'] = {}
self._dct = dct self.update(dct)
self._credstore_env = credstore_env self._credstore_env = credstore_env
self._stores = {} self._stores = {}
...@@ -200,15 +202,15 @@ class AuthConfig(object): ...@@ -200,15 +202,15 @@ class AuthConfig(object):
@property @property
def auths(self): def auths(self):
return self._dct.get('auths', {}) return self.get('auths', {})
@property @property
def creds_store(self): def creds_store(self):
return self._dct.get('credsStore', None) return self.get('credsStore', None)
@property @property
def cred_helpers(self): def cred_helpers(self):
return self._dct.get('credHelpers', {}) return self.get('credHelpers', {})
def resolve_authconfig(self, registry=None): def resolve_authconfig(self, registry=None):
""" """
...@@ -305,10 +307,12 @@ class AuthConfig(object): ...@@ -305,10 +307,12 @@ class AuthConfig(object):
return auth_data return auth_data
def add_auth(self, reg, 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): def resolve_authconfig(authconfig, registry=None, credstore_env=None):
if not isinstance(authconfig, AuthConfig):
authconfig = AuthConfig(authconfig, credstore_env)
return authconfig.resolve_authconfig(registry) return authconfig.resolve_authconfig(registry)
......
...@@ -466,7 +466,7 @@ class LoadConfigTest(unittest.TestCase): ...@@ -466,7 +466,7 @@ class LoadConfigTest(unittest.TestCase):
json.dump(config, f) json.dump(config, f)
cfg = auth.load_config(dockercfg_path) cfg = auth.load_config(dockercfg_path)
assert cfg._dct == {'auths': {}} assert dict(cfg) == {'auths': {}}
def test_load_config_invalid_auth_dict(self): def test_load_config_invalid_auth_dict(self):
folder = tempfile.mkdtemp() folder = tempfile.mkdtemp()
...@@ -481,7 +481,7 @@ class LoadConfigTest(unittest.TestCase): ...@@ -481,7 +481,7 @@ class LoadConfigTest(unittest.TestCase):
json.dump(config, f) json.dump(config, f)
cfg = auth.load_config(dockercfg_path) 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): def test_load_config_identity_token(self):
folder = tempfile.mkdtemp() folder = tempfile.mkdtemp()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment