Skip to content

Commit

Permalink
Added debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dstrelbytskyi authored and carsongee committed Feb 15, 2024
1 parent b6179df commit db52e80
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/result/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

dbTypes "github.com/aquasecurity/trivy-db/pkg/types"
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/aquasecurity/trivy/pkg/log"
"github.com/aquasecurity/trivy/pkg/types"
"github.com/aquasecurity/trivy/pkg/vex"
)
Expand Down Expand Up @@ -69,7 +70,8 @@ func FilterResult(ctx context.Context, result *types.Result, ignoreConf IgnoreCo
filteredLicenses := filterLicenses(result.Licenses, severities, opt.IgnoreLicenses, ignoreConf.Licenses)

var ignoredMisconfs int
if opt.PolicyFile != "" {
if opt.PolicyFile != "" && len(filteredVulns)+len(filteredMisconfs)+len(filteredSecrets)+len(filteredLicenses) > 0 {
log.Logger.Debugf("Filtering result with ignore policies, type: %s, path: %s", result.Type, result.Target)
var err error
var ignored int

Expand All @@ -84,11 +86,15 @@ func FilterResult(ctx context.Context, result *types.Result, ignoreConf IgnoreCo
if err != nil {
return xerrors.Errorf("failed to find policy files in %s: %w", opt.PolicyFile, err)
}
if len(policyFiles) == 0 {
log.Logger.Warnf("No ignore policies found in %s", opt.PolicyFile)
}
} else {
policyFiles = append(policyFiles, opt.PolicyFile)
}

for _, policyFile := range policyFiles {
log.Logger.Debugf("Applying ignore policy: %s", policyFile)
filteredVulns, filteredMisconfs, ignored, filteredSecrets, filteredLicenses, err = applyPolicy(ctx, filteredVulns, filteredMisconfs, filteredSecrets, filteredLicenses, policyFile)
if err != nil {
return xerrors.Errorf("failed to apply ignore policy %s: %w", policyFile, err)
Expand Down

0 comments on commit db52e80

Please sign in to comment.