-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
api/client.go
Outdated
@@ -215,6 +228,10 @@ func (c *Config) ReadEnvironment() error { | |||
c.MaxRetries = int(*envMaxRetries) + 1 | |||
} | |||
|
|||
if envClientTimeout != time.Second*0 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
Looks good, thank you! |
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.