go sarif
v2.3.3
SARIF是靜態分析結果互換格式,該項目旨在提供一個簡單的接口來以SARIF格式生成報告。
此示例直接從Microsoft Sarif頁面中獲取
{
"version" : " 2.1.0 " ,
"$schema" : " https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json " ,
"runs" : [
{
"tool" : {
"driver" : {
"name" : " ESLint " ,
"informationUri" : " https://eslint.org " ,
"rules" : [
{
"id" : " no-unused-vars " ,
"shortDescription" : {
"text" : " disallow unused variables "
},
"helpUri" : " https://eslint.org/docs/rules/no-unused-vars " ,
"properties" : {
"category" : " Variables "
}
}
]
}
},
"artifacts" : [
{
"location" : {
"uri" : " file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js "
}
}
],
"results" : [
{
"level" : " error " ,
"message" : {
"text" : " 'x' is assigned a value but never used. "
},
"locations" : [
{
"physicalLocation" : {
"artifactLocation" : {
"uri" : " file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js " ,
"index" : 0
},
"region" : {
"startLine" : 1 ,
"startColumn" : 5
}
}
}
],
"ruleId" : " no-unused-vars " ,
"ruleIndex" : 0
}
]
}
]
}我想為TFSEC貢獻的項目之一 - 這是Terraform的靜態分析工具,它以多種格式產生輸出。生成SARIF報告缺少功能,並且覺得它有必要將其轉移到一個自己的項目中。
有關SARIF的更多信息,您可以訪問Oasis Open網站。
添加導入到go get github.com/owenrumney/go-sarif/sarif
Sarif報告的內容中有多種加載方法。
sarif.Open採用文件路徑並從該位置加載SARIF。返回報告和任何相應的錯誤
sarif.FromBytes拿了一小部分字節,並返回報告和任何相應的錯誤。
sarif.FromString取一根SARIF內容並返回報告和任何相應的錯誤。
創建新的SARIF報告是通過傳遞版本完成的,目前唯一支持的是2.1.0
有關詳細示例,請檢查示例文件夾示例/main.go