diff --git a/physical/consul.go b/physical/consul.go index 9f3e427595..07675e6746 100644 --- a/physical/consul.go +++ b/physical/consul.go @@ -67,6 +67,7 @@ type ConsulBackend struct { serviceTags []string disableRegistration bool checkTimeout time.Duration + requireConsistent bool notifyActiveCh 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 c := &ConsulBackend{ path: path, @@ -204,6 +215,7 @@ func newConsulBackend(conf map[string]string, logger log.Logger) (Backend, error serviceTags: strutil.ParseDedupAndSortStrings(tags, ","), checkTimeout: checkTimeout, disableRegistration: disableRegistration, + requireConsistent: requireConsistent, } return c, nil } @@ -285,7 +297,14 @@ func (c *ConsulBackend) Get(key string) (*Entry, error) { c.permitPool.Acquire() 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 { return nil, err }