open-vault/builtin/logical/consul/client.go
Jeff Mitchell 86e078ff98 Use Consul API client's DefaultNonPooledTransport.
What we should probably do is create a client with a mutex and
invalidate it when parameters change rather than creating a client over
and over...that can be a TODO for later but for now this fix suffices.

Fixes #1428
2016-05-18 00:47:42 +00:00

33 lines
718 B
Go

package consul
import (
"fmt"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/vault/logical"
)
func client(s logical.Storage) (*api.Client, error) {
entry, err := s.Get("config/access")
if err != nil {
return nil, err
}
if entry == nil {
return nil, fmt.Errorf(
"root credentials haven't been configured. Please configure\n" +
"them at the '/root' endpoint")
}
var conf accessConfig
if err := entry.DecodeJSON(&conf); err != nil {
return nil, fmt.Errorf("error reading root configuration: %s", err)
}
consulConf := api.DefaultNonPooledConfig()
consulConf.Address = conf.Address
consulConf.Scheme = conf.Scheme
consulConf.Token = conf.Token
return api.NewClient(consulConf)
}