Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
16cde1bfae | |||
|
68696aebd5 | ||
|
8d46e8b45a | ||
cb81c3f768 | |||
fbdb6e332b |
2
go.mod
2
go.mod
@@ -7,7 +7,7 @@ require (
|
|||||||
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
|
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
|
||||||
github.com/hashicorp/vault/api v1.0.4
|
github.com/hashicorp/vault/api v1.0.4
|
||||||
github.com/imdario/mergo v0.3.11
|
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
|
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 // indirect
|
||||||
gopkg.in/square/go-jose.v2 v2.4.1 // indirect
|
gopkg.in/square/go-jose.v2 v2.4.1 // indirect
|
||||||
)
|
)
|
||||||
|
3
go.sum
3
go.sum
@@ -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/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 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.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 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
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=
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package vault
|
package vault
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/vault/api"
|
"github.com/hashicorp/vault/api"
|
||||||
"github.com/unistack-org/micro/v3/config"
|
"github.com/unistack-org/micro/v3/config"
|
||||||
)
|
)
|
||||||
@@ -40,3 +42,9 @@ type secretIDKey struct{}
|
|||||||
func SecretID(secret string) config.Option {
|
func SecretID(secret string) config.Option {
|
||||||
return config.SetOption(secretIDKey{}, secret)
|
return config.SetOption(secretIDKey{}, secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type timeoutKey struct{}
|
||||||
|
|
||||||
|
func Timeout(td time.Duration) config.Option {
|
||||||
|
return config.SetOption(timeoutKey{}, td)
|
||||||
|
}
|
||||||
|
17
vault.go
17
vault.go
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/vault/api"
|
"github.com/hashicorp/vault/api"
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
@@ -36,6 +37,7 @@ func (c *vaultConfig) Init(opts ...config.Option) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfg := api.DefaultConfig()
|
cfg := api.DefaultConfig()
|
||||||
|
cfg.Timeout = 3 * time.Second
|
||||||
path := ""
|
path := ""
|
||||||
token := ""
|
token := ""
|
||||||
roleID := ""
|
roleID := ""
|
||||||
@@ -46,6 +48,10 @@ func (c *vaultConfig) Init(opts ...config.Option) error {
|
|||||||
cfg = v
|
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 {
|
if v, ok := c.opts.Context.Value(addrKey{}).(string); ok {
|
||||||
cfg.Address = v
|
cfg.Address = v
|
||||||
}
|
}
|
||||||
@@ -70,6 +76,8 @@ func (c *vaultConfig) Init(opts ...config.Option) error {
|
|||||||
|
|
||||||
cli, err := api.NewClient(cfg)
|
cli, err := api.NewClient(cfg)
|
||||||
if err != nil && !c.opts.AllowFail {
|
if err != nil && !c.opts.AllowFail {
|
||||||
|
return nil
|
||||||
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,8 +88,9 @@ func (c *vaultConfig) Init(opts ...config.Option) error {
|
|||||||
})
|
})
|
||||||
if err != nil && !c.opts.AllowFail {
|
if err != nil && !c.opts.AllowFail {
|
||||||
return err
|
return err
|
||||||
|
} else if err == nil {
|
||||||
|
token = rsp.Auth.ClientToken
|
||||||
}
|
}
|
||||||
token = rsp.Auth.ClientToken
|
|
||||||
}
|
}
|
||||||
cli.SetToken(token)
|
cli.SetToken(token)
|
||||||
|
|
||||||
@@ -98,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)
|
pair, err := c.cli.Logical().Read(c.path)
|
||||||
if err != nil && !c.opts.AllowFail {
|
if err != nil && !c.opts.AllowFail {
|
||||||
return err
|
return err
|
||||||
|
Reference in New Issue
Block a user