Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option to set custom vault client timeout using env variable VAULT_CLIENT_TIMEOUT #3022

Merged
merged 4 commits into from
Jul 18, 2017

Conversation

gobins
Copy link
Contributor

@gobins gobins commented Jul 16, 2017

Fixes #2956

Option to set the vault client timeout using env var VAULT_CLIENT_TIMEOUT has been added.
Added a new function SetClientTimeout which can set the client timeout through api config.

api/client.go Outdated
@@ -183,6 +184,13 @@ func (c *Config) ReadEnvironment() error {
if v := os.Getenv(EnvVaultClientKey); v != "" {
envClientKey = v
}
if t := os.Getenv(EnvVaultClientTimeout); t != "" {
clientTimeout, err := strconv.ParseUint(t, 10, 32)
Copy link
Member

@jefferai jefferai Jul 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use parseutil.ParseDurationSecond.

api/client.go Outdated
if err != nil {
return err
}
c.HttpClient.Timeout = time.Second * time.Duration(clientTimeout)
Copy link
Member

@jefferai jefferai Jul 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HTTP client might be nil here, and this is not the right place to create one. You should create a timeout variable in the Config struct, and assign it here (and in the set function). Then move the actual logic to the request function so that the current value (e.g. if it's set with SetClientTimeout below) will be used for the current request.

@jefferai jefferai added this to the 0.7.4 milestone Jul 16, 2017
api/client.go Outdated
@@ -215,6 +228,10 @@ func (c *Config) ReadEnvironment() error {
c.MaxRetries = int(*envMaxRetries) + 1
}

if envClientTimeout != time.Second*0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be != 0.

api/client.go Outdated
@@ -362,6 +384,9 @@ func (c *Client) NewRequest(method, requestPath string) *Request {
} else {
req.WrapTTL = DefaultWrappingLookupFunc(method, lookupPath)
}
if c.config.Timeout != time.Second*0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

@jefferai
Copy link
Member

Looks good, thank you!

@jefferai jefferai merged commit 638ef2c into hashicorp:master Jul 18, 2017
@gobins gobins deleted the client-timeout branch July 18, 2017 22:47
@jefferai jefferai modified the milestones: 0.7.4, 0.8.0 Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants