kubescape / storage

Apache License 2.0
1 stars 6 forks source link

Fix MetadataType in artifacts #108

Closed dwertent closed 3 months ago

dwertent commented 3 months ago

User description

Sorry, we do not accept changes directly against this repository. Please see CONTRIBUTING.md for information on where and how to contribute instead.


Type

bug_fix, tests


Description


Changes walkthrough

Relevant files
Bug fix
syfttypes.go
Set MetadataType in SyftPackage Unpacking                               

pkg/apis/softwarecomposition/syfttypes.go - Explicitly set `MetadataType` based on the determined type.
+1/-0     
syfttypes.go
Set MetadataType in SyftPackage Unpacking for v1beta1       

pkg/apis/softwarecomposition/v1beta1/syfttypes.go - Explicitly set `MetadataType` based on the determined type.
+1/-0     
Tests
syfttypes_test.go
Add Tests for SyftPackage JSON Unmarshalling                         

pkg/apis/softwarecomposition/syfttypes_test.go
  • Added new tests for SyftPackage JSON unmarshalling.
  • Validates MetadataType and ID fields after unmarshalling.
  • +41/-0   

    PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    codiumai-pr-agent[bot] commented 3 months ago

    PR Description updated to latest commit (https://github.com/kubescape/storage/commit/1a921cf0da421c17eb6732eb86cb9bda559a62c9)

    codiumai-pr-agent[bot] commented 3 months ago

    PR Review

    ⏱️ Estimated effort to review [1-5] 2, because the changes are straightforward and localized to specific functions, but require understanding of the existing data structures and their usage in the system. The addition of tests helps in validating the changes made.
    🧪 Relevant tests Yes
    🔍 Possible issues Possible Bug: Ensure that the `MetadataType` assignment does not override any existing data unintentionally. It seems like `MetadataType` is now being explicitly set, which is good, but there should be checks to ensure this does not lead to data integrity issues if `MetadataType` was already set by some other means.
    🔒 Security concerns No

    ✨ Review tool usage guide:
    **Overview:** The `review` tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be [added](https://pr-agent-docs.codium.ai/tools/review/#general-configurations) by configuring the tool. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on any PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L23) related to the review tool (`pr_reviewer` section), use the following template: ``` /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_reviewer] some_config1=... some_config2=... ``` See the review [usage page](https://pr-agent-docs.codium.ai/tools/review/) for a comprehensive guide on using this tool.
    codiumai-pr-agent[bot] commented 3 months ago

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Best practice
    Ensure p.MetadataType is not set to an empty string. ___ **Consider checking if ty is not an empty string before assigning it to p.MetadataType. This
    ensures that p.MetadataType is not unintentionally set to an empty value, which could lead
    to unexpected behavior or errors in downstream processing.** [pkg/apis/softwarecomposition/syfttypes.go [326]](https://github.com/kubescape/storage/pull/108/files#diff-4d4a17b456526172028f75509a8e9a0a2b72d2566873a7c0a83a59261b02de5fR326-R326) ```diff -p.MetadataType = ty +if ty != "" { + p.MetadataType = ty +} ```
    Ensure p.MetadataType is not set to an empty string in v1beta1. ___ **Similar to the suggestion made for syfttypes.go, consider checking if ty is not an empty
    string before assigning it to p.MetadataType in v1beta1/syfttypes.go. This consistency
    across versions helps in maintaining the integrity of the metadata type assignment.** [pkg/apis/softwarecomposition/v1beta1/syfttypes.go [326]](https://github.com/kubescape/storage/pull/108/files#diff-007ef636e3e3645c3872a86698fa7c52323e62cae03755761ff27df69bd67722R326-R326) ```diff -p.MetadataType = ty +if ty != "" { + p.MetadataType = ty +} ```
    Enhancement
    Add test cases for edge cases in metadataType. ___ **It's recommended to add a test case where metadataType is an empty string or an unexpected
    value. This will help ensure that your code robustly handles edge cases and maintains
    correct behavior under various inputs.** [pkg/apis/softwarecomposition/syfttypes_test.go [25-30]](https://github.com/kubescape/storage/pull/108/files#diff-0de18d26e7883822db933987055aa72aae954c3f39ffab9989afa78979497f80R25-R30) ```diff { - name: "TestUpdateSBOMSyft", + name: "TestUpdateSBOMSyft with empty metadataType", input: artifact, - args: args{id: "8a49897e59f569c2", metadataType: "dpkg-db-entry"}, - wantErr: false, + args: args{id: "8a49897e59f569c2", metadataType: ""}, + wantErr: true, // Assuming the function should error out on empty metadataType } ```

    ✨ Improve tool usage guide:
    **Overview:** The `improve` tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on a PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L78) related to the improve tool (`pr_code_suggestions` section), use the following template: ``` /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_code_suggestions] some_config1=... some_config2=... ``` See the improve [usage page](https://pr-agent-docs.codium.ai/tools/improve/) for a comprehensive guide on using this tool.