3
3
import logging
4
4
import os
5
5
6
+ import dockerpycreds
6
7
import six
7
8
8
9
from .. import errors
11
12
INDEX_URL = 'https://{0}/v1/' .format (INDEX_NAME )
12
13
DOCKER_CONFIG_FILENAME = os .path .join ('.docker' , 'config.json' )
13
14
LEGACY_DOCKER_CONFIG_FILENAME = '.dockercfg'
15
+ TOKEN_USERNAME = '<token>'
14
16
15
17
log = logging .getLogger (__name__ )
16
18
@@ -74,6 +76,13 @@ def resolve_authconfig(authconfig, registry=None):
74
76
with full URLs are stripped down to hostnames before checking for a match.
75
77
Returns None if no match was found.
76
78
"""
79
+ if 'credsStore' in authconfig :
80
+ log .debug (
81
+ 'Using credentials store "{0}"' .format (authconfig ['credsStore' ])
82
+ )
83
+ return _resolve_authconfig_credstore (
84
+ authconfig , registry , authconfig ['credsStore' ]
85
+ )
77
86
# Default to the public index server
78
87
registry = resolve_index_name (registry ) if registry else INDEX_NAME
79
88
log .debug ("Looking for auth entry for {0}" .format (repr (registry )))
@@ -91,6 +100,35 @@ def resolve_authconfig(authconfig, registry=None):
91
100
return None
92
101
93
102
103
+ def _resolve_authconfig_credstore (authconfig , registry , credstore_name ):
104
+ if not registry or registry == INDEX_NAME :
105
+ # The ecosystem is a little schizophrenic with index.docker.io VS
106
+ # docker.io - in that case, it seems the full URL is necessary.
107
+ registry = 'https://index.docker.io/v1/'
108
+ log .debug ("Looking for auth entry for {0}" .format (repr (registry )))
109
+ store = dockerpycreds .Store (credstore_name )
110
+ try :
111
+ data = store .get (registry )
112
+ res = {
113
+ 'ServerAddress' : registry ,
114
+ }
115
+ if data ['Username' ] == TOKEN_USERNAME :
116
+ res ['IdentityToken' ] = data ['Secret' ]
117
+ else :
118
+ res .update ({
119
+ 'Username' : data ['Username' ],
120
+ 'Password' : data ['Secret' ],
121
+ })
122
+ return res
123
+ except dockerpycreds .CredentialsNotFound as e :
124
+ log .debug ('No entry found' )
125
+ return None
126
+ except dockerpycreds .StoreError as e :
127
+ raise errors .DockerException (
128
+ 'Credentials store error: {0}' .format (repr (e ))
129
+ )
130
+
131
+
94
132
def convert_to_hostname (url ):
95
133
return url .replace ('http://' , '' ).replace ('https://' , '' ).split ('/' , 1 )[0 ]
96
134
0 commit comments