feat(uploads): wrap one-shot nomos, monk and ceu scan endpoints#194
Closed
Valyrian-Code wants to merge 1 commit into
Closed
feat(uploads): wrap one-shot nomos, monk and ceu scan endpoints#194Valyrian-Code wants to merge 1 commit into
Valyrian-Code wants to merge 1 commit into
Conversation
Refs fossology#52. Adds three methods to run one-shot scans on a single file without creating a persistent upload: - upload_oneshot_nomos() -> POST /uploads/oneshot/nomos (license) - upload_oneshot_monk() -> POST /uploads/oneshot/monk (license) - upload_oneshot_ceu() -> POST /uploads/oneshot/ceu (copyright/email/URL) Shared multipart logic lives in a private _run_oneshot() helper. Each returns the OneShotInfo result (data findings and highlights). Validated against the OpenAPI spec (API 1.6.2 / Fossology 4.4.0); the multipart field name is "fileInput". Tests cover live happy paths for all three scanners, a mocked payload assertion (field name + parsing) and a mocked 500 error path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: RAJVEER42 <irajveer.bishnoi2310@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR extends the Uploads endpoint wrapper to support Fossology’s “one-shot” scanning APIs, enabling license/copyright scanning of a single local file via multipart upload without creating a persistent upload entry.
Changes:
- Added a shared private helper
_run_oneshot()to POST a local file to/uploads/oneshot/{scanner}using multipart fieldfileInput. - Added three public convenience methods:
upload_oneshot_nomos(),upload_oneshot_monk(), andupload_oneshot_ceu(). - Added integration and mocked tests covering happy paths, multipart payload field name, JSON parsing, and a 500 error path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
fossology/uploads.py |
Adds _run_oneshot() helper and three one-shot scan wrapper methods. |
tests/test_uploads.py |
Adds integration + mocked tests for the new one-shot upload scan endpoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+821
to
+845
| def _run_oneshot(self, scanner: str, file: str) -> dict: | ||
| """Run a one-shot scan on a single file without storing the results. | ||
|
|
||
| :param scanner: the scanner to run ("nomos", "monk" or "ceu") | ||
| :param file: local path to the file to scan | ||
| :type scanner: str | ||
| :type file: str | ||
| :return: the scanner result (``data`` findings and ``highlights``) | ||
| :rtype: dict | ||
| :raises FossologyApiError: if the REST call failed | ||
| """ | ||
| with open(file, "rb") as fp: | ||
| response = self.session.post( # type: ignore | ||
| f"{self.api}/uploads/oneshot/{scanner}", # type: ignore | ||
| files={"fileInput": fp}, | ||
| ) | ||
|
|
||
| if response.status_code == 200: | ||
| logger.info(f"One-shot {scanner} scan completed for {file}") | ||
| return response.json() | ||
|
|
||
| description = f"One-shot {scanner} scan failed for {file}" | ||
| raise FossologyApiError(description, response) | ||
|
|
||
| def upload_oneshot_nomos(self, file: str) -> dict: |
Contributor
Author
|
Closing this after verifying against the fossology 4.4.0 container that CI pins (API 1.6.1): the |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refs #52.
Adds one-shot scan wrappers (
upload_oneshot_nomos/upload_oneshot_monk/upload_oneshot_ceu) forPOST /uploads/oneshot/{scanner}.Closed: these routes are API 1.6.2 / master-only and do not exist in fossology 4.4.0 (the version CI pins), so they 404 there. Will revisit when the CI target includes them.