Skip to content

Commit

Permalink
feat(cli): max number of retries for HTTP calls from env variable (#5934
Browse files Browse the repository at this point in the history
)

Signed-off-by: francois  samin <[email protected]>
  • Loading branch information
fsamin authored Sep 16, 2021
1 parent 833ebb3 commit f0337e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cli/cdsctl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path"
"strconv"

"github.com/fsamin/go-repo"
"github.com/pkg/errors"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion cli/cdsctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
`,
}

Expand Down

0 comments on commit f0337e4

Please sign in to comment.