Skip to content

Feature/issue195 - #224

Merged
san-zrl merged 9 commits into
cbomkit:mainfrom
fynnth:feature/Issue195
Jun 16, 2025
Merged

san-zrl merged 9 commits into
cbomkit:mainfrom
fynnth:feature/Issue195

Conversation

@fynnth

@fynnth fynnth commented Jun 10, 2025 •

Copy link
Copy Markdown
Contributor

Implements the Endpoints from #195. Please check carefully if that fits your expectations regarding this issue, since I have no experience as a java developer.

I took the freedom and decided that manual uploads with POST will be marked with "manual-upload-{UUID}" where the UUID is the same as the id of the entry. I hope that fits with you, otherwise please change it to whatever you like. Also no real unit-tests were done, so there might be some unforseen bugs.

@fynnth
fynnth requested a review from a team June 10, 2025 14:05
@fynnth

fynnth commented Jun 11, 2025

Copy link
Copy Markdown
Contributor Author

I did not see that signing is required for this project, sorry! Should I rebase and make another PR or is it not that important?

@san-zrl san-zrl left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @fynnth,

Thanks a lot for your PR! I partially tested it with the the built-in Swagger UI and, unfortunately, it does not quite work as expected. Here is what I did:

I have a local CBOMkit instance running with a few CBOMs in its inventory. I tested your DELETE and GET endpoints. The strategy was first to delete a certain CBOM by its identifier so that a subsequent GET call for this identifier shouldn't return a result (because the CBOM has been deleted).

The DELETE call returned a 200 {"status":"CBOM deleted"}. This looked promising but the GET call got stuck and never returned.

I checked the logs and saw:

2025-06-11 11:05:22,849 INFO  [com.ibm.inf.CommandBus] (executor-thread-1) sending command DeleteCBOMCommand[projectIdentifier=pkg:maven/com.fasterxml.jackson.core/[email protected]?type=jar]
2025-06-11 11:05:22,850 ERROR [com.ibm.inf.CommandBus] (pool-8-thread-3) Invalid command type

I checked the database and the deletion did not happen despite the success message. The error message indicates that the command handler registration didn't work and hence we get an "Invalid command type" error (and nothing has been deleted).

Please take a look at the com.ibm.usecases.database.queries.ListStoredCBOMsQueryHandler class which implements the command handler for the /api/v1/cbom/last/{limit} endpoint. This contains an onStart method which registers the handler with the IQuery bus. If you implement your handlers this way you also don't have to explicitly inject them as you did in the CBOMResource class (and hence no dummy objects). In fact, the ListStoredCBOMsQueryHandler gets created and registered implicitly and it's never used directly in our code.

