From ac6aa4e306b1431b6db89158e25ed4c2c5a356bd Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Fri, 22 Dec 2023 09:50:46 +0100 Subject: [PATCH] bug: ctl: handle non-existing bot modules the new function utils.get_bot_module_name returns None if a bot module does not exist, and importlib.import_module raises an exception when passed None --- intelmq/bin/intelmqctl.py | 6 ++++++ intelmq/lib/utils.py | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/intelmq/bin/intelmqctl.py b/intelmq/bin/intelmqctl.py index 2add4b82e..9ad9266d0 100644 --- a/intelmq/bin/intelmqctl.py +++ b/intelmq/bin/intelmqctl.py @@ -941,6 +941,12 @@ def check(self, no_connections=False, check_executables=True): check_logger.error('SyntaxError in bot %r: %r', bot_id, exc) retval = 1 continue + except AttributeError: + # if module does not exist, utils.get_bot_module_name returns None. import_module then raises + # AttributeError: 'NoneType' object has no attribute 'startswith' + check_logger.error('Incomplete installation: Bot %r not importable.', bot_id,) + retval = 1 + continue bot = getattr(bot_module, 'BOT') bot_parameters = copy.deepcopy(global_settings) bot_parameters.update(bot_config.get('parameters', {})) # the parameters field may not exist diff --git a/intelmq/lib/utils.py b/intelmq/lib/utils.py index 5701db1af..294f4107a 100644 --- a/intelmq/lib/utils.py +++ b/intelmq/lib/utils.py @@ -852,7 +852,10 @@ def _get_console_entry_points(): return entries.get("console_scripts", []) # it's a dict -def get_bot_module_name(bot_name: str) -> str: +def get_bot_module_name(bot_name: str) -> Optional[str]: + """ + Returns None if the bot does not exist + """ entries = entry_points() if hasattr(entries, "select"): entries = tuple(entries.select(name=bot_name, group="console_scripts"))