Skip to content

Commit

Permalink
added logical location
Browse files Browse the repository at this point in the history
  • Loading branch information
devang-gaur committed May 26, 2021
1 parent e54cac8 commit ea7c9ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 11 additions & 4 deletions pkg/writer/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,21 @@ func SarifWriter(data interface{}, writer io.Writer) error {
rule := run.AddRule(string(violation.RuleID)).
WithDescription(violation.Description).WithName(violation.RuleName).WithProperties(m)

location := sarif.NewLocation().
WithPhysicalLocation(sarif.NewPhysicalLocation().
WithArtifactLocation(sarif.NewSimpleArtifactLocation(violation.File)).
WithContextRegion(sarif.NewRegion().WithStartLine(violation.LineNumber)))

if len(violation.ResourceType) > 0 && len(violation.ResourceName) > 0 {
location.LogicalLocations = append(location.LogicalLocations, sarif.NewLogicalLocation().
WithKind(violation.ResourceType).WithName(violation.ResourceName))
}

run.AddResult(rule.ID).
WithMessage(sarif.NewTextMessage(violation.Description)).
WithMessage(sarif.NewMarkdownMessage(violation.Description)).
WithLevel(getSarifLevel(violation.Severity)).
WithLocation(sarif.NewLocation().
WithPhysicalLocation(sarif.NewPhysicalLocation().
WithArtifactLocation(sarif.NewSimpleArtifactLocation(violation.File)).
WithContextRegion(sarif.NewRegion().WithStartLine(violation.LineNumber))))
WithLocation(location)
}

// print the report to anything that implements `io.Writer`
Expand Down
8 changes: 7 additions & 1 deletion pkg/writer/sarif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ const expectedSarifOutput1 = `{
"contextRegion": {
"startLine": 20
}
}
},
"logicalLocations": [
{
"name": "bucket",
"kind": "aws_s3_bucket"
}
]
}
]
}
Expand Down

0 comments on commit ea7c9ae

Please sign in to comment.