@@ -46,7 +46,7 @@ def resolve_repository_name(repo_name):
46
46
47
47
def resolve_index_name (index_name ):
48
48
index_name = convert_to_hostname (index_name )
49
- if index_name == 'index.' + INDEX_NAME :
49
+ if index_name == 'index.' + INDEX_NAME :
50
50
index_name = INDEX_NAME
51
51
return index_name
52
52
@@ -102,19 +102,34 @@ def encode_header(auth):
102
102
return base64 .urlsafe_b64encode (auth_json )
103
103
104
104
105
- def parse_auth (entries ):
105
+ def parse_auth (entries , raise_on_error = False ):
106
106
"""
107
107
Parses authentication entries
108
108
109
109
Args:
110
- entries: Dict of authentication entries.
110
+ entries: Dict of authentication entries.
111
+ raise_on_error: If set to true, an invalid format will raise
112
+ InvalidConfigFile
111
113
112
114
Returns:
113
115
Authentication registry.
114
116
"""
115
117
116
118
conf = {}
117
119
for registry , entry in six .iteritems (entries ):
120
+ if not (isinstance (entry , dict ) and 'auth' in entry ):
121
+ log .debug (
122
+ 'Config entry for key {0} is not auth config' .format (registry )
123
+ )
124
+ # We sometimes fall back to parsing the whole config as if it was
125
+ # the auth config by itself, for legacy purposes. In that case, we
126
+ # fail silently and return an empty conf if any of the keys is not
127
+ # formatted properly.
128
+ if raise_on_error :
129
+ raise errors .InvalidConfigFile (
130
+ 'Invalid configuration for registry {0}' .format (registry )
131
+ )
132
+ return {}
118
133
username , password = decode_auth (entry ['auth' ])
119
134
log .debug (
120
135
'Found entry (registry={0}, username={1})'
@@ -170,7 +185,7 @@ def load_config(config_path=None):
170
185
res = {}
171
186
if data .get ('auths' ):
172
187
log .debug ("Found 'auths' section" )
173
- res .update (parse_auth (data ['auths' ]))
188
+ res .update (parse_auth (data ['auths' ], raise_on_error = True ))
174
189
if data .get ('HttpHeaders' ):
175
190
log .debug ("Found 'HttpHeaders' section" )
176
191
res .update ({'HttpHeaders' : data ['HttpHeaders' ]})
0 commit comments