Skip to content

Commit 01f5f08

Browse files
patrick.rissmann@l3montree.compatrick.rissmann@l3montree.com
authored andcommitted
Fixed bug where load components only returns components found by the same scanner and not by others
1 parent ad93864 commit 01f5f08

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

internal/core/assetversion/asset_version_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ func buildBomRefMap(bom normalize.SBOM) map[string]cdx.Component {
336336

337337
func (s *service) UpdateSBOM(assetVersion models.AssetVersion, scannerID string, sbom normalize.SBOM) error {
338338
// load the asset components
339-
scannerID = "AdditionalScanner"
340-
assetComponents, err := s.componentRepository.LoadComponents(nil, assetVersion.Name, assetVersion.AssetID, scannerID)
339+
340+
assetComponents, err := s.componentRepository.LoadComponents(nil, assetVersion.Name, assetVersion.AssetID, "")
341341
if err != nil {
342342
return errors.Wrap(err, "could not load asset components")
343343
}

internal/database/repositories/component_repository.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,27 @@ func (c *componentRepository) HandleStateDiff(tx core.DB, assetVersionName strin
200200
needToBeChanged := comparison.InBoth
201201

202202
return c.GetDB(tx).Transaction(func(tx *gorm.DB) error {
203+
//We remove the scanner id from all components in removed and if it was the only scanner id we remove the component
203204
dependenciesToUpdate, err := removeScannerIDFromComponents(tx, c, removed, scannerID)
204205
if err != nil {
205206
return err
206207
}
208+
209+
//Now we want to update the database with the new scanner id values
207210
if len(dependenciesToUpdate) > 0 {
208211
err := c.db.Save(dependenciesToUpdate).Error
209212
if err != nil {
210213
return err
211214
}
212215
}
213216

217+
//Next step is adding the scanner id to all existing component dependencies we just found
214218
for i := range needToBeChanged {
215219
if !strings.Contains(needToBeChanged[i].ScannerIDs, scannerID) {
216220
needToBeChanged[i].ScannerIDs = needToBeChanged[i].ScannerIDs + scannerID + " "
217221
}
218222
}
223+
//We also need to update these changes in the database
219224
if len(needToBeChanged) > 0 {
220225
err := c.db.Save(needToBeChanged).Error
221226
if err != nil {
@@ -229,6 +234,7 @@ func (c *componentRepository) HandleStateDiff(tx core.DB, assetVersionName strin
229234
added[i].AssetVersionName = assetVersionName
230235
}
231236

237+
//At last we create all the new component dependencies
232238
return c.CreateComponents(tx, added)
233239
})
234240
}

0 commit comments

Comments
 (0)