2015-03-21 16:19:37 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
2018-01-19 06:44:44 +00:00
|
|
|
"context"
|
2015-03-21 16:19:37 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/api"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2015-03-21 16:19:37 +00:00
|
|
|
)
|
|
|
|
|
2018-11-02 14:44:12 +00:00
|
|
|
func (b *backend) client(ctx context.Context, s logical.Storage) (*api.Client, error, error) {
|
|
|
|
conf, userErr, intErr := b.readConfigAccess(ctx, s)
|
2016-05-24 18:23:27 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-20 22:16:15 +00:00
|
|
|
consulConf := conf.NewConfig()
|
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
|
|
|
}
|