2015-03-21 16:19:37 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/api"
|
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
)
|
|
|
|
|
2016-05-24 18:23:27 +00:00
|
|
|
func client(s logical.Storage) (*api.Client, error, error) {
|
|
|
|
conf, userErr, intErr := readConfigAccess(s)
|
|
|
|
if intErr != nil {
|
|
|
|
return nil, nil, intErr
|
2015-03-21 16:19:37 +00:00
|
|
|
}
|
2016-05-24 18:23:27 +00:00
|
|
|
if userErr != nil {
|
|
|
|
return nil, userErr, nil
|
2015-03-21 16:19:37 +00:00
|
|
|
}
|
2016-05-24 18:23:27 +00:00
|
|
|
if conf == nil {
|
|
|
|
return nil, nil, fmt.Errorf("no error received but no configuration found")
|
2015-03-21 16:19:37 +00:00
|
|
|
}
|
|
|
|
|
2016-05-18 00:47:42 +00:00
|
|
|
consulConf := api.DefaultNonPooledConfig()
|
2015-03-21 16:19:37 +00:00
|
|
|
consulConf.Address = conf.Address
|
|
|
|
consulConf.Scheme = conf.Scheme
|
|
|
|
consulConf.Token = conf.Token
|
|
|
|
|
2016-05-24 18:23:27 +00:00
|
|
|
client, err := api.NewClient(consulConf)
|
|
|
|
return client, nil, err
|
2015-03-21 16:19:37 +00:00
|
|
|
}
|