Skip to content

Commit

Permalink
bug: ctl: handle non-existing bot modules
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sebix authored and aaronkaplan committed Feb 8, 2024
1 parent 76c08f9 commit ac6aa4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions intelmq/bin/intelmqctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion intelmq/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit ac6aa4e

Please sign in to comment.