@@ -46,7 +46,7 @@ def resolve_repository_name(repo_name):
4646
4747def resolve_index_name (index_name ):
4848 index_name = convert_to_hostname (index_name )
49- if index_name == 'index.' + INDEX_NAME :
49+ if index_name == 'index.' + INDEX_NAME :
5050 index_name = INDEX_NAME
5151 return index_name
5252
@@ -102,19 +102,34 @@ def encode_header(auth):
102102 return base64 .urlsafe_b64encode (auth_json )
103103
104104
105- def parse_auth (entries ):
105+ def parse_auth (entries , raise_on_error = False ):
106106 """
107107 Parses authentication entries
108108
109109 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
111113
112114 Returns:
113115 Authentication registry.
114116 """
115117
116118 conf = {}
117119 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 {}
118133 username , password = decode_auth (entry ['auth' ])
119134 log .debug (
120135 'Found entry (registry={0}, username={1})'
@@ -170,7 +185,7 @@ def load_config(config_path=None):
170185 res = {}
171186 if data .get ('auths' ):
172187 log .debug ("Found 'auths' section" )
173- res .update (parse_auth (data ['auths' ]))
188+ res .update (parse_auth (data ['auths' ], raise_on_error = True ))
174189 if data .get ('HttpHeaders' ):
175190 log .debug ("Found 'HttpHeaders' section" )
176191 res .update ({'HttpHeaders' : data ['HttpHeaders' ]})
0 commit comments