Skip to content

Commit

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

Signed-off-by: stonezdj <daojunz@vmware.com>
  • Loading branch information
stonezdj committed Nov 14, 2023
1 parent e941f32 commit 8b413ee
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

Check warning on line 90 in src/controller/securityhub/controller.go

View check run for this annotation

Codecov / codecov/patch

src/controller/securityhub/controller.go#L90

Added line #L90 was not covered by tests
}
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
}

Check warning on line 157 in src/pkg/scan/scanner/manager.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/scan/scanner/manager.go#L156-L157

Added lines #L156 - L157 were not covered by tests
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)

Check warning on line 112 in src/server/v2.0/handler/security.go

View check run for this annotation

Codecov / codecov/patch

src/server/v2.0/handler/security.go#L111-L112

Added lines #L111 - L112 were not covered by tests
}
cnt, err := s.controller.CountVuls(ctx, scannerUUID, 0, *params.TuneCount, query)
if err != nil {
Expand Down

0 comments on commit 8b413ee

Please sign in to comment.