open-vault/builtin/logical/consul/client.go
Rémi Lapeyre bf4c4595f3
secrets/consul: Add support to auto-bootstrap Consul ACL system (#10751)
* Automatically bootstraps the Consul ACL system if no management token is given on the access config
2022-04-20 17:16:15 -05:00

27 lines
573 B
Go

package consul
import (
"context"
"fmt"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/vault/sdk/logical"
)
func (b *backend) client(ctx context.Context, s logical.Storage) (*api.Client, error, error) {
conf, userErr, intErr := b.readConfigAccess(ctx, s)
if intErr != nil {
return nil, nil, intErr
}
if userErr != nil {
return nil, userErr, nil
}
if conf == nil {
return nil, nil, fmt.Errorf("no error received but no configuration found")
}
consulConf := conf.NewConfig()
client, err := api.NewClient(consulConf)
return client, nil, err
}