1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00
This commit is contained in:
Nedyalko Dyakov
2025-03-18 11:07:14 +02:00
parent 8fadbef84a
commit 5410adb9dc
3 changed files with 152 additions and 62 deletions

39
auth/auth.go Normal file
View File

@ -0,0 +1,39 @@
package auth
type StreamingCredentialsProvider interface {
// Subscribe subscribes to the credentials provider and returns a channel that will receive updates.
// The first response is blocking, then data will be pushed to the channel.
Subscribe(listener CredentialsListener) (Credentials, CancelProviderFunc, error)
}
type CancelProviderFunc func() error
type CredentialsListener interface {
OnNext(credentials Credentials)
OnError(err error)
}
type Credentials interface {
BasicAuth() (username string, password string)
RawCredentials() string
}
type basicAuth struct {
username string
password string
}
func (b *basicAuth) RawCredentials() string {
return b.username + ":" + b.password
}
func (b *basicAuth) BasicAuth() (username string, password string) {
return b.username, b.password
}
func NewCredentials(username, password string) Credentials {
return &basicAuth{
username: username,
password: password,
}
}