feat: support auth account for etcd (#1174)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/tal-tech/go-zero/core/discov"
|
||||
"github.com/tal-tech/go-zero/zrpc/internal"
|
||||
"github.com/tal-tech/go-zero/zrpc/internal/auth"
|
||||
"google.golang.org/grpc"
|
||||
@@ -74,6 +75,10 @@ func NewClient(c RpcClientConf, options ...ClientOption) (Client, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.Etcd.HasAccount() {
|
||||
discov.RegisterAccount(c.Etcd.Hosts, c.Etcd.User, c.Etcd.Pass)
|
||||
}
|
||||
|
||||
target = internal.BuildDiscovTarget(c.Etcd.Hosts, c.Etcd.Key)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,14 @@ const (
|
||||
)
|
||||
|
||||
// NewRpcPubServer returns a Server.
|
||||
func NewRpcPubServer(etcdEndpoints []string, etcdKey, listenOn string,
|
||||
opts ...ServerOption) (Server, error) {
|
||||
func NewRpcPubServer(etcd discov.EtcdConf, listenOn string, opts ...ServerOption) (Server, error) {
|
||||
registerEtcd := func() error {
|
||||
pubListenOn := figureOutListenOn(listenOn)
|
||||
pubClient := discov.NewPublisher(etcdEndpoints, etcdKey, pubListenOn)
|
||||
var pubOpts []discov.PubOption
|
||||
if etcd.HasAccount() {
|
||||
pubOpts = append(pubOpts, discov.WithPubEtcdAccount(etcd.User, etcd.Pass))
|
||||
}
|
||||
pubClient := discov.NewPublisher(etcd.Hosts, etcd.Key, pubListenOn, pubOpts...)
|
||||
return pubClient.KeepAlive()
|
||||
}
|
||||
server := keepAliveServer{
|
||||
|
||||
@@ -41,7 +41,7 @@ func NewServer(c RpcServerConf, register internal.RegisterFn) (*RpcServer, error
|
||||
serverOptions := []internal.ServerOption{internal.WithMetrics(metrics), internal.WithMaxRetries(c.MaxRetries)}
|
||||
|
||||
if c.HasEtcd() {
|
||||
server, err = internal.NewRpcPubServer(c.Etcd.Hosts, c.Etcd.Key, c.ListenOn, serverOptions...)
|
||||
server, err = internal.NewRpcPubServer(c.Etcd, c.ListenOn, serverOptions...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user