Skip to content

Commit eaa3f3a

Browse files
committed
timeout support added
1 parent 3b69b96 commit eaa3f3a

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

appknox/sarif_generator.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/iancoleman/strcase"
1414
"github.com/vbauerster/mpb/v4"
1515
"github.com/vbauerster/mpb/v4/decor"
16+
"github.com/spf13/viper"
1617
)
1718

1819
type SARIF struct {
@@ -109,7 +110,7 @@ func GenerateSARIFGivenFileID(client *Client, fileID int, riskThreshold int) (SA
109110
decor.Name("] "),
110111
),
111112
)
112-
113+
113114
for sarifReportProgess < 100 {
114115
file, _, err := client.Files.GetByID(ctx, fileID)
115116
if err != nil {
@@ -118,7 +119,8 @@ func GenerateSARIFGivenFileID(client *Client, fileID int, riskThreshold int) (SA
118119
}
119120
sarifReportProgess = file.StaticScanProgress
120121
bar.SetCurrent(int64(sarifReportProgess), time.Since(start))
121-
if time.Since(start) > 15*time.Minute {
122+
123+
if time.Since(start) > time.Duration(viper.GetInt("timeout")) * time.Minute {
122124
err := errors.New("Request timed out")
123125
PrintError(err)
124126
os.Exit(1)

cmd/root.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7-
7+
88
// "github.com/appknox/appknox-go/appknox"
99
"github.com/spf13/cobra"
1010
"github.com/spf13/viper"
@@ -39,7 +39,11 @@ func init() {
3939
viper.BindPFlag("host", RootCmd.PersistentFlags().Lookup("host"))
4040
viper.BindEnv("host", "APPKNOX_API_HOST")
4141

42-
42+
// Define flags globally here for all subcommands
43+
RootCmd.PersistentFlags().String("timeout", "", "Timeout for Appknox scanner, default is 30 minutes")
44+
viper.BindPFlag("timeout", RootCmd.PersistentFlags().Lookup("timeout"))
45+
viper.BindEnv("timeout", "APPKNOX_TIMEOUT")
46+
viper.SetDefault("timeout", "30") // Default to 30 minutes
4347
RootCmd.PersistentFlags().String("region", "", "Region names, e.g., global, saudi, uae. By default, global is used")
4448
viper.BindPFlag("region", RootCmd.PersistentFlags().Lookup("region"))
4549
viper.BindEnv("region", "APPKNOX_API_REGION")

helper/cicheck.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"fmt"
77
"os"
88
"time"
9-
9+
1010
"github.com/appknox/appknox-go/appknox"
1111
"github.com/appknox/appknox-go/appknox/enums"
12+
"github.com/spf13/viper"
1213
"github.com/cheynewallace/tabby"
1314
"github.com/vbauerster/mpb/v4"
1415
"github.com/vbauerster/mpb/v4/decor"
@@ -20,6 +21,9 @@ func ProcessCiCheck(fileID, riskThreshold int) {
2021
client := getClient()
2122
var staticScanProgess int
2223
start := time.Now()
24+
timeoutMinutes := viper.GetInt("timeout")
25+
timeout := time.Duration(timeoutMinutes) * time.Minute
26+
fmt.Printf("Starting scan at: %v with timeout of %d minutes\n", start.Format(time.RFC3339), timeoutMinutes)
2327
p := mpb.New(
2428
mpb.WithWidth(60),
2529
mpb.WithRefreshRate(180*time.Millisecond),
@@ -44,7 +48,8 @@ func ProcessCiCheck(fileID, riskThreshold int) {
4448
}
4549
staticScanProgess = file.StaticScanProgress
4650
bar.SetCurrent(int64(staticScanProgess), time.Since(start))
47-
if time.Since(start) > 30*time.Minute {
51+
52+
if time.Since(start) > timeout {
4853
err := errors.New("Request timed out")
4954
PrintError(err)
5055
os.Exit(1)

0 commit comments

Comments
 (0)