Skip to content

Commit 993544e

Browse files
Merge pull request #395 from viveksahu26/feat/add_timeout_flag
add timeout flag for cutomization(default to 60s)
2 parents 81b872b + 9387900 commit 993544e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cmd/dtrackScore.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func extractArgs(cmd *cobra.Command, args []string) (*engine.DtParams, error) {
8383
params.ProjectIDs = append(params.ProjectIDs, argID)
8484
}
8585

86+
params.Timeout, _ = cmd.Flags().GetInt("timeout")
87+
8688
return params, nil
8789
}
8890

@@ -108,4 +110,5 @@ func init() {
108110
dtrackScoreCmd.Flags().BoolP("basic", "b", false, "results in single line format")
109111

110112
dtrackScoreCmd.Flags().BoolP("tag-project-with-score", "t", false, "tag project with sbomqs score")
113+
dtrackScoreCmd.Flags().IntP("timeout", "i", 60, "Timeout in seconds for Dependency-Track API requests")
111114
}

pkg/engine/dtrack.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"os"
2121
"strings"
22+
"time"
2223

2324
dtrack "github.com/DependencyTrack/client-go"
2425
"github.com/google/uuid"
@@ -39,6 +40,7 @@ type DtParams struct {
3940
Detailed bool
4041

4142
TagProjectWithScore bool
43+
Timeout int // handle cutom timeout
4244
}
4345

4446
func DtrackScore(ctx context.Context, dtP *DtParams) error {
@@ -47,8 +49,12 @@ func DtrackScore(ctx context.Context, dtP *DtParams) error {
4749

4850
log.Debugf("Config: %+v", dtP)
4951

52+
timeout := time.Duration(dtP.Timeout) * time.Second
53+
54+
log.Debug("Timeout set to: ", timeout)
55+
5056
dTrackClient, err := dtrack.NewClient(dtP.URL,
51-
dtrack.WithAPIKey(dtP.APIKey), dtrack.WithDebug(false))
57+
dtrack.WithAPIKey(dtP.APIKey), dtrack.WithTimeout(timeout), dtrack.WithDebug(false))
5258
if err != nil {
5359
log.Fatalf("Failed to create Dependency-Track client: %s", err)
5460
}

0 commit comments

Comments
 (0)