diff --git a/cli/go.sum b/cli/go.sum index 8021180066e..c59515ebb61 100644 --- a/cli/go.sum +++ b/cli/go.sum @@ -471,6 +471,7 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E= @@ -559,6 +560,7 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/svanharmelen/jsonapi v0.0.0-20180618144545-0c0828c3f16d/go.mod h1:BSTlc8jOjh0niykqEGVXOLXdi9o0r0kR8tCYiMvjFgw= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= diff --git a/cli/scorecard/score.go b/cli/scorecard/score.go index 0abf9ea6ea9..c0606c877d1 100644 --- a/cli/scorecard/score.go +++ b/cli/scorecard/score.go @@ -16,6 +16,7 @@ package scorecard import ( "context" + "crypto/md5" "encoding/csv" "encoding/json" "flag" @@ -85,7 +86,8 @@ func (cv constraintViolations) Count() int { } func (cv constraintViolations) GetName() string { - return cv.constraint.GetMetadata().GetStructValue().GetFields()["name"].GetStringValue() + return cv.Violations[0].Constraint + // return cv.constraint.GetMetadata().GetStructValue().GetFields()["name"].GetStringValue() } // RichViolation holds a violation with its category @@ -171,6 +173,9 @@ func (inventory *InventoryConfig) Score(config *ScoringConfig, outputPath string if err != nil { return err } + Log.Debug("AuditResult from Config Validator", "# of Violations", len(auditResult.Violations)) + auditResult.Violations = uniqueViolations(auditResult.Violations) + Log.Debug("AuditResult from Config Validator", "# of Unique Violations", len(auditResult.Violations)) err = config.attachViolations(auditResult) if err != nil { @@ -269,3 +274,18 @@ func (inventory *InventoryConfig) Score(config *ScoringConfig, outputPath string return nil } + +func uniqueViolations(violations []*validator.Violation) []*validator.Violation { + uniqueViolationMap := make(map[string]*validator.Violation) + for _, v := range violations { + b, _ := json.Marshal(v) + hash := md5.Sum(b) + uniqueViolationMap[string(hash[:])] = v + } + uniqueViolations := make([]*validator.Violation, 0, len(uniqueViolationMap)) + for _, v := range uniqueViolationMap { + uniqueViolations = append(uniqueViolations, v) + } + return uniqueViolations +} + diff --git a/cli/scorecard/violations.go b/cli/scorecard/violations.go index 992e5ec3780..272ded5235b 100644 --- a/cli/scorecard/violations.go +++ b/cli/scorecard/violations.go @@ -115,6 +115,7 @@ func getViolations(inventory *InventoryConfig, config *ScoringConfig) (*validato auditResult := &validator.AuditResponse{} for _, asset := range pbAssets { violations, err := config.validator.ReviewAsset(context.Background(), asset) + if err != nil { return nil, errors.Wrapf(err, "reviewing asset %s", asset) }