provide timeout option and lower default

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-03-10 01:04:58 +03:00
parent 68696aebd5
commit 16cde1bfae
2 changed files with 14 additions and 0 deletions

View File

@ -1,6 +1,8 @@
package vault
import (
"time"
"github.com/hashicorp/vault/api"
"github.com/unistack-org/micro/v3/config"
)
@ -40,3 +42,9 @@ type secretIDKey struct{}
func SecretID(secret string) config.Option {
return config.SetOption(secretIDKey{}, secret)
}
type timeoutKey struct{}
func Timeout(td time.Duration) config.Option {
return config.SetOption(timeoutKey{}, td)
}

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"time"
"github.com/hashicorp/vault/api"
"github.com/imdario/mergo"
@ -36,6 +37,7 @@ func (c *vaultConfig) Init(opts ...config.Option) error {
}
cfg := api.DefaultConfig()
cfg.Timeout = 3 * time.Second
path := ""
token := ""
roleID := ""
@ -46,6 +48,10 @@ func (c *vaultConfig) Init(opts ...config.Option) error {
cfg = v
}
if v, ok := c.opts.Context.Value(timeoutKey{}).(time.Duration); ok {
cfg.Timeout = v
}
if v, ok := c.opts.Context.Value(addrKey{}).(string); ok {
cfg.Address = v
}