sarif

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sarif writes SARIF 2.1.0 logs, the format GitHub code scanning reads.

Index

Constants

View Source
const (
	Version   = "2.1.0"
	SchemaURI = "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json"
)

Version and SchemaURI identify SARIF 2.1.0.

View Source
const (
	LevelError   = "error"
	LevelWarning = "warning"
	LevelNote    = "note"
)

Levels a result can have.

Variables

This section is empty.

Functions

func FileURI

func FileURI(path string) string

FileURI returns the artifact URI of a slash-separated path. A relative path stays relative to the repository root, as GitHub code scanning prefers; an absolute one (/src, C:/src, //host/share) becomes a file URI, so Windows paths never reach the log as bare drive letters.

func Write

func Write(w io.Writer, l *Log) error

Write encodes l as indented JSON.

func WriteGitHub added in v0.2.0

func WriteGitHub(w io.Writer, l *Log) error

WriteGitHub writes each unsuppressed result of l as a GitHub Actions workflow command, which GitHub shows as an annotation: error results as errors, warnings as warnings, the rest as notices.

Types

type ArtifactLocation

type ArtifactLocation struct {
	URI string `json:"uri"`
}

ArtifactLocation is a URI, relative to the repository root or absolute (s3://, dynamodb://).

type Configuration

type Configuration struct {
	Level string `json:"level"`
}

Configuration holds a rule's default level.

type Driver

type Driver struct {
	Name           string `json:"name"`
	Version        string `json:"version,omitempty"`
	InformationURI string `json:"informationUri,omitempty"`
	Rules          []Rule `json:"rules"`
}

Driver is the tool's main component.

type Location

type Location struct {
	PhysicalLocation PhysicalLocation `json:"physicalLocation"`
}

Location points at an artifact by URI.

type Log

type Log struct {
	Schema  string `json:"$schema"`
	Version string `json:"version"`
	Runs    []Run  `json:"runs"`
}

Log is a SARIF log with one run.

func New

func New(name, version, infoURI string) *Log

New returns an empty log for a tool.

type Message

type Message struct {
	Text string `json:"text"`
}

Message is a plain-text message.

type PhysicalLocation

type PhysicalLocation struct {
	ArtifactLocation ArtifactLocation `json:"artifactLocation"`
	Region           *Region          `json:"region,omitempty"`
}

PhysicalLocation names an artifact and, when known, a line in it.

type Region

type Region struct {
	StartLine int `json:"startLine"` // 1-based
}

Region is a line of an artifact.

type Result

type Result struct {
	RuleID              string            `json:"ruleId"`
	RuleIndex           int               `json:"ruleIndex"`
	Level               string            `json:"level"`
	Message             Message           `json:"message"`
	Locations           []Location        `json:"locations"`
	PartialFingerprints map[string]string `json:"partialFingerprints,omitempty"`
	Suppressions        []Suppression     `json:"suppressions,omitempty"`
	Properties          map[string]any    `json:"properties,omitempty"`
}

Result is one finding.

type Rule

type Rule struct {
	ID                   string         `json:"id"`
	ShortDescription     Message        `json:"shortDescription"`
	FullDescription      Message        `json:"fullDescription,omitzero"`
	Help                 Message        `json:"help"`
	DefaultConfiguration Configuration  `json:"defaultConfiguration"`
	Properties           map[string]any `json:"properties,omitempty"`
}

Rule is one reportingDescriptor.

type Run

type Run struct {
	Tool    Tool     `json:"tool"`
	Results []Result `json:"results"`
}

Run is one tool invocation.

type Suppression

type Suppression struct {
	Kind          string `json:"kind"` // external: from configuration, not the source
	Status        string `json:"status"`
	Justification string `json:"justification"`
}

Suppression records why a result is accepted.

type Tool

type Tool struct {
	Driver Driver `json:"driver"`
}

Tool describes the tool and its rules.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL