Skip to content

Commit

Permalink
Return empty result when no scanner configured (#19577)
Browse files Browse the repository at this point in the history
fixes #19534

Signed-off-by: stonezdj <[email protected]>
  • Loading branch information
stonezdj authored Nov 17, 2023
1 parent 08cb080 commit 307a312
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/controller/securityhub/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/scan/scanner/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions src/server/v2.0/handler/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 307a312

Please sign in to comment.