diff --git a/cmd/rekor-cli/app/get.go b/cmd/rekor-cli/app/get.go index 85817ef2c..df5bdea6d 100644 --- a/cmd/rekor-cli/app/get.go +++ b/cmd/rekor-cli/app/get.go @@ -86,6 +86,7 @@ var getCmd = &cobra.Command{ logIndex := viper.GetString("log-index") if logIndex != "" { params := entries.NewGetLogEntryByIndexParams() + params.SetTimeout(viper.GetDuration("timeout")) logIndexInt, err := strconv.ParseInt(logIndex, 10, 0) if err != nil { return nil, fmt.Errorf("error parsing --log-index: %w", err) @@ -108,6 +109,7 @@ var getCmd = &cobra.Command{ uuid := viper.GetString("uuid") if uuid != "" { params := entries.NewGetLogEntryByUUIDParams() + params.SetTimeout(viper.GetDuration("timeout")) params.EntryUUID = uuid resp, err := rekorClient.Entries.GetLogEntryByUUID(params) diff --git a/cmd/rekor-cli/app/log_info.go b/cmd/rekor-cli/app/log_info.go index 767185788..bb2493e81 100644 --- a/cmd/rekor-cli/app/log_info.go +++ b/cmd/rekor-cli/app/log_info.go @@ -67,7 +67,9 @@ var logInfoCmd = &cobra.Command{ return nil, err } - result, err := rekorClient.Tlog.GetLogInfo(nil) + params := tlog.GetLogInfoParams{} + params.SetTimeout(viper.GetDuration("timeout")) + result, err := rekorClient.Tlog.GetLogInfo(¶ms) if err != nil { return nil, err } diff --git a/cmd/rekor-cli/app/log_proof.go b/cmd/rekor-cli/app/log_proof.go index b136572eb..c682d5b93 100644 --- a/cmd/rekor-cli/app/log_proof.go +++ b/cmd/rekor-cli/app/log_proof.go @@ -83,6 +83,7 @@ var logProofCmd = &cobra.Command{ params := tlog.NewGetLogProofParams() params.FirstSize = &firstSize params.LastSize = lastSize + params.SetTimeout(viper.GetDuration("timeout")) result, err := rekorClient.Tlog.GetLogProof(params) if err != nil { diff --git a/cmd/rekor-cli/app/pflags.go b/cmd/rekor-cli/app/pflags.go index 78c01ac2f..a144a9086 100644 --- a/cmd/rekor-cli/app/pflags.go +++ b/cmd/rekor-cli/app/pflags.go @@ -20,6 +20,7 @@ import ( "log" "strconv" "strings" + "time" "github.com/sigstore/rekor/pkg/pki" "github.com/spf13/pflag" @@ -42,6 +43,7 @@ const ( fileOrURLFlag FlagType = "fileOrURL" oidFlag FlagType = "oid" formatFlag FlagType = "format" + timeoutFlag FlagType = "timeout" ) type newPFlagValueFunc func() pflag.Value @@ -95,6 +97,10 @@ func initializePFlagMap() { // this validates the output format requested return valueFactory(formatFlag, validateString("required,oneof=json default"), "") }, + timeoutFlag: func() pflag.Value { + // this validates the timeout is >= 0 + return valueFactory(formatFlag, validateTimeout, "") + }, } } @@ -210,6 +216,18 @@ func validateOID(v string) error { return useValidator(oidFlag, o) } +// validateTimeout ensures that the supplied string is a valid time.Duration value >= 0 +func validateTimeout(v string) error { + duration, err := time.ParseDuration(v) + if err != nil { + return err + } + d := struct { + Duration time.Duration `validate:"min=0"` + }{duration} + return useValidator(timeoutFlag, d) +} + // validateTypeFlag ensures that the string is in the format type(\.version)? and // that one of the types requested is implemented func validateTypeFlag(v string) error { diff --git a/cmd/rekor-cli/app/root.go b/cmd/rekor-cli/app/root.go index 5114d18a3..67f2333c0 100644 --- a/cmd/rekor-cli/app/root.go +++ b/cmd/rekor-cli/app/root.go @@ -59,6 +59,7 @@ func init() { rootCmd.PersistentFlags().Var(NewFlagValue(urlFlag, "https://rekor.sigstore.dev"), "rekor_server", "Server address:port") rootCmd.PersistentFlags().Var(NewFlagValue(formatFlag, "default"), "format", "Command output format") + rootCmd.PersistentFlags().Var(NewFlagValue(timeoutFlag, "30s"), "timeout", "HTTP timeout") rootCmd.PersistentFlags().String("api-key", "", "API key for rekor.sigstore.dev") diff --git a/cmd/rekor-cli/app/search.go b/cmd/rekor-cli/app/search.go index e447d235e..940193f5b 100644 --- a/cmd/rekor-cli/app/search.go +++ b/cmd/rekor-cli/app/search.go @@ -109,6 +109,7 @@ var searchCmd = &cobra.Command{ } params := index.NewSearchIndexParams() + params.SetTimeout(viper.GetDuration("timeout")) params.Query = &models.SearchIndex{} artifactStr := viper.GetString("artifact") diff --git a/cmd/rekor-cli/app/timestamp.go b/cmd/rekor-cli/app/timestamp.go index 948709369..62b6e3026 100644 --- a/cmd/rekor-cli/app/timestamp.go +++ b/cmd/rekor-cli/app/timestamp.go @@ -154,6 +154,7 @@ var timestampCmd = &cobra.Command{ } params := timestamp.NewGetTimestampResponseParams() + params.SetTimeout(viper.GetDuration("timeout")) params.Request = ioutil.NopCloser(bytes.NewReader(requestBytes)) var respBytes bytes.Buffer diff --git a/cmd/rekor-cli/app/upload.go b/cmd/rekor-cli/app/upload.go index f7a97de23..7b4efce84 100644 --- a/cmd/rekor-cli/app/upload.go +++ b/cmd/rekor-cli/app/upload.go @@ -78,6 +78,7 @@ var uploadCmd = &cobra.Command{ } var entry models.ProposedEntry params := entries.NewCreateLogEntryParams() + params.SetTimeout(viper.GetDuration("timeout")) entryStr := viper.GetString("entry") if entryStr != "" { diff --git a/cmd/rekor-cli/app/verify.go b/cmd/rekor-cli/app/verify.go index 1ef3bdb21..80e071c0a 100644 --- a/cmd/rekor-cli/app/verify.go +++ b/cmd/rekor-cli/app/verify.go @@ -91,6 +91,7 @@ var verifyCmd = &cobra.Command{ } searchParams := entries.NewSearchLogQueryParams() + searchParams.SetTimeout(viper.GetDuration("timeout")) searchLogQuery := models.SearchLogQuery{} uuid := viper.GetString("uuid")