intelmq icon indicating copy to clipboard operation
intelmq copied to clipboard

Check missing requirements in `check` command

Open kamil-certat opened this issue 2 years ago • 0 comments

Currently, bots check their requirements only during startup. It would be helpful, if the check() method of bots does it as well, so we'll get the clear information when verifying IntelMQ installation. Probably it would be also useful to have a helper that gets the modules and versions, and can be then reused.

Pseudo-code idea:

# importing with fallback to None as usual
try:
   import requests
except ImportError:
  requests = None

from intelmq.lib.utils import DependencyValidator

deps = DependencyValidator()
deps.register(module=requests, version=(1, 1, 1), validator=lambda module, version: module.__version__ >= version)
# ^ validator only optional when the package has some non-standard version check or so

# ...  in init()
    deps.validate(raise=True)

# ... in check()
    errors.extend(deps.validate(raise=False))

Maybe it would be even possible to do a method for dependency auto-discovery from corresponding REQUIREMENTS.txt file - but this could be tricky.

kamil-certat avatar Sep 20 '23 08:09 kamil-certat