From 40b71074e82b421568a8bd38d368f8a87e510d69 Mon Sep 17 00:00:00 2001 From: CFC4N Date: Wed, 16 Sep 2020 23:15:29 +0800 Subject: [PATCH] clientv3: get AuthToken automatically when clientConn is ready. fixes: #11954 --- clientv3/retry_interceptor.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clientv3/retry_interceptor.go b/clientv3/retry_interceptor.go index 2c266e55bec..29db576909d 100644 --- a/clientv3/retry_interceptor.go +++ b/clientv3/retry_interceptor.go @@ -105,6 +105,16 @@ func (c *Client) streamClientInterceptor(logger *zap.Logger, optFuncs ...retryOp intOpts := reuseOrNewWithCallOptions(defaultOptions, optFuncs) return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) { ctx = withVersion(ctx) + // getToken automatically + // TODO(cfc4n): keep this code block, remove codes about getToken in client.go after pr #12165 merged. + if c.authTokenBundle != nil { + // equal to c.Username != "" && c.Password != "" + err := c.getToken(ctx) + if err != nil && rpctypes.Error(err) != rpctypes.ErrAuthNotEnabled { + logger.Error("clientv3/retry_interceptor: getToken failed", zap.Error(err)) + return nil, err + } + } grpcOpts, retryOpts := filterCallOptions(opts) callOpts := reuseOrNewWithCallOptions(intOpts, retryOpts) // short circuit for simplicity, and avoiding allocations.