Skip to content

Commit

Permalink
other scan summary details
Browse files Browse the repository at this point in the history
  • Loading branch information
patilpankaj212 committed Dec 15, 2020
1 parent 5a6d70e commit 9103637
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/results/types.go
Expand Up @@ -16,6 +16,12 @@

package results

import (
"time"

"github.com/accurics/terrascan/pkg/utils"
)

// Violation Contains data for each violation
type Violation struct {
RuleName string `json:"rule_name" yaml:"rule_name" xml:"rule_name,attr"`
Expand Down Expand Up @@ -65,3 +71,26 @@ func (vs ViolationStore) Add(extra ViolationStore) ViolationStore {

return vs
}

// AddSummary will update the summary with remaining details
func (vs *ViolationStore) AddSummary(iacType, iacFilePath, iacDirPath string) {
if iacType == "" {
// the default scan type is terraform
vs.Summary.IacType = "terraform"
} else {
vs.Summary.IacType = iacType
}

if iacFilePath != "" {
// can skip the error as the file validation is already done
// while executor is initialized
filePath, _ := utils.GetAbsPath(iacFilePath)
vs.Summary.ResourcePath = filePath
} else {
// can skip the error as the directory validation is already done
// while executor is initialized
dirPath, _ := utils.GetAbsPath(iacDirPath)
vs.Summary.ResourcePath = dirPath
}
vs.Summary.Timestamp = time.Now().UTC().String()
}
3 changes: 3 additions & 0 deletions pkg/runtime/executor.go
Expand Up @@ -123,6 +123,9 @@ func (e *Executor) Execute() (results Output, err error) {

results.Violations = policy.EngineOutputFromViolationStore(&violations)

// add other summary details after policies are evaluated
results.Violations.ViolationStore.AddSummary(e.iacType, e.filePath, e.dirPath)

// send notifications, if configured
if err = e.SendNotifications(results); err != nil {
return results, err
Expand Down

0 comments on commit 9103637

Please sign in to comment.