Skip to content

Commit 253fc5e

Browse files
committed
Add CredentialsProvider field to universal client
1 parent d43a9fa commit 253fc5e

File tree

3 files changed

+44
-33
lines changed

3 files changed

+44
-33
lines changed

ring.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ type RingOptions struct {
7070
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
7171
OnConnect func(ctx context.Context, cn *Conn) error
7272

73-
Protocol int
74-
Username string
75-
Password string
76-
DB int
73+
Protocol int
74+
Username string
75+
Password string
76+
CredentialsProvider func() (username string, password string)
77+
DB int
7778

7879
MaxRetries int
7980
MinRetryBackoff time.Duration
@@ -142,10 +143,11 @@ func (opt *RingOptions) clientOptions() *Options {
142143
Dialer: opt.Dialer,
143144
OnConnect: opt.OnConnect,
144145

145-
Protocol: opt.Protocol,
146-
Username: opt.Username,
147-
Password: opt.Password,
148-
DB: opt.DB,
146+
Protocol: opt.Protocol,
147+
Username: opt.Username,
148+
Password: opt.Password,
149+
CredentialsProvider: opt.CredentialsProvider,
150+
DB: opt.DB,
149151

150152
MaxRetries: -1,
151153

sentinel.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ type FailoverOptions struct {
5454
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
5555
OnConnect func(ctx context.Context, cn *Conn) error
5656

57-
Protocol int
58-
Username string
59-
Password string
60-
DB int
57+
Protocol int
58+
Username string
59+
Password string
60+
CredentialsProvider func() (username string, password string)
61+
DB int
6162

6263
MaxRetries int
6364
MinRetryBackoff time.Duration
@@ -92,10 +93,11 @@ func (opt *FailoverOptions) clientOptions() *Options {
9293
Dialer: opt.Dialer,
9394
OnConnect: opt.OnConnect,
9495

95-
DB: opt.DB,
96-
Protocol: opt.Protocol,
97-
Username: opt.Username,
98-
Password: opt.Password,
96+
DB: opt.DB,
97+
Protocol: opt.Protocol,
98+
Username: opt.Username,
99+
Password: opt.Password,
100+
CredentialsProvider: opt.CredentialsProvider,
99101

100102
MaxRetries: opt.MaxRetries,
101103
MinRetryBackoff: opt.MinRetryBackoff,
@@ -166,9 +168,10 @@ func (opt *FailoverOptions) clusterOptions() *ClusterOptions {
166168
Dialer: opt.Dialer,
167169
OnConnect: opt.OnConnect,
168170

169-
Protocol: opt.Protocol,
170-
Username: opt.Username,
171-
Password: opt.Password,
171+
Protocol: opt.Protocol,
172+
Username: opt.Username,
173+
Password: opt.Password,
174+
CredentialsProvider: opt.CredentialsProvider,
172175

173176
MaxRedirects: opt.MaxRetries,
174177

universal.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ type UniversalOptions struct {
2626
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
2727
OnConnect func(ctx context.Context, cn *Conn) error
2828

29-
Protocol int
30-
Username string
31-
Password string
29+
Protocol int
30+
Username string
31+
Password string
32+
CredentialsProvider func() (username string, password string)
33+
3234
SentinelUsername string
3335
SentinelPassword string
3436

@@ -82,9 +84,10 @@ func (o *UniversalOptions) Cluster() *ClusterOptions {
8284
Dialer: o.Dialer,
8385
OnConnect: o.OnConnect,
8486

85-
Protocol: o.Protocol,
86-
Username: o.Username,
87-
Password: o.Password,
87+
Protocol: o.Protocol,
88+
Username: o.Username,
89+
Password: o.Password,
90+
CredentialsProvider: o.CredentialsProvider,
8891

8992
MaxRedirects: o.MaxRedirects,
9093
ReadOnly: o.ReadOnly,
@@ -131,10 +134,12 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
131134
Dialer: o.Dialer,
132135
OnConnect: o.OnConnect,
133136

134-
DB: o.DB,
135-
Protocol: o.Protocol,
136-
Username: o.Username,
137-
Password: o.Password,
137+
DB: o.DB,
138+
Protocol: o.Protocol,
139+
Username: o.Username,
140+
Password: o.Password,
141+
CredentialsProvider: o.CredentialsProvider,
142+
138143
SentinelUsername: o.SentinelUsername,
139144
SentinelPassword: o.SentinelPassword,
140145

@@ -176,10 +181,11 @@ func (o *UniversalOptions) Simple() *Options {
176181
Dialer: o.Dialer,
177182
OnConnect: o.OnConnect,
178183

179-
DB: o.DB,
180-
Protocol: o.Protocol,
181-
Username: o.Username,
182-
Password: o.Password,
184+
DB: o.DB,
185+
Protocol: o.Protocol,
186+
Username: o.Username,
187+
Password: o.Password,
188+
CredentialsProvider: o.CredentialsProvider,
183189

184190
MaxRetries: o.MaxRetries,
185191
MinRetryBackoff: o.MinRetryBackoff,

0 commit comments

Comments
 (0)