From f0337e46c10c83d78e4d41be877622d6bffb3677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Thu, 16 Sep 2021 09:15:10 +0200 Subject: [PATCH] feat(cli): max number of retries for HTTP calls from env variable (#5934) Signed-off-by: francois samin --- cli/cdsctl/config.go | 6 ++++++ cli/cdsctl/main.go | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cli/cdsctl/config.go b/cli/cdsctl/config.go index 10aefcd974..77839fa90a 100644 --- a/cli/cdsctl/config.go +++ b/cli/cdsctl/config.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "path" + "strconv" "github.com/fsamin/go-repo" "github.com/pkg/errors" @@ -118,12 +119,17 @@ func loadConfig(cmd *cobra.Command) (string, *cdsclient.Config, error) { return "", nil, cli.NewError("invalid cdsctl configuration to reach a CDS API") } + // Get max retry config from environment only + configNbRetryFromEnv := os.Getenv("CDS_HTTP_MAX_RETRY") + configNbRetry, _ := strconv.ParseInt(configNbRetryFromEnv, 10, 64) + config := &cdsclient.Config{ Host: cdsctx.Host, SessionToken: cdsctx.Session, BuitinConsumerAuthenticationToken: cdsctx.Token, Verbose: verbose, InsecureSkipVerifyTLS: insecureSkipVerifyTLS, + Retry: int(configNbRetry), } return configFile, config, nil diff --git a/cli/cdsctl/main.go b/cli/cdsctl/main.go index 87527c2822..b92a0a13d7 100644 --- a/cli/cdsctl/main.go +++ b/cli/cdsctl/main.go @@ -117,10 +117,16 @@ If you're using a self-signed certificate on CDS API, you probably want to use ` CDS_INSECURE=true cdsctl [command] -For advanced usage, you can use a session-token instead of a token: +Advanced usages: + +* you can use a session-token instead of a token: CDS_API_URL="https://instance.cds.api" CDS_USER="username" CDS_SESSION_TOKEN="yourtoken" cdsctl [command] +* you define a maximum number of retries for HTTP calls: + + CDS_API_URL="https://instance.cds.api" CDS_SESSION_TOKEN="yourtoken" CDS_HTTP_MAX_RETRY=10 cdsctl [command] + `, }