forked from owenrumney/go-sarif
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from owenrumney/initial_dev
Update the version and schema
- Loading branch information
Showing
7 changed files
with
117 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
# go-sarif | ||
Go library for sarif - Static Analysis Results Interchange Format | ||
|
||
## What? | ||
|
||
SARIF is the Static Analysis Results Interchange Format, this project seeks to provide a simple interface to generate reports in the SARIF format. | ||
|
||
## What prompted this? | ||
One of the projects I like to contribute to is [tfsec](https://tfsec.dev) - this is a static analysis tool for Terraform which produces output in many formats. Generating SARIF reports is missing functionality and felt like it warranted being moved out to a project of its own. | ||
|
||
## More information about SARIF | ||
For more information about SARIF, you can visit the [Oasis Open](https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=sarif) site. | ||
|
||
## Usage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package sarif | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"github.com/owenrumney/go-sarif/models" | ||
"io" | ||
) | ||
|
||
var versions = map[string]string{ | ||
"2.1.0": "http://json.schemastore.org/sarif-2.1.0-rtm.4", | ||
} | ||
|
||
type SarifReport struct { | ||
Version string `json:"version"` | ||
Schema string `json:"$schema"` | ||
Runs []*models.Run `json:"runs"` | ||
} | ||
|
||
func New(version string) (*SarifReport, error) { | ||
schema, err := getVersionSchema(version) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &SarifReport{ | ||
Version: version, | ||
Schema: schema, | ||
Runs: []*models.Run{}, | ||
}, nil | ||
} | ||
|
||
func getVersionSchema(version string) (string, error) { | ||
for ver, schema := range versions { | ||
if ver == version { | ||
return schema, nil | ||
} | ||
} | ||
return "", errors.New(fmt.Sprintf("version [%s] is not supported", version)) | ||
} | ||
|
||
func (sarif *SarifReport) AddRun(run *models.Run) { | ||
sarif.Runs = append(sarif.Runs, run) | ||
} | ||
|
||
func (sarif *SarifReport) Write(w io.Writer) error { | ||
marshal, err := json.Marshal(sarif) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = w.Write(marshal) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters