Skip to content

Commit

Permalink
use same timeout value for http client & graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelDriowya committed Nov 6, 2023
1 parent b35e35d commit 7ab8634
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 8 additions & 0 deletions api/header/global.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package header

import "time"

// When the CLI is initialized, we set this to a string of the current CLI subcommand
// (e.g. `circleci orb list`) with no args or flags, so we include it as a header in API requests.
var cliCommandStr string = ""
Expand All @@ -11,3 +13,9 @@ func SetCommandStr(commandStr string) {
func GetCommandStr() string {
return cliCommandStr
}

const defaultTimeout = 60 * time.Second

func GetDefaultTimeout() time.Duration {
return defaultTimeout
}
4 changes: 1 addition & 3 deletions api/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
"github.com/CircleCI-Public/circleci-cli/version"
)

const defaultTimeout = 10 * time.Second

type Client struct {
BaseURL *url.URL
circleToken string
Expand All @@ -41,7 +39,7 @@ func NewFromConfig(host string, config *settings.Config) *Client {
}

baseURL, _ := url.Parse(host)
timeout := defaultTimeout
timeout := header.GetDefaultTimeout()
if timeoutEnv, ok := os.LookupEnv("CIRCLECI_CLI_TIMEOUT"); ok {
if parsedTimeout, err := time.ParseDuration(timeoutEnv); err == nil {
timeout = parsedTimeout
Expand Down
3 changes: 2 additions & 1 deletion settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

yaml "gopkg.in/yaml.v3"

"github.com/CircleCI-Public/circleci-cli/api/header"
"github.com/CircleCI-Public/circleci-cli/data"
"github.com/spf13/afero"
)
Expand Down Expand Up @@ -287,7 +288,7 @@ func (cfg *Config) WithHTTPClient() error {
customTransport.TLSClientConfig = tlsConfig

cfg.HTTPClient = &http.Client{
Timeout: 60 * time.Second,
Timeout: header.GetDefaultTimeout(),
Transport: customTransport,
}

Expand Down

0 comments on commit 7ab8634

Please sign in to comment.