|
| 1 | +Plugins |
| 2 | +======= |
| 3 | + |
| 4 | +``debsbom`` provides plugin capability for select functionality. |
| 5 | + |
| 6 | +Resolver Plugin |
| 7 | +--------------- |
| 8 | + |
| 9 | +In the ``download`` command ``debsbom`` is downloading packages described by an SBOM. For this it needs to resolve from the package to a download location. What resolver to use can be controlled by the ``--resolver`` flag. ``debsbom`` per default provides a resolver for the Debian snapshot mirror (snapshot.debian.org). |
| 10 | + |
| 11 | +Builders of custom Debian distributions might have different repositories where packages can be downloaded from. Some of these solutions might not be publicly available, or its implementation not relevant for the general public for some other reason. In these cases code for a resolver for these repositories should not land in ``debsbom`` proper, but we still want to give the option to use it as a fully integrated part of ``debsbom``. |
| 12 | + |
| 13 | +A resolver plugin provides an additional choice for the ``--resolver`` option, which can be selected in the CLI once the plugin is loaded. |
| 14 | + |
| 15 | +Implementing a Resolver Plugin |
| 16 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 17 | + |
| 18 | +Plugin discovery happens by entry points. ``debsbom`` specifically looks for the ``debsbom.download.resolver`` entry point. The name of the entry point is the name of the resolver, and its content is a setup function for a resolver. The signature of the setup function looks like this: |
| 19 | + |
| 20 | +.. code-block:: python |
| 21 | +
|
| 22 | + from request import Session |
| 23 | + from debsbom.download.plugin import Resolver |
| 24 | +
|
| 25 | + def setup_resolver(session: Session) -> Resolver |
| 26 | + pass |
| 27 | +
|
| 28 | +The passed in ``request.Session`` is later used by ``debsbom`` to download the packages. It is not required to use it, but consider reusing it instead of opening a new session. |
| 29 | +
|
| 30 | +The resolver itself needs to inherit from the ``Resolver`` class. See the documentation here: :ref:`package-resolving-label`. The important part here is implementing the ``resolve`` function, which takes a package representation and returns a list of ``RemoteFile``, the locations from where files associated with the package can be downloaded. A minimal implementation could look like this: |
| 31 | +
|
| 32 | +.. code-block:: python |
| 33 | +
|
| 34 | + from request import Session |
| 35 | + from debsbom.download.plugin import Package, RemoteFile, Resolver, ResolveError |
| 36 | +
|
| 37 | + class MyResolver(Resolver): |
| 38 | +
|
| 39 | + def resolve(self, pkg: Package) -> list[RemoteFile]: |
| 40 | + try: |
| 41 | + my_remotefile = get_remotefile(pkg) |
| 42 | + except Exception as e: |
| 43 | + raise ResolveError |
| 44 | + return my_remotefile |
| 45 | +
|
| 46 | +All functionality required for implementing a plugin is exposed in the ``debsbom.download.plugin`` module. |
| 47 | + |
| 48 | +A full example implementation can be found in the ``debsbom_plugin_examples`` repository, which is kept up to date for all releases: TODO |
0 commit comments