Skip to content

Refactor resources - save SBOM on disk#45

Merged
dwertent merged 5 commits into
mainfrom
refactor-resources
Apr 16, 2023
Merged

Refactor resources - save SBOM on disk#45
dwertent merged 5 commits into
mainfrom
refactor-resources

Conversation

@rcohencyberarmor
Copy link
Copy Markdown
Contributor

Overview

rcohen added 3 commits March 30, 2023 16:53
Signed-off-by: rcohen <rcohen@armosec.io>
Signed-off-by: rcohen <rcohen@armosec.io>
@github-advanced-security
Copy link
Copy Markdown

You have successfully added a new CodeQL configuration .github/workflows/pr-created.yaml:Environment-Test. As part of the setup process, we have scanned this repository and found no existing alerts. In the future, you will see all code scanning alerts on the repository Security tab.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 2, 2023

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

Copy link
Copy Markdown

@dwertent dwertent left a comment

Choose a reason for hiding this comment

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

You made changes in 6 different files but did not change any unit tests.
This means the code is missing many unit tests.

Since the proposed changes involve re-filtering the SBOM', and as the PR indicates that we are "refactoring", I expect to see unit tests.

Comment thread pkg/sbom/v1/sbom_spdx_storage_format.go Outdated
func init() {
wd, err := os.Getwd()
if err != nil {
logger.L().Ctx(context.GetBackgroundContext()).Error("failed to get working directory", helpers.Error(err))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I suggest this function should return an error in case of an error.

}
spdxDataDirPath = fmt.Sprintf("%s/%s", wd, directorySBOM)
err = os.MkdirAll(spdxDataDirPath, os.ModeDir|os.ModePerm)
if err != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What will happen in such a case? Do we want the nodeAgent to panic?
Here you just print an error without doing anything.
If the program will continue running, then it is not an error.

Comment thread pkg/sbom/v1/sbom_spdx_storage_format.go Outdated
instanceID instanceidhandler.IInstanceID
}

func init() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add unitests.

}
}

func (sbom *SBOMData) saveSBOM(spdxData *spdxv1beta1.SBOMSPDXv2p3) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add unitest

}

func CreateSBOMDataSPDXVersionV040() *SBOMData {
func CreateSBOMDataSPDXVersionV040(instanceID instanceidhandler.IInstanceID) SBOMFormat {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add unitest

Comment thread pkg/sbom/v1/sbom_spdx_storage_format.go Outdated
return nil
}

func (sbom *SBOMData) getSBOMData() (*spdxv1beta1.SBOMSPDXv2p3, error) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unitests...

}
}

func (sc *SBOMData) CleanResources() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add unitest.

Comment thread pkg/sbom/v1/sbom_spdx_storage_format.go Outdated
func (sc *SBOMData) CleanResources() {
err := os.Remove(sc.spdxDataPath)
if err != nil {
logger.L().Warning("fail to remove file", helpers.String("file name", sc.spdxDataPath), helpers.Error(err))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this be a warning? When will this operation fail and why?

Comment thread pkg/sbom/v1/sbom_spdx_storage_format.go Outdated
func (sbom *SBOMData) FilterSBOM(sbomFileRelevantMap map[string]bool) error {
sbom.newRelevantData = false

spdxData, err := sbom.getSBOMData()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm confused, you named the function SBOMData, then you name the local variable spdxData.
Is the FilterSBOM a converter from one format to another?

return &spdxData, nil
}

func (sbom *SBOMData) FilterSBOM(sbomFileRelevantMap map[string]bool) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a really important function.
Add unitests for it.

rcohen added 2 commits April 3, 2023 14:09
Signed-off-by: rcohen <rcohen@armosec.io>
Signed-off-by: rcohen <rcohen@armosec.io>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 3, 2023

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

@dwertent dwertent merged commit 1914210 into main Apr 16, 2023
@dwertent dwertent deleted the refactor-resources branch July 30, 2023 07:21
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.

3 participants