mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-15 06:58:11 +00:00
* Pretty up the pretty-printer. Signed-off-by: Craig Box <craigb@armosec.io> * add some text fixes for the Operator also Signed-off-by: Craig Box <craigb@armosec.io> * fix another verb Signed-off-by: Craig Box <craigb@armosec.io> * fixed unit tests Signed-off-by: David Wertenteil <dwertent@armosec.io> * fixed test Signed-off-by: David Wertenteil <dwertent@armosec.io> --------- Signed-off-by: Craig Box <craigb@armosec.io> Signed-off-by: David Wertenteil <dwertent@armosec.io> Co-authored-by: David Wertenteil <dwertent@armosec.io>
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package core
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/anchore/grype/grype/presenter/models"
|
|
logger "github.com/kubescape/go-logger"
|
|
"github.com/kubescape/kubescape/v3/core/cautils"
|
|
ksmetav1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
|
|
"github.com/kubescape/kubescape/v3/core/pkg/resultshandling"
|
|
"github.com/kubescape/kubescape/v3/pkg/imagescan"
|
|
)
|
|
|
|
func (ks *Kubescape) ScanImage(ctx context.Context, imgScanInfo *ksmetav1.ImageScanInfo, scanInfo *cautils.ScanInfo) (*models.PresenterConfig, error) {
|
|
logger.L().Start(fmt.Sprintf("Scanning image %s...", imgScanInfo.Image))
|
|
|
|
dbCfg, _ := imagescan.NewDefaultDBConfig()
|
|
svc := imagescan.NewScanService(dbCfg)
|
|
|
|
creds := imagescan.RegistryCredentials{
|
|
Username: imgScanInfo.Username,
|
|
Password: imgScanInfo.Password,
|
|
}
|
|
|
|
scanResults, err := svc.Scan(ctx, imgScanInfo.Image, creds)
|
|
if err != nil {
|
|
logger.L().StopError(fmt.Sprintf("Failed to scan image: %s", imgScanInfo.Image))
|
|
return nil, err
|
|
}
|
|
|
|
logger.L().StopSuccess(fmt.Sprintf("Successfully scanned image: %s", imgScanInfo.Image))
|
|
|
|
scanInfo.SetScanType(cautils.ScanTypeImage)
|
|
|
|
outputPrinters := GetOutputPrinters(scanInfo, ctx, "")
|
|
|
|
uiPrinter := GetUIPrinter(ctx, scanInfo, "")
|
|
|
|
resultsHandler := resultshandling.NewResultsHandler(nil, outputPrinters, uiPrinter)
|
|
|
|
resultsHandler.ImageScanData = []cautils.ImageScanData{
|
|
{
|
|
PresenterConfig: scanResults,
|
|
Image: imgScanInfo.Image,
|
|
},
|
|
}
|
|
|
|
return scanResults, resultsHandler.HandleResults(ctx)
|
|
}
|