1
0
mirror of https://github.com/redis/go-redis.git synced 2025-04-17 20:17:02 +03:00
go-redis/auth/auth.go
Nedyalko Dyakov 5410adb9dc
wip
2025-03-18 11:07:14 +02:00

40 lines
941 B
Go

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,
}
}