Make sure self references are showing as base images
This commit is contained in:
Родитель
839925c997
Коммит
6db7bb2cf4
|
@ -53,7 +53,7 @@ func ForCvesAndBaseImagesAsync(sb *types.Sbom, includeCves bool, includeBaseImag
|
|||
wg.Add(2)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
bi, err := ForBaseImageInGraphQL(sb.Source.Image.Config, true)
|
||||
bi, err := ForBaseImageInGraphQL(sb.Source.Image.Config)
|
||||
if err != nil {
|
||||
resultChan <- queryResult{
|
||||
Error: err,
|
||||
|
@ -95,5 +95,23 @@ func ForCvesAndBaseImagesAsync(sb *types.Sbom, includeCves bool, includeBaseImag
|
|||
}
|
||||
}
|
||||
|
||||
// filter out input image from the list of base images
|
||||
if sb.Source.Image.Details != nil && len(sb.Source.BaseImages) > 0 {
|
||||
digest := sb.Source.Image.Details.Digest
|
||||
baseImages := make([]types.BaseImageMatch, 0)
|
||||
for _, b := range sb.Source.BaseImages {
|
||||
selfRef := false
|
||||
for _, i := range b.Images {
|
||||
if i.Digest == digest {
|
||||
selfRef = true
|
||||
}
|
||||
}
|
||||
if !selfRef {
|
||||
baseImages = append(baseImages, b)
|
||||
}
|
||||
}
|
||||
sb.Source.BaseImages = baseImages
|
||||
}
|
||||
|
||||
return sb
|
||||
}
|
||||
|
|
|
@ -217,14 +217,11 @@ func ForRepositoryInDb(repo string, workspace string, apiKey string) (*types.Rep
|
|||
}
|
||||
}
|
||||
|
||||
func ForBaseImageInGraphQL(cfg *v1.ConfigFile, excludeSelf bool) (*types.BaseImagesByDiffIdsQuery, error) {
|
||||
func ForBaseImageInGraphQL(cfg *v1.ConfigFile) (*types.BaseImagesByDiffIdsQuery, error) {
|
||||
diffIds := make([]graphql.ID, 0)
|
||||
for _, d := range cfg.RootFS.DiffIDs {
|
||||
diffIds = append(diffIds, graphql.ID(d.String()))
|
||||
}
|
||||
if excludeSelf {
|
||||
// diffIds = diffIds[0 : len(diffIds)-1]
|
||||
}
|
||||
|
||||
if len(diffIds) == 0 {
|
||||
return nil, nil
|
||||
|
|
Загрузка…
Ссылка в новой задаче