Skip to content

Commit 01ccaa6

Browse files
committed
Make AuthConfig a dict subclass for backward-compatibility
Signed-off-by: Joffrey F <[email protected]>
1 parent bc5d7c8 commit 01ccaa6

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

docker/auth.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_config_header(client, registry):
4343
log.debug(
4444
"No auth config in memory - loading from filesystem"
4545
)
46-
client._auth_configs = load_config()
46+
client._auth_configs = load_config(credstore_env=client.credstore_env)
4747
authcfg = resolve_authconfig(
4848
client._auth_configs, registry, credstore_env=client.credstore_env
4949
)
@@ -70,14 +70,16 @@ def split_repo_name(repo_name):
7070

7171

7272
def get_credential_store(authconfig, registry):
73+
if not isinstance(authconfig, AuthConfig):
74+
authconfig = AuthConfig(authconfig)
7375
return authconfig.get_credential_store(registry)
7476

7577

76-
class AuthConfig(object):
78+
class AuthConfig(dict):
7779
def __init__(self, dct, credstore_env=None):
7880
if 'auths' not in dct:
7981
dct['auths'] = {}
80-
self._dct = dct
82+
self.update(dct)
8183
self._credstore_env = credstore_env
8284
self._stores = {}
8385

@@ -200,15 +202,15 @@ def load_config(cls, config_path, config_dict, credstore_env=None):
200202

201203
@property
202204
def auths(self):
203-
return self._dct.get('auths', {})
205+
return self.get('auths', {})
204206

205207
@property
206208
def creds_store(self):
207-
return self._dct.get('credsStore', None)
209+
return self.get('credsStore', None)
208210

209211
@property
210212
def cred_helpers(self):
211-
return self._dct.get('credHelpers', {})
213+
return self.get('credHelpers', {})
212214

213215
def resolve_authconfig(self, registry=None):
214216
"""
@@ -305,10 +307,12 @@ def get_all_credentials(self):
305307
return auth_data
306308

307309
def add_auth(self, reg, data):
308-
self._dct['auths'][reg] = data
310+
self['auths'][reg] = data
309311

310312

311313
def resolve_authconfig(authconfig, registry=None, credstore_env=None):
314+
if not isinstance(authconfig, AuthConfig):
315+
authconfig = AuthConfig(authconfig, credstore_env)
312316
return authconfig.resolve_authconfig(registry)
313317

314318

tests/unit/auth_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def test_load_config_unknown_keys(self):
466466
json.dump(config, f)
467467

468468
cfg = auth.load_config(dockercfg_path)
469-
assert cfg._dct == {'auths': {}}
469+
assert dict(cfg) == {'auths': {}}
470470

471471
def test_load_config_invalid_auth_dict(self):
472472
folder = tempfile.mkdtemp()
@@ -481,7 +481,7 @@ def test_load_config_invalid_auth_dict(self):
481481
json.dump(config, f)
482482

483483
cfg = auth.load_config(dockercfg_path)
484-
assert cfg._dct == {'auths': {'scarlet.net': {}}}
484+
assert dict(cfg) == {'auths': {'scarlet.net': {}}}
485485

486486
def test_load_config_identity_token(self):
487487
folder = tempfile.mkdtemp()

0 commit comments

Comments
 (0)