summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <f.joffrey@gmail.com>2016-09-16 11:47:48 -0700
committerGitHub <noreply@github.com>2016-09-16 11:47:48 -0700
commit1e939be5fb26ccd5f5b064d9dcd0732e1397ff47 (patch)
treeee0e95bb992bbb329e79721564a1360eb88da033
parent9141e9496d7b77069ba262f32aeb54ad38f635fd (diff)
parentd731a4315c44974954eef503fd23c512b912296d (diff)
downloaddocker-py-1e939be5fb26ccd5f5b064d9dcd0732e1397ff47.tar.gz
Merge pull request #1210 from docker/identity-token-support
Add support for identity tokens in config file
-rw-r--r--docker/auth/auth.py13
-rw-r--r--tests/unit/auth_test.py26
2 files changed, 37 insertions, 2 deletions
diff --git a/docker/auth/auth.py b/docker/auth/auth.py
index ea15def..dc0baea 100644
--- a/docker/auth/auth.py
+++ b/docker/auth/auth.py
@@ -174,6 +174,15 @@ def parse_auth(entries, raise_on_error=False):
'Invalid configuration for registry {0}'.format(registry)
)
return {}
+ if 'identitytoken' in entry:
+ log.debug('Found an IdentityToken entry for registry {0}'.format(
+ registry
+ ))
+ conf[registry] = {
+ 'IdentityToken': entry['identitytoken']
+ }
+ continue # Other values are irrelevant if we have a token, skip.
+
if 'auth' not in entry:
# Starting with engine v1.11 (API 1.23), an empty dictionary is
# a valid value in the auths config.
@@ -182,13 +191,15 @@ def parse_auth(entries, raise_on_error=False):
'Auth data for {0} is absent. Client might be using a '
'credentials store instead.'
)
- return {}
+ conf[registry] = {}
+ continue
username, password = decode_auth(entry['auth'])
log.debug(
'Found entry (registry={0}, username={1})'
.format(repr(registry), repr(username))
)
+
conf[registry] = {
'username': username,
'password': password,
diff --git a/tests/unit/auth_test.py b/tests/unit/auth_test.py
index 4ea4047..f395133 100644
--- a/tests/unit/auth_test.py
+++ b/tests/unit/auth_test.py
@@ -460,4 +460,28 @@ class LoadConfigTest(base.Cleanup, base.BaseTestCase):
json.dump(config, f)
cfg = auth.load_config(dockercfg_path)
- assert cfg == {}
+ assert cfg == {'scarlet.net': {}}
+
+ def test_load_config_identity_token(self):
+ folder = tempfile.mkdtemp()
+ registry = 'scarlet.net'
+ token = '1ce1cebb-503e-7043-11aa-7feb8bd4a1ce'
+ self.addCleanup(shutil.rmtree, folder)
+ dockercfg_path = os.path.join(folder, 'config.json')
+ auth_entry = encode_auth({'username': 'sakuya'}).decode('ascii')
+ config = {
+ 'auths': {
+ registry: {
+ 'auth': auth_entry,
+ 'identitytoken': token
+ }
+ }
+ }
+ with open(dockercfg_path, 'w') as f:
+ json.dump(config, f)
+
+ cfg = auth.load_config(dockercfg_path)
+ assert registry in cfg
+ cfg = cfg[registry]
+ assert 'IdentityToken' in cfg
+ assert cfg['IdentityToken'] == token