Repository: zalando-stups/pierone-cli

Issue:
no basic auth credentials
Today I had an auth issue. While trying to do `docker push` I was getting the following log:

    ➜ pierone login             
    Getting OAuth2 token "pierone".. OK
    Storing Docker client configuration in /Users/whoever/.docker/config.json.. OK
    ➜ docker push myrepo/...
    The push refers to a repository [myrepo/...]
    a5f591aacc10: Preparing 
    ...
    cb11ba605400: Waiting 
    no basic auth credentials

Recreating `~/config.json` saved me.  
There was `"credsStore": "osxkeychain"` setting In the previous version of the `~/config.json` which was causing me troubles.

BTW 
mac os 10.12.3
pierone cli 1.1.27
docker 17.06.0-ce, build 02c1d87

Discussion:
coveralls: 
[![Coverage Status](https://coveralls.io/builds/12989449/badge)](https://coveralls.io/builds/12989449)

Coverage decreased (-0.2%) to 84.185% when pulling **bc4f97f25ac83c3272e0bd949d59ef3f7add1168 on luisfarzati:58-fix-credsstore-bug** into **0afce92aedf654855ad35b90623410e6d6c261dd on zalando-stups:master**.

Raffo: @hjacobs The problem looks like it is coming from pierone/api.py line 65 where we read from the local config instead of the temp file. 
Raffo: Ok I figured out the problem, pushed a commit with @luisfarzati , should work now! 
coveralls: 
[![Coverage Status](https://coveralls.io/builds/12992022/badge)](https://coveralls.io/builds/12992022)

Coverage increased (+0.08%) to 84.428% when pulling **2b8aa9d20c68984ea9af219f085e15182c5799d0 on luisfarzati:58-fix-credsstore-bug** into **0afce92aedf654855ad35b90623410e6d6c261dd on zalando-stups:master**.

Raffo: @hjacobs please review. 
luisfarzati: ty @Raffo :)
hjacobs: :+1: 

Patch:
diff --git a/pierone/api.py b/pierone/api.py
index 35542be..9b0c76a 100644
--- a/pierone/api.py
+++ b/pierone/api.py
@@ -71,6 +71,9 @@ def docker_login_with_token(url, access_token):
     basic_auth = codecs.encode('oauth2:{}'.format(access_token).encode('utf-8'), 'base64').strip().decode('utf-8')
     if 'auths' not in dockercfg:
         dockercfg['auths'] = {}
+    if 'credsStore' in dockercfg:
+        del dockercfg['credsStore']
+
     dockercfg['auths'][url] = {'auth': basic_auth,
                                'email': 'no-mail-required@example.org'}
     with Action('Storing Docker client configuration in {}..'.format(path)):


Test patch:
diff --git a/tests/test_api.py b/tests/test_api.py
index 62e1f0a..3ee83be 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -21,6 +21,29 @@ def test_docker_login(monkeypatch, tmpdir):
         assert {'auth': 'b2F1dGgyOjEyMzc3',
                 'email': 'no-mail-required@example.org'} == data.get('auths').get('https://pierone.example.org')
 
+def test_docker_login_with_credsstore(monkeypatch, tmpdir):
+    monkeypatch.setattr('os.path.expanduser', lambda x: x.replace('~', str(tmpdir)))
+    monkeypatch.setattr('pierone.api.get_token', MagicMock(return_value='12377'))
+    path = os.path.expanduser('~/.docker/config.json')
+    os.makedirs(os.path.dirname(path))
+    with open(path, 'w') as fd:
+        json.dump({
+            "auths": {
+                "https://pierone.stups.zalan.do": {
+                    "auth": "xxx",
+                    "email": "no-mail-required@example.org"
+                }
+            },
+            "credsStore": "osxkeychain"
+        }, fd)
+    docker_login('https://pierone.example.org', 'services', 'mytok',
+                 'myuser', 'mypass', 'https://token.example.org', use_keyring=False)
+    with open(path) as fd:
+        data = yaml.safe_load(fd)
+        assert {'auth': 'b2F1dGgyOjEyMzc3',
+                'email': 'no-mail-required@example.org'} == data.get('auths').get('https://pierone.example.org')
+        assert 'credsStore' not in data
+
 
 def test_docker_login_service_token(monkeypatch, tmpdir):
     monkeypatch.setattr('os.path.expanduser', lambda x: x.replace('~', str(tmpdir)))