mirror of https://github.com/docker/docker-py.git
Merge pull request #825 from aebm/master
Fix auth.load_config bug calling parse_auth
This commit is contained in:
commit
311ae711d4
|
@ -172,7 +172,7 @@ def load_config(config_path=None):
|
|||
data = json.load(f)
|
||||
if data.get('auths'):
|
||||
log.debug("Found 'auths' section")
|
||||
return parse_auth(data)
|
||||
return parse_auth(data['auths'])
|
||||
else:
|
||||
log.debug("Couldn't find 'auths' section")
|
||||
f.seek(0)
|
||||
|
|
|
@ -287,3 +287,32 @@ class LoadConfigTest(base.Cleanup, base.BaseTestCase):
|
|||
self.assertEqual(cfg['password'], 'izayoi')
|
||||
self.assertEqual(cfg['email'], 'sakuya@scarlet.net')
|
||||
self.assertEqual(cfg.get('auth'), None)
|
||||
|
||||
def test_load_config_custom_config_env_with_auths(self):
|
||||
folder = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, folder)
|
||||
|
||||
dockercfg_path = os.path.join(folder, 'config.json')
|
||||
registry = 'https://your.private.registry.io'
|
||||
auth_ = base64.b64encode(b'sakuya:izayoi').decode('ascii')
|
||||
config = {
|
||||
'auths': {
|
||||
registry: {
|
||||
'auth': '{0}'.format(auth_),
|
||||
'email': 'sakuya@scarlet.net'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
with open(dockercfg_path, 'w') as f:
|
||||
json.dump(config, f)
|
||||
|
||||
with mock.patch.dict(os.environ, {'DOCKER_CONFIG': folder}):
|
||||
cfg = auth.load_config(None)
|
||||
assert registry in cfg
|
||||
self.assertNotEqual(cfg[registry], None)
|
||||
cfg = cfg[registry]
|
||||
self.assertEqual(cfg['username'], 'sakuya')
|
||||
self.assertEqual(cfg['password'], 'izayoi')
|
||||
self.assertEqual(cfg['email'], 'sakuya@scarlet.net')
|
||||
self.assertEqual(cfg.get('auth'), None)
|
||||
|
|
Loading…
Reference in New Issue