mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 04:48:26 +08:00
Include image vulnerability information in ImageSummary (#798)
Return this data as part of GlobalSearch and RepoListWithNewestImage query results. This commit also includes refactoring of the CVE scanning logic in order to better encapsulate trivy specific logic, remove CVE scanning logic from the graphql resolver. Signed-off-by: Andrei Aaron <andaaron@cisco.com>
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"zotregistry.io/zot/pkg/extensions/search/common"
|
||||
cveinfo "zotregistry.io/zot/pkg/extensions/search/cve"
|
||||
cvemodel "zotregistry.io/zot/pkg/extensions/search/cve/model"
|
||||
)
|
||||
|
||||
type CveInfoMock struct {
|
||||
GetImageListForCVEFn func(repo, cveID string) ([]cveinfo.ImageInfoByCVE, error)
|
||||
GetImageListWithCVEFixedFn func(repo, cveID string) ([]common.TagInfo, error)
|
||||
GetCVEListForImageFn func(image string) (map[string]cvemodel.CVE, error)
|
||||
GetCVESummaryForImageFn func(image string) (cveinfo.ImageCVESummary, error)
|
||||
UpdateDBFn func() error
|
||||
}
|
||||
|
||||
func (cveInfo CveInfoMock) GetImageListForCVE(repo, cveID string) ([]cveinfo.ImageInfoByCVE, error) {
|
||||
if cveInfo.GetImageListForCVEFn != nil {
|
||||
return cveInfo.GetImageListForCVEFn(repo, cveID)
|
||||
}
|
||||
|
||||
return []cveinfo.ImageInfoByCVE{}, nil
|
||||
}
|
||||
|
||||
func (cveInfo CveInfoMock) GetImageListWithCVEFixed(repo, cveID string) ([]common.TagInfo, error) {
|
||||
if cveInfo.GetImageListWithCVEFixedFn != nil {
|
||||
return cveInfo.GetImageListWithCVEFixedFn(repo, cveID)
|
||||
}
|
||||
|
||||
return []common.TagInfo{}, nil
|
||||
}
|
||||
|
||||
func (cveInfo CveInfoMock) GetCVEListForImage(image string) (map[string]cvemodel.CVE, error) {
|
||||
if cveInfo.GetCVEListForImageFn != nil {
|
||||
return cveInfo.GetCVEListForImageFn(image)
|
||||
}
|
||||
|
||||
return map[string]cvemodel.CVE{}, nil
|
||||
}
|
||||
|
||||
func (cveInfo CveInfoMock) GetCVESummaryForImage(image string) (cveinfo.ImageCVESummary, error) {
|
||||
if cveInfo.GetCVESummaryForImageFn != nil {
|
||||
return cveInfo.GetCVESummaryForImageFn(image)
|
||||
}
|
||||
|
||||
return cveinfo.ImageCVESummary{}, nil
|
||||
}
|
||||
|
||||
func (cveInfo CveInfoMock) UpdateDB() error {
|
||||
if cveInfo.UpdateDBFn != nil {
|
||||
return cveInfo.UpdateDBFn()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type CveScannerMock struct {
|
||||
IsImageFormatScannableFn func(image string) (bool, error)
|
||||
ScanImageFn func(image string) (map[string]cvemodel.CVE, error)
|
||||
CompareSeveritiesFn func(severity1, severity2 string) int
|
||||
UpdateDBFn func() error
|
||||
}
|
||||
|
||||
func (scanner CveScannerMock) IsImageFormatScannable(image string) (bool, error) {
|
||||
if scanner.IsImageFormatScannableFn != nil {
|
||||
return scanner.IsImageFormatScannableFn(image)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (scanner CveScannerMock) ScanImage(image string) (map[string]cvemodel.CVE, error) {
|
||||
if scanner.ScanImageFn != nil {
|
||||
return scanner.ScanImageFn(image)
|
||||
}
|
||||
|
||||
return map[string]cvemodel.CVE{}, nil
|
||||
}
|
||||
|
||||
func (scanner CveScannerMock) CompareSeverities(severity1, severity2 string) int {
|
||||
if scanner.CompareSeveritiesFn != nil {
|
||||
return scanner.CompareSeveritiesFn(severity1, severity2)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func (scanner CveScannerMock) UpdateDB() error {
|
||||
if scanner.UpdateDBFn != nil {
|
||||
return scanner.UpdateDBFn()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -13,7 +13,6 @@ type OciLayoutUtilsMock struct {
|
||||
GetImageManifestsFn func(image string) ([]ispec.Descriptor, error)
|
||||
GetImageBlobManifestFn func(imageDir string, digest godigest.Digest) (v1.Manifest, error)
|
||||
GetImageInfoFn func(imageDir string, hash v1.Hash) (ispec.Image, error)
|
||||
IsValidImageFormatFn func(image string) (bool, error)
|
||||
GetImageTagsWithTimestampFn func(repo string) ([]common.TagInfo, error)
|
||||
GetImageLastUpdatedFn func(imageInfo ispec.Image) time.Time
|
||||
GetImagePlatformFn func(imageInfo ispec.Image) (string, string)
|
||||
@@ -28,7 +27,7 @@ type OciLayoutUtilsMock struct {
|
||||
}
|
||||
|
||||
func (olum OciLayoutUtilsMock) GetRepositories() ([]string, error) {
|
||||
if olum.GetImageManifestsFn != nil {
|
||||
if olum.GetRepositoriesFn != nil {
|
||||
return olum.GetRepositoriesFn()
|
||||
}
|
||||
|
||||
@@ -59,14 +58,6 @@ func (olum OciLayoutUtilsMock) GetImageInfo(imageDir string, hash v1.Hash) (ispe
|
||||
return ispec.Image{}, nil
|
||||
}
|
||||
|
||||
func (olum OciLayoutUtilsMock) IsValidImageFormat(image string) (bool, error) {
|
||||
if olum.IsValidImageFormatFn != nil {
|
||||
return olum.IsValidImageFormatFn(image)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (olum OciLayoutUtilsMock) GetImageTagsWithTimestamp(repo string) ([]common.TagInfo, error) {
|
||||
if olum.GetImageTagsWithTimestampFn != nil {
|
||||
return olum.GetImageTagsWithTimestampFn(repo)
|
||||
|
||||
Reference in New Issue
Block a user