You can easily test your PR via Swagger. The URL would be (http://localhost:8081/q/swagger-ui/) if you run the backend locally.

@san-zrl

san-zrl commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

I did not see that signing is required for this project, sorry! Should I rebase and make another PR or is it not that important?

That's ok.

@fynnth

fynnth commented Jun 11, 2025 •

Copy link
Copy Markdown
Contributor Author

Hi @san-zrl,

Thanks for the quick check!
I’ll definitely improve with the onStart method.

However, it seems like the GET method always hangs when called with a non-existent ID. I’ve completely restarted the database and rebuilt everything from scratch, and when I try to GET an ID that doesn’t exist, that seems to be the default behavior for me — after that, Swagger keeps loading indefinitely, and the command line shows the same behavior.
image

Also, the DELETE method doesn’t return a 404 when the identifier doesn’t exist (which I will fix), but it does remove existing entries from the CBOMReadModel table on my system.
It needs to be URL-encoded to work from the command line — maybe that’s the reason it wasn’t deleted in your test? Otherwise, I can’t reproduce the issue. From Swagger UI, it works consistently for me:

  1. DB contains pkg:github/fasterxml/jackson-annotations@e40494c?branch=2.3

image

  1. Delete is executed with pkg:github/fasterxml/jackson-annotations@e40494c?branch=2.3 as parameter.

image

  1. DB does not contain pkg:github/fasterxml/jackson-annotations@e40494c?branch=2.3

image

I’m a bit unsure about what caused the deletion to fail on your side — could you check again whether URL encoding was the issue? Also is the behavior of the GET function only like this for me?
Sorry for the extra unnecessary work.

@san-zrl

san-zrl commented Jun 11, 2025 •

Copy link
Copy Markdown
Contributor

Hi @fynnth ,

I have to correct myself - it's a bit more complex.

I don't think the problem is related to URL encoding since swagger does that for us AFAIK. I only tested via swagger and this is the behavior I see:

  1. GET on an existing id works.
  2. DELETE on an existing id works. It sends a success msg which is okay - but it also generates above log error.
  3. GET on a non-existing id hangs. Should send a 404.
  4. DELETE on a non-existing id sends the success msg and generates the log error. Should send a 404.

@fynnth

fynnth commented Jun 11, 2025 •

Copy link
Copy Markdown
Contributor Author

Hi @san-zrl,

I think the latest commit should fix the problems by:

  1. adding a try/catch for the QueryBus and the GET method -> GET should now return 404 when a projectidentifier does not exist
  2. Removing wrong logging output for Delete/Post-Commands -> no longer invalid command message
  3. Delete now checks properly if rescource exists -> returns 404 if not
  4. Uses the onStart method -> no dummy/inject anymore

For me everything runs through without any errors or wrong logging messages. I tested all implemented endpoints with swagger and with the commandline. Since I made changes to the QueryBus please check that those do not disrupt any other functionality that might use it.
-> Hopefully this time it works without any issues. Once again sorry for the trouble with this PR.

@san-zrl

san-zrl commented Jun 12, 2025 •

Copy link
Copy Markdown
Contributor

Hi @fynnth - Thanks a lot for the update and the work you put into this PR.

I tested

  • GET: works as expected
  • DELETE works as expected
  • scan: works as expected
  • POST: works but may I ask for two improvements?
  1. The POST method takes any json input and happily stores it in our database. If it is not a proper CBOM object we get an inconsistent inventory. Could you check that it is valid CBOM and send a 400 if not? Below is a code snippet
        try {
            byte[] cbomBytes = cbomString.getBytes(StandardCharsets.UTF_8);
            Parser parser = BomParserFactory.createParser(cbomBytes);
            Bom cycloneDXbom = parser.parse(cbomBytes);
        } catch (ParseException e) {
            // send response code 400
        }
  1. The CBOM objects created by our scanner set some metadata that we use to associate the CBOM with a github repo. Strictly speaking this is optional and may not exist in CBOMs we get from elsewhere. For conveniently loading CBOMkit CBOMs it would be super helpful if you could check if the Metadata object exists and, if so, extract the properties. Here's such a metadata object produced by CBOMkit:
    "metadata": {
      "timestamp": "2025-06-12T09:00:41Z",
      "properties": [
        {
          "name": "gitUrl",
          "value": "https://github.com/FasterXML/jackson-core"
        },
        {
          "name": "revision",
          "value": "2.13.4"
        },
        {
          "name": "commit",
          "value": "e9598e5"
        },
        {
          "name": "subfolder",
          "value": ""
        }
      ]
    }

The metadata are located at top level of the BOM object. Thy can be accessed very easily via the cycloneDXbom above. If existing, the properties should go into repository, revision, packageFolder and commit parameters of the CBOMReadModel constructor.

@fynnth

fynnth commented Jun 12, 2025

Copy link
Copy Markdown
Contributor Author

Hi @san-zrl ,

I've refined the POST method and tested it with several CBOMs and SBOMs I had on my laptop. Please check whether the changes in the latest commit align with what you had in mind and if it works well for you.

@san-zrl

san-zrl commented Jun 12, 2025

Copy link
Copy Markdown
Contributor

Hi @fynnth - great work! Thank you very much once again.

@san-zrl
san-zrl merged commit cacb428 into cbomkit:main Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants