86e078ff98
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
33 lines
718 B
Go
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)
|
|
}
|