2021-05-10 10:08:04 +02:00
package sarif
2021-05-31 10:44:12 +02:00
// NewReport instantiate a SARIF Report
2021-05-10 10:08:04 +02:00
func NewReport ( version string , schema string ) * Report {
return & Report {
Version : version ,
Schema : schema ,
}
}
2023-10-05 13:59:17 +03:00
// WithRuns defines runs for the current report
2021-05-10 10:08:04 +02:00
func ( r * Report ) WithRuns ( runs ... * Run ) * Report {
r . Runs = runs
return r
}
2021-05-31 10:44:12 +02:00
// NewMultiformatMessageString instantiate a MultiformatMessageString
2021-05-10 10:08:04 +02:00
func NewMultiformatMessageString ( text string ) * MultiformatMessageString {
return & MultiformatMessageString {
Text : text ,
}
}
2021-05-31 10:44:12 +02:00
// NewRun instantiate a Run
2021-05-10 10:08:04 +02:00
func NewRun ( tool * Tool ) * Run {
return & Run {
Tool : tool ,
}
}
2021-05-31 10:44:12 +02:00
// WithTaxonomies set the taxonomies for the current run
2021-05-10 10:08:04 +02:00
func ( r * Run ) WithTaxonomies ( taxonomies ... * ToolComponent ) * Run {
r . Taxonomies = taxonomies
return r
}
2021-05-31 10:44:12 +02:00
// WithResults set the results for the current run
2021-05-10 10:08:04 +02:00
func ( r * Run ) WithResults ( results ... * Result ) * Run {
r . Results = results
return r
}
2021-05-31 10:44:12 +02:00
// NewArtifactLocation instantiate an ArtifactLocation
2021-05-10 10:08:04 +02:00
func NewArtifactLocation ( uri string ) * ArtifactLocation {
return & ArtifactLocation {
URI : uri ,
}
}
2021-05-31 10:44:12 +02:00
// NewRegion instantiate a Region
2021-05-10 10:08:04 +02:00
func NewRegion ( startLine int , endLine int , startColumn int , endColumn int , sourceLanguage string ) * Region {
return & Region {
StartLine : startLine ,
EndLine : endLine ,
StartColumn : startColumn ,
EndColumn : endColumn ,
SourceLanguage : sourceLanguage ,
}
}
2021-05-31 10:44:12 +02:00
// WithSnippet defines the Snippet for the current Region
2021-05-13 16:02:28 +02:00
func ( r * Region ) WithSnippet ( snippet * ArtifactContent ) * Region {
r . Snippet = snippet
return r
}
2021-05-31 10:44:12 +02:00
// NewArtifactContent instantiate an ArtifactContent
2021-05-13 16:02:28 +02:00
func NewArtifactContent ( text string ) * ArtifactContent {
return & ArtifactContent {
Text : text ,
}
}
2021-05-31 10:44:12 +02:00
// NewTool instantiate a Tool
2021-05-10 10:08:04 +02:00
func NewTool ( driver * ToolComponent ) * Tool {
return & Tool {
Driver : driver ,
}
}
2021-05-31 10:44:12 +02:00
// NewResult instantiate a Result
2024-08-12 17:52:41 +07:00
func NewResult ( ruleID string , ruleIndex int , level Level , message string , suppressions [ ] * Suppression , autofix string ) * Result {
2024-09-18 13:43:01 +02:00
result := & Result {
2021-12-09 18:53:36 +08:00
RuleID : ruleID ,
RuleIndex : ruleIndex ,
Level : level ,
Message : NewMessage ( message ) ,
Suppressions : suppressions ,
2024-09-18 13:43:01 +02:00
}
if len ( autofix ) > 0 {
result . Fixes = [ ] * Fix {
2024-08-12 17:52:41 +07:00
{
Description : & Message {
2025-10-01 09:30:43 +02:00
// Note: Text SHALL be supplied when Markdown is used: https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141790720
Text : autofix , // TODO: ensure this is plain text
2024-08-12 17:52:41 +07:00
Markdown : autofix ,
} ,
2025-11-11 10:24:32 +01:00
ArtifactChanges : [ ] * ArtifactChange { // TODO: this is a placeholder to pass validation. The values are not of use right now
{
ArtifactLocation : & ArtifactLocation {
Description : NewMessage ( "unknown" ) ,
} ,
Replacements : [ ] * Replacement {
{
DeletedRegion : NewRegion ( 1 , 1 , 1 , 1 , "unknown" ) ,
} ,
} ,
} ,
} ,
2024-08-12 17:52:41 +07:00
} ,
2024-09-18 13:43:01 +02:00
}
2021-05-10 10:08:04 +02:00
}
2024-09-18 13:43:01 +02:00
return result
2021-05-10 10:08:04 +02:00
}
2021-05-31 10:44:12 +02:00
// NewMessage instantiate a Message
2021-05-10 10:08:04 +02:00
func NewMessage ( text string ) * Message {
return & Message {
Text : text ,
}
}
2021-05-31 10:44:12 +02:00
// WithLocations define the current result's locations
2021-05-10 10:08:04 +02:00
func ( r * Result ) WithLocations ( locations ... * Location ) * Result {
r . Locations = locations
return r
}
2021-05-31 10:44:12 +02:00
// NewLocation instantiate a Location
2021-05-10 10:08:04 +02:00
func NewLocation ( physicalLocation * PhysicalLocation ) * Location {
return & Location {
PhysicalLocation : physicalLocation ,
}
}
2021-05-31 10:44:12 +02:00
// NewPhysicalLocation instantiate a PhysicalLocation
2021-05-10 10:08:04 +02:00
func NewPhysicalLocation ( artifactLocation * ArtifactLocation , region * Region ) * PhysicalLocation {
return & PhysicalLocation {
ArtifactLocation : artifactLocation ,
Region : region ,
}
}
2021-05-31 10:44:12 +02:00
// NewToolComponent instantiate a ToolComponent
2021-05-10 10:08:04 +02:00
func NewToolComponent ( name string , version string , informationURI string ) * ToolComponent {
return & ToolComponent {
Name : name ,
Version : version ,
InformationURI : informationURI ,
GUID : uuid3 ( name ) ,
}
}
2021-05-31 10:44:12 +02:00
// WithLanguage set Language for the current ToolComponent
2021-05-20 10:16:42 +02:00
func ( t * ToolComponent ) WithLanguage ( language string ) * ToolComponent {
t . Language = language
return t
}
2021-05-31 10:44:12 +02:00
// WithSemanticVersion set SemanticVersion for the current ToolComponent
2021-05-20 10:16:42 +02:00
func ( t * ToolComponent ) WithSemanticVersion ( semanticVersion string ) * ToolComponent {
t . SemanticVersion = semanticVersion
return t
}
2021-05-31 10:44:12 +02:00
// WithReleaseDateUtc set releaseDateUtc for the current ToolComponent
2021-05-10 10:08:04 +02:00
func ( t * ToolComponent ) WithReleaseDateUtc ( releaseDateUtc string ) * ToolComponent {
t . ReleaseDateUtc = releaseDateUtc
return t
}
2021-05-31 10:44:12 +02:00
// WithDownloadURI set downloadURI for the current ToolComponent
2021-05-10 10:08:04 +02:00
func ( t * ToolComponent ) WithDownloadURI ( downloadURI string ) * ToolComponent {
t . DownloadURI = downloadURI
return t
}
2021-05-31 10:44:12 +02:00
// WithOrganization set organization for the current ToolComponent
2021-05-10 10:08:04 +02:00
func ( t * ToolComponent ) WithOrganization ( organization string ) * ToolComponent {
t . Organization = organization
return t
}
2021-05-31 10:44:12 +02:00
// WithShortDescription set shortDescription for the current ToolComponent
2021-05-10 10:08:04 +02:00
func ( t * ToolComponent ) WithShortDescription ( shortDescription * MultiformatMessageString ) * ToolComponent {
t . ShortDescription = shortDescription
return t
}
2021-05-31 10:44:12 +02:00
// WithIsComprehensive set isComprehensive for the current ToolComponent
2021-05-10 10:08:04 +02:00
func ( t * ToolComponent ) WithIsComprehensive ( isComprehensive bool ) * ToolComponent {
t . IsComprehensive = isComprehensive
return t
}
2021-05-31 10:44:12 +02:00
// WithMinimumRequiredLocalizedDataSemanticVersion set MinimumRequiredLocalizedDataSemanticVersion for the current ToolComponent
2021-05-10 10:08:04 +02:00
func ( t * ToolComponent ) WithMinimumRequiredLocalizedDataSemanticVersion ( minimumRequiredLocalizedDataSemanticVersion string ) * ToolComponent {
t . MinimumRequiredLocalizedDataSemanticVersion = minimumRequiredLocalizedDataSemanticVersion
return t
}
2021-05-31 10:44:12 +02:00
// WithTaxa set taxa for the current ToolComponent
2021-05-10 10:08:04 +02:00
func ( t * ToolComponent ) WithTaxa ( taxa ... * ReportingDescriptor ) * ToolComponent {
t . Taxa = taxa
return t
}
2021-05-31 10:44:12 +02:00
// WithSupportedTaxonomies set the supported taxonomies for the current ToolComponent
2021-05-10 10:08:04 +02:00
func ( t * ToolComponent ) WithSupportedTaxonomies ( supportedTaxonomies ... * ToolComponentReference ) * ToolComponent {
t . SupportedTaxonomies = supportedTaxonomies
return t
}
2021-05-31 10:44:12 +02:00
// WithRules set the rules for the current ToolComponent
2021-05-10 10:08:04 +02:00
func ( t * ToolComponent ) WithRules ( rules ... * ReportingDescriptor ) * ToolComponent {
t . Rules = rules
return t
}
2021-05-31 10:44:12 +02:00
// NewToolComponentReference instantiate a ToolComponentReference
2021-05-10 10:08:04 +02:00
func NewToolComponentReference ( name string ) * ToolComponentReference {
return & ToolComponentReference {
Name : name ,
GUID : uuid3 ( name ) ,
}
}
2021-12-09 18:53:36 +08:00
// NewSuppression instantiate a Suppression
func NewSuppression ( kind string , justification string ) * Suppression {
return & Suppression {
Kind : kind ,
Justification : justification ,
}
}