Make sure self references are showing as base images

This commit is contained in:
Christian Dupuis 2022-11-24 08:21:01 +01:00
Родитель 839925c997
Коммит 6db7bb2cf4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E32B019A8B65E57A
2 изменённых файлов: 20 добавлений и 5 удалений

Просмотреть файл

@ -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