-
Notifications
You must be signed in to change notification settings - Fork 4
Add plugin support for download resolving #129
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
Draft
Urist-McGit
wants to merge
10
commits into
main
Choose a base branch
from
feat/plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+372
−179
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7d6c736
chore(snapshot): remove unnecessary shebang
Urist-McGit 146b8cd
refactor(download): generalize upstream resolver logic
Urist-McGit 4405339
refactor(download): only use required fields from the remote file
Urist-McGit 8b6a609
feat(download): add --resolver option
Urist-McGit da87013
feat(download): make cache unique for each resolver
Urist-McGit 4ffda73
refactor(download): make cache replaceable
Urist-McGit ae46320
refactor(download): upcast remotefile cache entries
Urist-McGit 688fa71
refactor(download): introduce base exception for resolve errors
Urist-McGit c958df0
feat(download): add plugin functionality for resolvers
Urist-McGit d6e7657
chore(download): improve error message for resolve failures
Urist-McGit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ debsbom documentation | |
| design-decisions | ||
| commands | ||
| examples | ||
| plugins | ||
| api | ||
|
|
||
| Indices and tables | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| Plugins | ||
| ======= | ||
|
|
||
| ``debsbom`` provides plugin capability for select functionality. | ||
|
|
||
| Resolver Plugin | ||
| --------------- | ||
|
|
||
| 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). | ||
|
|
||
| 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``. | ||
|
|
||
| A resolver plugin provides an additional choice for the ``--resolver`` option, which can be selected in the CLI once the plugin is loaded. | ||
|
|
||
| Implementing a Resolver Plugin | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| 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: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from request import Session | ||
| from debsbom.download.plugin import Resolver | ||
|
|
||
| def setup_resolver(session: Session) -> Resolver | ||
| pass | ||
|
|
||
| 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. | ||
|
|
||
| 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: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from request import Session | ||
| from debsbom.download.plugin import Package, RemoteFile, Resolver, ResolveError | ||
|
|
||
| class MyResolver(Resolver): | ||
|
|
||
| def resolve(self, pkg: Package) -> list[RemoteFile]: | ||
| try: | ||
| my_remotefile = get_remotefile(pkg) | ||
| except Exception as e: | ||
| raise ResolveError | ||
| return my_remotefile | ||
|
|
||
| All functionality required for implementing a plugin is exposed in the ``debsbom.download.plugin`` module. | ||
|
|
||
| A full example implementation can be found in the ``debsbom_plugin_examples`` repository, which is kept up to date for all releases: TODO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Copyright (C) 2025 Siemens | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| from .resolver import RemoteFile, ResolveError, Resolver | ||
| from ..dpkg.package import Package |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.