Skip to content

Commit a7e7707

Browse files
committed
fix(options): Add credentials providers to universal options and pass to client options
1 parent 7dcb49a commit a7e7707

File tree

3 files changed

+83
-25
lines changed

3 files changed

+83
-25
lines changed

ring.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/cespare/xxhash/v2"
1515
"github.com/dgryski/go-rendezvous" //nolint
16+
"github.com/redis/go-redis/v9/auth"
1617

1718
"github.com/redis/go-redis/v9/internal"
1819
"github.com/redis/go-redis/v9/internal/hashtag"
@@ -70,11 +71,27 @@ type RingOptions struct {
7071
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
7172
OnConnect func(ctx context.Context, cn *Conn) error
7273

73-
Protocol int
74-
Username string
75-
Password string
74+
Protocol int
75+
Username string
76+
Password string
77+
// CredentialsProvider allows the username and password to be updated
78+
// before reconnecting. It should return the current username and password.
7679
CredentialsProvider func() (username string, password string)
77-
DB int
80+
81+
// CredentialsProviderContext is an enhanced parameter of CredentialsProvider,
82+
// done to maintain API compatibility. In the future,
83+
// there might be a merge between CredentialsProviderContext and CredentialsProvider.
84+
// There will be a conflict between them; if CredentialsProviderContext exists, we will ignore CredentialsProvider.
85+
CredentialsProviderContext func(ctx context.Context) (username string, password string, err error)
86+
87+
// StreamingCredentialsProvider is used to retrieve the credentials
88+
// for the connection from an external source. Those credentials may change
89+
// during the connection lifetime. This is useful for managed identity
90+
// scenarios where the credentials are retrieved from an external source.
91+
//
92+
// Currently, this is a placeholder for the future implementation.
93+
StreamingCredentialsProvider auth.StreamingCredentialsProvider
94+
DB int
7895

7996
MaxRetries int
8097
MinRetryBackoff time.Duration

sentinel.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"sync"
1313
"time"
1414

15+
"github.com/redis/go-redis/v9/auth"
1516
"github.com/redis/go-redis/v9/internal"
1617
"github.com/redis/go-redis/v9/internal/pool"
1718
"github.com/redis/go-redis/v9/internal/rand"
@@ -57,11 +58,27 @@ type FailoverOptions struct {
5758
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
5859
OnConnect func(ctx context.Context, cn *Conn) error
5960

60-
Protocol int
61-
Username string
62-
Password string
61+
Protocol int
62+
Username string
63+
Password string
64+
// CredentialsProvider allows the username and password to be updated
65+
// before reconnecting. It should return the current username and password.
6366
CredentialsProvider func() (username string, password string)
64-
DB int
67+
68+
// CredentialsProviderContext is an enhanced parameter of CredentialsProvider,
69+
// done to maintain API compatibility. In the future,
70+
// there might be a merge between CredentialsProviderContext and CredentialsProvider.
71+
// There will be a conflict between them; if CredentialsProviderContext exists, we will ignore CredentialsProvider.
72+
CredentialsProviderContext func(ctx context.Context) (username string, password string, err error)
73+
74+
// StreamingCredentialsProvider is used to retrieve the credentials
75+
// for the connection from an external source. Those credentials may change
76+
// during the connection lifetime. This is useful for managed identity
77+
// scenarios where the credentials are retrieved from an external source.
78+
//
79+
// Currently, this is a placeholder for the future implementation.
80+
StreamingCredentialsProvider auth.StreamingCredentialsProvider
81+
DB int
6582

6683
MaxRetries int
6784
MinRetryBackoff time.Duration

universal.go

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"crypto/tls"
66
"net"
77
"time"
8+
9+
"github.com/redis/go-redis/v9/auth"
810
)
911

1012
// UniversalOptions information is required by UniversalClient to establish
@@ -26,11 +28,27 @@ type UniversalOptions struct {
2628
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
2729
OnConnect func(ctx context.Context, cn *Conn) error
2830

29-
Protocol int
30-
Username string
31-
Password string
31+
Protocol int
32+
Username string
33+
Password string
34+
// CredentialsProvider allows the username and password to be updated
35+
// before reconnecting. It should return the current username and password.
3236
CredentialsProvider func() (username string, password string)
3337

38+
// CredentialsProviderContext is an enhanced parameter of CredentialsProvider,
39+
// done to maintain API compatibility. In the future,
40+
// there might be a merge between CredentialsProviderContext and CredentialsProvider.
41+
// There will be a conflict between them; if CredentialsProviderContext exists, we will ignore CredentialsProvider.
42+
CredentialsProviderContext func(ctx context.Context) (username string, password string, err error)
43+
44+
// StreamingCredentialsProvider is used to retrieve the credentials
45+
// for the connection from an external source. Those credentials may change
46+
// during the connection lifetime. This is useful for managed identity
47+
// scenarios where the credentials are retrieved from an external source.
48+
//
49+
// Currently, this is a placeholder for the future implementation.
50+
StreamingCredentialsProvider auth.StreamingCredentialsProvider
51+
3452
SentinelUsername string
3553
SentinelPassword string
3654

@@ -98,10 +116,12 @@ func (o *UniversalOptions) Cluster() *ClusterOptions {
98116
Dialer: o.Dialer,
99117
OnConnect: o.OnConnect,
100118

101-
Protocol: o.Protocol,
102-
Username: o.Username,
103-
Password: o.Password,
104-
CredentialsProvider: o.CredentialsProvider,
119+
Protocol: o.Protocol,
120+
Username: o.Username,
121+
Password: o.Password,
122+
CredentialsProvider: o.CredentialsProvider,
123+
CredentialsProviderContext: o.CredentialsProviderContext,
124+
StreamingCredentialsProvider: o.StreamingCredentialsProvider,
105125

106126
MaxRedirects: o.MaxRedirects,
107127
ReadOnly: o.ReadOnly,
@@ -150,11 +170,13 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
150170
Dialer: o.Dialer,
151171
OnConnect: o.OnConnect,
152172

153-
DB: o.DB,
154-
Protocol: o.Protocol,
155-
Username: o.Username,
156-
Password: o.Password,
157-
CredentialsProvider: o.CredentialsProvider,
173+
DB: o.DB,
174+
Protocol: o.Protocol,
175+
Username: o.Username,
176+
Password: o.Password,
177+
CredentialsProvider: o.CredentialsProvider,
178+
CredentialsProviderContext: o.CredentialsProviderContext,
179+
StreamingCredentialsProvider: o.StreamingCredentialsProvider,
158180

159181
SentinelUsername: o.SentinelUsername,
160182
SentinelPassword: o.SentinelPassword,
@@ -204,11 +226,13 @@ func (o *UniversalOptions) Simple() *Options {
204226
Dialer: o.Dialer,
205227
OnConnect: o.OnConnect,
206228

207-
DB: o.DB,
208-
Protocol: o.Protocol,
209-
Username: o.Username,
210-
Password: o.Password,
211-
CredentialsProvider: o.CredentialsProvider,
229+
DB: o.DB,
230+
Protocol: o.Protocol,
231+
Username: o.Username,
232+
Password: o.Password,
233+
CredentialsProvider: o.CredentialsProvider,
234+
CredentialsProviderContext: o.CredentialsProviderContext,
235+
StreamingCredentialsProvider: o.StreamingCredentialsProvider,
212236

213237
MaxRetries: o.MaxRetries,
214238
MinRetryBackoff: o.MinRetryBackoff,

0 commit comments

Comments
 (0)