Compare commits

4 Commits

Author SHA1 Message Date
16cde1bfae provide timeout option and lower default
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-03-10 01:05:05 +03:00
Renovate Bot
68696aebd5 Update module github.com/unistack-org/micro/v3 to v3.2.20 2021-03-07 02:21:05 +00:00
Renovate Bot
8d46e8b45a Update module github.com/unistack-org/micro/v3 to v3.2.17 2021-03-05 18:32:48 +00:00
cb81c3f768 fixup error
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-03-05 17:02:17 +03:00
4 changed files with 26 additions and 1 deletions

2
go.mod
View File

@@ -7,7 +7,7 @@ require (
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/vault/api v1.0.4
github.com/imdario/mergo v0.3.11
github.com/unistack-org/micro/v3 v3.2.16
github.com/unistack-org/micro/v3 v3.2.20
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 // indirect
gopkg.in/square/go-jose.v2 v2.4.1 // indirect
)

3
go.sum
View File

@@ -85,6 +85,9 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/unistack-org/micro/v3 v3.2.16 h1:eQwEJr7RiB0jvOSAil+c6t2C1zW7MpfFAVx2u9PmItM=
github.com/unistack-org/micro/v3 v3.2.16/go.mod h1:y+fV+BPNK2IqGoLquRU396jTYifG0HCw3zxFfI4E0dc=
github.com/unistack-org/micro/v3 v3.2.17 h1:WNkkcKj1NMLViH9YgSDJRA2PJxIaDmY3GQBjHQV20DU=
github.com/unistack-org/micro/v3 v3.2.17/go.mod h1:y+fV+BPNK2IqGoLquRU396jTYifG0HCw3zxFfI4E0dc=
github.com/unistack-org/micro/v3 v3.2.20/go.mod h1:y+fV+BPNK2IqGoLquRU396jTYifG0HCw3zxFfI4E0dc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=

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
}
@@ -70,6 +76,8 @@ func (c *vaultConfig) Init(opts ...config.Option) error {
cli, err := api.NewClient(cfg)
if err != nil && !c.opts.AllowFail {
return nil
} else if err != nil {
return err
}
@@ -99,6 +107,12 @@ func (c *vaultConfig) Load(ctx context.Context) error {
}
}
if c.cli == nil && !c.opts.AllowFail {
return ErrPathNotExist
} else if c.cli == nil && c.opts.AllowFail {
return nil
}
pair, err := c.cli.Logical().Read(c.path)
if err != nil && !c.opts.AllowFail {
return err