15
15
import base64
16
16
import fileinput
17
17
import json
18
+ import logging
18
19
import os
19
20
import warnings
20
21
28
29
DOCKER_CONFIG_FILENAME = os .path .join ('.docker' , 'config.json' )
29
30
LEGACY_DOCKER_CONFIG_FILENAME = '.dockercfg'
30
31
32
+ log = logging .getLogger (__name__ )
33
+
31
34
32
35
def resolve_repository_name (repo_name , insecure = False ):
33
36
if insecure :
@@ -65,14 +68,18 @@ def resolve_authconfig(authconfig, registry=None):
65
68
"""
66
69
# Default to the public index server
67
70
registry = convert_to_hostname (registry ) if registry else INDEX_NAME
71
+ log .debug ("Looking for auth entry for {0}" .format (repr (registry )))
68
72
69
73
if registry in authconfig :
74
+ log .debug ("Found {0}" .format (repr (registry )))
70
75
return authconfig [registry ]
71
76
72
77
for key , config in six .iteritems (authconfig ):
73
78
if convert_to_hostname (key ) == registry :
79
+ log .debug ("Found {0}" .format (repr (key )))
74
80
return config
75
81
82
+ log .debug ("No entry found" )
76
83
return None
77
84
78
85
@@ -112,6 +119,10 @@ def parse_auth(entries):
112
119
conf = {}
113
120
for registry , entry in six .iteritems (entries ):
114
121
username , password = decode_auth (entry ['auth' ])
122
+ log .debug (
123
+ 'Found entry (registry={0}, username={1})'
124
+ .format (repr (registry ), repr (username ))
125
+ )
115
126
conf [registry ] = {
116
127
'username' : username ,
117
128
'password' : password ,
@@ -133,38 +144,49 @@ def load_config(config_path=None):
133
144
config_file = config_path or os .path .join (os .path .expanduser ('~' ),
134
145
DOCKER_CONFIG_FILENAME )
135
146
147
+ log .debug ("Trying {0}" .format (config_file ))
148
+
136
149
if os .path .exists (config_file ):
137
150
try :
138
151
with open (config_file ) as f :
139
152
for section , data in six .iteritems (json .load (f )):
140
153
if section != 'auths' :
141
154
continue
155
+ log .debug ("Found 'auths' section" )
142
156
return parse_auth (data )
143
- except (IOError , KeyError , ValueError ):
157
+ log .debug ("Couldn't find 'auths' section" )
158
+ except (IOError , KeyError , ValueError ) as e :
144
159
# Likely missing new Docker config file or it's in an
145
160
# unknown format, continue to attempt to read old location
146
161
# and format.
162
+ log .debug (e )
147
163
pass
164
+ else :
165
+ log .debug ("File doesn't exist" )
148
166
149
167
config_file = config_path or os .path .join (os .path .expanduser ('~' ),
150
168
LEGACY_DOCKER_CONFIG_FILENAME )
151
169
152
- # if config path doesn't exist return empty config
170
+ log .debug ("Trying {0}" .format (config_file ))
171
+
153
172
if not os .path .exists (config_file ):
173
+ log .debug ("File doesn't exist - returning empty config" )
154
174
return {}
155
175
156
- # Try reading legacy location as JSON.
176
+ log . debug ( "Attempting to parse as JSON" )
157
177
try :
158
178
with open (config_file ) as f :
159
179
return parse_auth (json .load (f ))
160
- except :
180
+ except Exception as e :
181
+ log .debug (e )
161
182
pass
162
183
163
184
# If that fails, we assume the configuration file contains a single
164
185
# authentication token for the public registry in the following format:
165
186
#
166
187
# auth = AUTH_TOKEN
167
188
189
+ log .debug ("Attempting to parse legacy auth file format" )
168
190
try :
169
191
data = []
170
192
for line in fileinput .input (config_file ):
@@ -182,8 +204,9 @@ def load_config(config_path=None):
182
204
'serveraddress' : INDEX_URL ,
183
205
}
184
206
return conf
185
- except :
207
+ except Exception as e :
208
+ log .debug (e )
186
209
pass
187
210
188
- # If all fails, return an empty config
211
+ log . debug ( "All parsing attempts failed - returning empty config" )
189
212
return {}
0 commit comments