mirror of
https://github.com/hashicorp/vault.git
synced 2025-09-03 21:11:10 +02:00
add a option for strong consistancy for consul
This commit is contained in:
parent
fc1d75032b
commit
2baf39f050
@ -67,6 +67,7 @@ type ConsulBackend struct {
|
|||||||
serviceTags []string
|
serviceTags []string
|
||||||
disableRegistration bool
|
disableRegistration bool
|
||||||
checkTimeout time.Duration
|
checkTimeout time.Duration
|
||||||
|
requireConsistent bool
|
||||||
|
|
||||||
notifyActiveCh chan notifyEvent
|
notifyActiveCh chan notifyEvent
|
||||||
notifySealedCh chan notifyEvent
|
notifySealedCh chan notifyEvent
|
||||||
@ -193,6 +194,16 @@ func newConsulBackend(conf map[string]string, logger log.Logger) (Backend, error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
requireConsistentRaw, ok := conf["require_consistent"]
|
||||||
|
var requireConsistent bool
|
||||||
|
if ok {
|
||||||
|
b, err := strconv.ParseBool(requireConsistentRaw)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errwrap.Wrapf("failed parsing require_consistent parameter: {{err}}", err)
|
||||||
|
}
|
||||||
|
requireConsistent = b
|
||||||
|
}
|
||||||
|
|
||||||
// Setup the backend
|
// Setup the backend
|
||||||
c := &ConsulBackend{
|
c := &ConsulBackend{
|
||||||
path: path,
|
path: path,
|
||||||
@ -204,6 +215,7 @@ func newConsulBackend(conf map[string]string, logger log.Logger) (Backend, error
|
|||||||
serviceTags: strutil.ParseDedupAndSortStrings(tags, ","),
|
serviceTags: strutil.ParseDedupAndSortStrings(tags, ","),
|
||||||
checkTimeout: checkTimeout,
|
checkTimeout: checkTimeout,
|
||||||
disableRegistration: disableRegistration,
|
disableRegistration: disableRegistration,
|
||||||
|
requireConsistent: requireConsistent,
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
@ -285,7 +297,14 @@ func (c *ConsulBackend) Get(key string) (*Entry, error) {
|
|||||||
c.permitPool.Acquire()
|
c.permitPool.Acquire()
|
||||||
defer c.permitPool.Release()
|
defer c.permitPool.Release()
|
||||||
|
|
||||||
pair, _, err := c.kv.Get(c.path+key, nil)
|
var queryOptions *api.QueryOptions
|
||||||
|
if c.requireConsistent {
|
||||||
|
queryOptions = &api.QueryOptions{
|
||||||
|
RequireConsistent: c.requireConsistent,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pair, _, err := c.kv.Get(c.path+key, queryOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user