Merge pull request #15071 from wafuwafu13/refactor-gettoken

clientv3: refactor getToken automatically
This commit is contained in:
Sahdev Zala 2023-01-15 18:26:21 -05:00 committed by GitHub
commit 7daec2928a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,15 +109,12 @@ func (c *Client) streamClientInterceptor(optFuncs ...retryOption) grpc.StreamCli
intOpts := reuseOrNewWithCallOptions(defaultOptions, optFuncs) 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) { 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) ctx = withVersion(ctx)
// getToken automatically // getToken automatically. Otherwise, auth token may be invalid after watch reconnection because the token has expired
// TODO(cfc4n): keep this code block, remove codes about getToken in client.go after pr #12165 merged. // (see https://github.com/etcd-io/etcd/issues/11954 for more).
if c.authTokenBundle != nil { err := c.getToken(ctx)
// equal to c.Username != "" && c.Password != "" if err != nil {
err := c.getToken(ctx) c.GetLogger().Error("clientv3/retry_interceptor: getToken failed", zap.Error(err))
if err != nil && rpctypes.Error(err) != rpctypes.ErrAuthNotEnabled { return nil, err
c.GetLogger().Error("clientv3/retry_interceptor: getToken failed", zap.Error(err))
return nil, err
}
} }
grpcOpts, retryOpts := filterCallOptions(opts) grpcOpts, retryOpts := filterCallOptions(opts)
callOpts := reuseOrNewWithCallOptions(intOpts, retryOpts) callOpts := reuseOrNewWithCallOptions(intOpts, retryOpts)