Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discover bots based on the entry points #2413

Merged
merged 14 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
SPDX-License-Identifier: AGPL-3.0-or-later
"""

# Use your package as usual
from mybots.lib import common

from intelmq.lib.bot import CollectorBot
kamil-certat marked this conversation as resolved.
Show resolved Hide resolved


Expand All @@ -14,7 +17,7 @@ class ExampleAdditionalCollectorBot(CollectorBot):
def process(self):
report = self.new_report()
if self.raw: # noqa: Set as parameter
report['raw'] = 'test'
report['raw'] = common.return_value('example')
self.send_message(report)


Expand Down
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Depends: bash-completion,
python3-ruamel.yaml,
python3-termstyle (>= 0.1.10),
python3-tz,
python3-importlib-metadata,
kamil-certat marked this conversation as resolved.
Show resolved Hide resolved
redis-server,
systemd,
${misc:Depends},
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ bots work with IntelMQ, you need to ensure that

Apart from these requirements, your package can use any of the usual package features. We strongly
recommend following the same principles and main guidelines as the official bots. This will ensure
experience when using official and additional bots.
the same experience when using official and additional bots.

Naming convention
=================
Expand Down
4 changes: 4 additions & 0 deletions docs/user/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Native deb/rpm packages

These are the operating systems which are currently supported by packages:

* **Debian 10** Buster

* Enable the backport repository by the line ``deb-src http://deb.debian.org/debian buster-backports main contrib non-free`` to the file ``/etc/apt/sources.list`` first.
kamil-certat marked this conversation as resolved.
Show resolved Hide resolved

* **Debian 11** Bullseye
* **openSUSE Tumbleweed**
* **Ubuntu 20.04** Focal Fossa
Expand Down
28 changes: 28 additions & 0 deletions intelmq/tests/lib/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
from intelmq.lib.test import skip_internet
from intelmq.tests.test_conf import CerberusTests

try:
from importlib.metadata import EntryPoint
except ImportError:
from importlib_metadata import EntryPoint


LINES = {'spare': ['Lorem', 'ipsum', 'dolor'],
'short': ['{}: Lorem', '{}: ipsum',
'{}: dolor'],
Expand Down Expand Up @@ -318,6 +324,28 @@ def _mock_importing(module):
bot_count = sum([len(val) for val in bots.values()])
self.assertEqual(1, bot_count)

def test_list_all_bots_filters_entrypoints(self):
entries = [
EntryPoint("intelmq.bots.collector.api.collector_api",
"intelmq.bots.collector.api.collector_api:BOT.run", group="console_scripts"),
EntryPoint("intelmq.bots.collector.awesome.my_bot",
"awesome.extension.package.collector:BOT.run", group="console_scripts"),
EntryPoint("not.a.bot", "not.a.bot:run", group="console_scripts")
]

with unittest.mock.patch.object(utils, "_get_console_entry_points", return_value=entries):
with unittest.mock.patch.object(utils.importlib, "import_module") as import_mock:
import_mock.side_effect = SyntaxError() # stop processing after import try
utils.list_all_bots()

import_mock.assert_has_calls(
[
unittest.mock.call("intelmq.bots.collector.api.collector_api"),
unittest.mock.call("awesome.extension.package.collector"),
]
)
self.assertEqual(2, import_mock.call_count)

def test_get_bots_settings(self):
with unittest.mock.patch.object(utils, "get_runtime", new_get_runtime):
runtime = utils.get_bots_settings()
Expand Down