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,34 @@ 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
+ if registry not in authconfig :
110
+ log .debug ("No entry found" )
111
+ store = dockerpycreds .Store (credstore_name )
112
+ try :
113
+ data = store .get (registry )
114
+ res = {
115
+ 'ServerAddress' : registry ,
116
+ }
117
+ if data ['Username' ] == TOKEN_USERNAME :
118
+ res ['IdentityToken' ] = data ['Secret' ]
119
+ else :
120
+ res .update ({
121
+ 'Username' : data ['Username' ],
122
+ 'Password' : data ['Secret' ],
123
+ })
124
+ return res
125
+ except dockerpycreds .StoreError as e :
126
+ log .error ('Credentials store error: {0}' .format (repr (e )))
127
+
128
+ return None
129
+
130
+
94
131
def convert_to_hostname (url ):
95
132
return url .replace ('http://' , '' ).replace ('https://' , '' ).split ('/' , 1 )[0 ]
96
133
0 commit comments