Skip to content

Commit

Permalink
added version property in sarif output
Browse files Browse the repository at this point in the history
  • Loading branch information
devang-gaur committed May 30, 2021
1 parent 5bec8fb commit c0b286b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@

package version

import "fmt"

// Terrascan The Terrascan version
const Terrascan = "v1.6.0"
const Terrascan = "1.6.0"

// Get returns the terrascan version
func Get() string {
return fmt.Sprintf("v%s",Terrascan)
}

// Get returns the terrascan version
func GetNumeric() string {
return Terrascan
}
5 changes: 4 additions & 1 deletion pkg/writer/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package writer
import (
"fmt"
"github.com/accurics/terrascan/pkg/policy"
"github.com/accurics/terrascan/pkg/version"
"github.com/owenrumney/go-sarif/sarif"
"io"
"path/filepath"
Expand All @@ -42,6 +43,8 @@ func SarifWriter(data interface{}, writer io.Writer) error {
}

run := sarif.NewRun("terrascan", "https://github.com/accurics/terrascan")
run.Tool.Driver.WithVersion(version.GetNumeric())

// add a run to the report
report.AddRun(run)

Expand Down Expand Up @@ -71,7 +74,7 @@ func SarifWriter(data interface{}, writer io.Writer) error {
location := sarif.NewLocation().
WithPhysicalLocation(sarif.NewPhysicalLocation().
WithArtifactLocation(sarif.NewSimpleArtifactLocation(fmt.Sprintf("file://%s", absFilePath))).
WithRegion(sarif.NewRegion().WithStartLine(violation.LineNumber - 1)))
WithRegion(sarif.NewRegion().WithStartLine(violation.LineNumber)))

if len(violation.ResourceType) > 0 && len(violation.ResourceName) > 0 {
location.LogicalLocations = append(location.LogicalLocations, sarif.NewLogicalLocation().
Expand Down
5 changes: 4 additions & 1 deletion pkg/writer/sarif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const expectedSarifOutput1 = `{
"tool": {
"driver": {
"name": "terrascan",
"version": "1.6.0",
"informationUri": "https://github.com/accurics/terrascan",
"rules": [
{
Expand Down Expand Up @@ -47,7 +48,7 @@ const expectedSarifOutput1 = `{
"uri": "file://test/modules/m1/main.tf"
},
"region": {
"startLine": 19
"startLine": 20
}
},
"logicalLocations": [
Expand All @@ -72,6 +73,7 @@ const expectedSarifOutput2 = `{
"tool": {
"driver": {
"name": "terrascan",
"version": "1.6.0",
"informationUri": "https://github.com/accurics/terrascan"
}
},
Expand All @@ -88,6 +90,7 @@ const expectedSarifOutput3 = `{
"tool": {
"driver": {
"name": "terrascan",
"version": "1.6.0",
"informationUri": "https://github.com/accurics/terrascan",
"rules": [
{
Expand Down

0 comments on commit c0b286b

Please sign in to comment.