@@ -278,18 +278,23 @@ def get_download_plugin(self, product: EOProduct) -> Union[Download, Api]:
278278 if api := getattr (plugin_conf , "api" , None ):
279279 plugin_conf .api .products = plugin_conf .products
280280 plugin_conf .api .priority = plugin_conf .priority
281- plugin = cast (Api , self ._build_plugin (product .provider , api , Api ))
281+ return cast (Api , self ._build_plugin (product .provider , api , Api ))
282282 elif getattr (plugin_conf , "download" , None ):
283283 plugin = next (
284284 self .get_auth_or_download_plugins (
285285 "download" , product .provider , matching_url = matching_url
286286 )
287287 )
288+ if not isinstance (plugin , Download ):
289+ # basically this should not happen
290+ raise MisconfiguredError (
291+ f"Invalid download plugin for provider { plugin_conf .name } "
292+ )
293+ return plugin
288294 else :
289295 raise MisconfiguredError (
290296 f"No download plugin configured for provider { plugin_conf .name } ."
291297 )
292- return plugin
293298
294299 def get_auth_plugin (
295300 self , associated_plugin : PluginTopic , product : Optional [EOProduct ] = None
@@ -307,7 +312,7 @@ def get_auth_plugin(
307312 :returns: The Authentication plugin
308313 """
309314 # matching url from product to download
310- matching_url = ""
315+ matching_url = None
311316 if product :
312317 matching_url = _get_matching_url_for_product (product )
313318 if not matching_url :
@@ -323,6 +328,11 @@ def get_auth_plugin(
323328 matching_conf = associated_plugin .config ,
324329 )
325330 )
331+ if not isinstance (auth_plugin , Authentication ):
332+ # basically this should not happen
333+ raise MisconfiguredError (
334+ f"Invalid auth plugin found: { auth_plugin .config } "
335+ )
326336 except StopIteration :
327337 auth_plugin = None
328338 return auth_plugin
@@ -333,7 +343,7 @@ def get_auth_or_download_plugins(
333343 provider : str ,
334344 matching_url : Optional [str ] = None ,
335345 matching_conf : Optional [PluginConfig ] = None ,
336- ) -> Iterator [Authentication ]:
346+ ) -> Iterator [Union [ Authentication , Download ] ]:
337347 """Build and return the authentication plugin for the given provider and
338348 matching conf or url
339349
@@ -379,18 +389,17 @@ def get_auth_or_download_plugins(
379389 ):
380390 plugin_conf .priority = provider_conf .priority
381391 if plugin_type == "auth" :
382- plugin = cast (
392+ yield cast (
383393 Authentication ,
384394 self ._build_plugin (
385395 plugin_provider , plugin_conf , Authentication
386396 ),
387397 )
388398 else :
389- plugin = cast (
399+ yield cast (
390400 Download ,
391401 self ._build_plugin (plugin_provider , plugin_conf , Download ),
392402 )
393- yield plugin
394403 else :
395404 continue
396405
@@ -419,7 +428,11 @@ def get_auth(
419428 ):
420429 # not the plugin we were looking for
421430 continue
422- if auth_plugin and callable (getattr (auth_plugin , "authenticate" , None )):
431+ if (
432+ auth_plugin
433+ and isinstance (auth_plugin , Authentication )
434+ and callable (getattr (auth_plugin , "authenticate" , None ))
435+ ):
423436 try :
424437 auth = auth_plugin .authenticate ()
425438 return auth
0 commit comments