Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing correctly pURLs and prefixing targets. #476

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ tests/output
.vscode/
deploy/smithy/chart/charts
.idea/
components/consumers/pdf/report.html
2 changes: 1 addition & 1 deletion components/producers/checkov/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func run(inFile []byte, target string) error {
func handleSarif(inFile []byte) ([]*smithyv1.Issue, error) {
var sarifResults []*sarif.SmithyIssueCollection
var smithyResults []*smithyv1.Issue
sarifResults, err := sarif.ToSmithy(string(inFile))
sarifResults, err := sarif.ToSmithy(string(inFile), sarif.ExtraContextLanguageUnspecified)
if err != nil {
return smithyResults, err
}
Expand Down
6 changes: 3 additions & 3 deletions components/producers/checkov/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ func TestRunSarif(t *testing.T) {
require.NoError(t, err)
expectedIssues := []*smithyv1.Issue{
{
Target: "code/cfngoat/cfngoat.yaml:891-892",
Target: "file://code/cfngoat/cfngoat.yaml:891-892",
Type: "CKV_SECRET_6",
Title: "Base64 High Entropy String",
Severity: smithyv1.Severity_SEVERITY_HIGH,
Description: "MatchedRule: {\"id\":\"CKV_SECRET_6\",\"name\":\"Base64 High Entropy String\",\"shortDescription\":{\"text\":\"Base64 High Entropy String\"},\"fullDescription\":{\"text\":\"Base64 High Entropy String\"},\"defaultConfiguration\":{\"level\":\"error\"},\"help\":{\"text\":\"Base64 High Entropy String\\nResource: c00f1a6e4b20aa64691d50781b810756d6254b8e\"}} \n Message: Base64 High Entropy String",
}, {
Target: "code/cfngoat/.github/workflows/checkov.yaml:1-1",
Target: "file://code/cfngoat/.github/workflows/checkov.yaml:1-1",
Type: "CKV2_GHA_1",
Title: "Ensure top-level permissions are not set to write-all",
Severity: smithyv1.Severity_SEVERITY_HIGH,
Description: "MatchedRule: {\"id\":\"CKV2_GHA_1\",\"name\":\"Ensure top-level permissions are not set to write-all\",\"shortDescription\":{\"text\":\"Ensure top-level permissions are not set to write-all\"},\"fullDescription\":{\"text\":\"Ensure top-level permissions are not set to write-all\"},\"defaultConfiguration\":{\"level\":\"error\"},\"help\":{\"text\":\"Ensure top-level permissions are not set to write-all\\nResource: on(build)\"}} \n Message: Ensure top-level permissions are not set to write-all",
}, {
Target: "code/cfngoat/.github/workflows/main.yaml:1-1",
Target: "file://code/cfngoat/.github/workflows/main.yaml:1-1",
Type: "CKV2_GHA_1",
Title: "Ensure top-level permissions are not set to write-all",
Severity: smithyv1.Severity_SEVERITY_HIGH,
Expand Down
2 changes: 1 addition & 1 deletion components/producers/docker-trivy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func handleJSON(inFile []byte) ([]*v1.Issue, error) {
func handleSarif(inFile []byte) ([]*v1.Issue, error) {
var sarifResults []*sarif.SmithyIssueCollection
var smithyResults []*v1.Issue
sarifResults, err := sarif.ToSmithy(string(inFile))
sarifResults, err := sarif.ToSmithy(string(inFile), sarif.ExtraContextLanguageUnspecified)
if err != nil {
return smithyResults, err
}
Expand Down
2 changes: 1 addition & 1 deletion components/producers/java-findsecbugs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
sarifResults, err = sarif.ToSmithy(string(inFile))
sarifResults, err = sarif.ToSmithy(string(inFile), sarif.ExtraContextLanguageUnspecified)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion components/producers/kics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
if Sarif {
var sarifResults []*sarif.SmithyIssueCollection
var smithyResults []*v1.Issue
sarifResults, err := sarif.ToSmithy(string(inFile))
sarifResults, err := sarif.ToSmithy(string(inFile), sarif.ExtraContextLanguageUnspecified)
if err != nil {
log.Fatal(err)
}
Expand Down
20 changes: 17 additions & 3 deletions components/producers/snyk-docker/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"log"
"log/slog"

Expand All @@ -10,6 +11,8 @@ import (
)

func main() {
var producerLang string
flag.StringVar(&producerLang, "language", "", "")

if err := producers.ParseFlags(); err != nil {
log.Fatal(err)
Expand All @@ -20,7 +23,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
results, err := processInput(string(inFile))
results, err := processInput(string(inFile), producerLang)
if err != nil {
log.Fatal(err)
}
Expand All @@ -46,11 +49,22 @@ func writeOutput(results map[string][]*v1.Issue) error {
return nil
}

func processInput(input string) (map[string][]*v1.Issue, error) {
issues, err := sarif.ToSmithy(string(input))
func processInput(input string, language string) (map[string][]*v1.Issue, error) {
var (
issues []*sarif.SmithyIssueCollection
extraCtxLang = sarif.ExtraContextLanguageUnspecified
err error
)

if language != "" {
extraCtxLang = sarif.ExtraContextLanguage(language)
}

issues, err = sarif.ToSmithy(input, extraCtxLang)
if err != nil {
return nil, err
}

results := map[string][]*v1.Issue{}
for _, output := range issues {
results[output.ToolName] = append(results[output.ToolName], output.Issues...)
Expand Down
12 changes: 6 additions & 6 deletions components/producers/snyk-docker/main_test.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions components/producers/snyk-node/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ spec:
args:
- "-in=/scratch/snyk.out"
- "-out=$(workspaces.output.path)/.smithy/producers/snyk.pb"
- "-language=javascript"
volumeMounts:
- mountPath: /scratch
name: scratch
1 change: 1 addition & 0 deletions components/producers/snyk-python/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ spec:
args:
- "-in=/scratch/snyk.out"
- "-out=$(workspaces.output.path)/.smithy/producers/snyk.pb"
- "-language=python"
volumeMounts:
- mountPath: /scratch
name: scratch
2 changes: 1 addition & 1 deletion components/producers/terraform-tfsec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
if Sarif {
var sarifResults []*sarif.SmithyIssueCollection
var smithyResults []*v1.Issue
sarifResults, err := sarif.ToSmithy(string(inFile))
sarifResults, err := sarif.ToSmithy(string(inFile), sarif.ExtraContextLanguageUnspecified)
if err != nil {
log.Fatal(err)
}
Expand Down
Loading