Skip to content

Commit c5ce9ca

Browse files
committed
sarif timeout added
1 parent 667529b commit c5ce9ca

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

appknox/sarif_generator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type Help struct {
9090
Markdown string `json:"markdown,omitempty"`
9191
}
9292

93-
func GenerateSARIFGivenFileID(client *Client, fileID int, riskThreshold int) (SARIF, error) {
93+
func GenerateSARIFGivenFileID(client *Client, fileID int, riskThreshold int,staticScanTimeout time.Duration) (SARIF, error) {
9494
ctx := context.Background()
9595
var sarifReportProgess int
9696
start := time.Now()
@@ -119,7 +119,7 @@ func GenerateSARIFGivenFileID(client *Client, fileID int, riskThreshold int) (SA
119119
sarifReportProgess = file.StaticScanProgress
120120
bar.SetCurrent(int64(sarifReportProgess), time.Since(start))
121121

122-
if time.Since(start) > 15*time.Minute {
122+
if time.Since(start) > staticScanTimeout {
123123
err := errors.New("Request timed out")
124124
PrintError(err)
125125
os.Exit(1)
@@ -264,7 +264,7 @@ func GenerateSARIFGivenFileID(client *Client, fileID int, riskThreshold int) (SA
264264
}
265265

266266
func PrintError(err error) {
267-
panic("unimplemented")
267+
panic(err)
268268
}
269269

270270
func GenerateSARIFFileContent(sarif SARIF) (string, error) {

cmd/cicheck.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var cicheckCmd = &cobra.Command{
4646
helper.PrintError(err)
4747
os.Exit(1)
4848
}
49-
timeoutMinutes, _ := cmd.Flags().GetInt("sast-timeout")
49+
timeoutMinutes, _ := cmd.Flags().GetInt("timeout")
5050
timeout := time.Duration(timeoutMinutes) * time.Minute
5151

5252
helper.ProcessCiCheck(fileID, riskThresholdInt, timeout)
@@ -58,6 +58,6 @@ func init() {
5858
cicheckCmd.Flags().StringP(
5959
"risk-threshold", "r", "low", "Risk threshold to fail the command. Available options: low, medium, high")
6060
cicheckCmd.Flags().IntP(
61-
"sast-timeout", "t", 30, "Static scan timeout in minutes for the CI check (default: 30)")
61+
"timeout", "t", 30, "Static scan timeout in minutes for the CI check (default: 30)")
6262

6363
}

cmd/sarif.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
"os"
66
"strconv"
77
"strings"
8-
8+
"time"
9+
910
"github.com/appknox/appknox-go/helper"
1011
"github.com/spf13/cobra"
1112
)
@@ -45,7 +46,9 @@ var sarifCmd = &cobra.Command{
4546
os.Exit(1)
4647
}
4748
outputFilePath, _ := cmd.Flags().GetString("output")
48-
helper.ConvertToSARIFReport(fileID,riskThresholdInt,outputFilePath)
49+
timeoutMinutes, _ := cmd.Flags().GetInt("timeout")
50+
timeout := time.Duration(timeoutMinutes) * time.Minute
51+
helper.ConvertToSARIFReport(fileID,riskThresholdInt,outputFilePath,timeout)
4952
},
5053
}
5154

@@ -54,4 +57,6 @@ func init() {
5457
sarifCmd.Flags().StringP(
5558
"risk-threshold", "r", "low", "Risk threshold to fail the command. Available options: low, medium, high")
5659
sarifCmd.PersistentFlags().StringP("output", "o", "report.sarif", "Output file path to save reports")
60+
sarifCmd.Flags().IntP(
61+
"timeout", "t", 30, "Static scan timeout in minutes for the CI check (default: 30)")
5762
}

helper/sarif.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package helper
33
import (
44
"fmt"
55
"os"
6-
6+
"time"
7+
78
"github.com/appknox/appknox-go/appknox"
89
)
910

10-
func ConvertToSARIFReport(fileID int, riskThreshold int, filePath string) error {
11+
func ConvertToSARIFReport(fileID int, riskThreshold int, filePath string,staticScanTimeout time.Duration) error {
1112
client := getClient()
12-
sarif, err := appknox.GenerateSARIFGivenFileID(client, fileID, riskThreshold)
13+
sarif, err := appknox.GenerateSARIFGivenFileID(client, fileID, riskThreshold,staticScanTimeout)
1314
if err != nil {
1415
return err
1516
}

0 commit comments

Comments
 (0)