From 307a3121aa4646fb08d77974f526f70a929ca047 Mon Sep 17 00:00:00 2001 From: "stonezdj(Daojun Zhang)" Date: Fri, 17 Nov 2023 15:29:19 +0800 Subject: [PATCH] Return empty result when no scanner configured (#19577) fixes #19534 Signed-off-by: stonezdj --- src/controller/securityhub/controller.go | 4 ++-- src/pkg/scan/scanner/manager.go | 3 +++ src/server/v2.0/handler/security.go | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/controller/securityhub/controller.go b/src/controller/securityhub/controller.go index f53527a5ddb..80babcb9ab3 100644 --- a/src/controller/securityhub/controller.go +++ b/src/controller/securityhub/controller.go @@ -86,8 +86,8 @@ func NewController() Controller { func (c *controller) SecuritySummary(ctx context.Context, projectID int64, options ...Option) (*secHubModel.Summary, error) { opts := newOptions(options...) scannerUUID, err := c.scannerMgr.DefaultScannerUUID(ctx) - if err != nil { - return nil, err + if len(scannerUUID) == 0 || err != nil { + return &secHubModel.Summary{}, nil } sum, err := c.secHubMgr.Summary(ctx, scannerUUID, projectID, nil) if err != nil { diff --git a/src/pkg/scan/scanner/manager.go b/src/pkg/scan/scanner/manager.go index 96598f20b1c..ed73e38ace6 100644 --- a/src/pkg/scan/scanner/manager.go +++ b/src/pkg/scan/scanner/manager.go @@ -152,5 +152,8 @@ func (bm *basicManager) DefaultScannerUUID(ctx context.Context) (string, error) if err != nil { return "", err } + if reg == nil { + return "", nil + } return reg.UUID, nil } diff --git a/src/server/v2.0/handler/security.go b/src/server/v2.0/handler/security.go index 27aba998fcf..d324b97e5de 100644 --- a/src/server/v2.0/handler/security.go +++ b/src/server/v2.0/handler/security.go @@ -108,8 +108,8 @@ func (s *securityAPI) ListVulnerabilities(ctx context.Context, params securityMo return s.SendError(ctx, err) } scannerUUID, err := scanner.Mgr.DefaultScannerUUID(ctx) - if err != nil { - return s.SendError(ctx, err) + if err != nil || len(scannerUUID) == 0 { + return securityModel.NewListVulnerabilitiesOK().WithPayload([]*models.VulnerabilityItem{}).WithXTotalCount(0) } cnt, err := s.controller.CountVuls(ctx, scannerUUID, 0, *params.TuneCount, query) if err != nil {