diff --git a/auth/auth.go b/auth/auth.go index d5834fc5..7cb1d1fd 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -1,20 +1,36 @@ package auth +// StreamingCredentialsProvider is an interface that defines the methods for a streaming credentials provider. +// It is used to provide credentials for authentication. +// The CredentialsListener is used to receive updates when the credentials change. 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 subscribes to the credentials provider for updates. + // It returns the current credentials, a cancel function to unsubscribe from the provider, + // and an error if any. Subscribe(listener CredentialsListener) (Credentials, CancelProviderFunc, error) } +// CancelProviderFunc is a function that is used to cancel the subscription to the credentials provider. +// It is used to unsubscribe from the provider when the credentials are no longer needed. type CancelProviderFunc func() error +// CredentialsListener is an interface that defines the methods for a credentials listener. +// It is used to receive updates when the credentials change. +// The OnNext method is called when the credentials change. +// The OnError method is called when an error occurs while requesting the credentials. type CredentialsListener interface { OnNext(credentials Credentials) OnError(err error) } +// Credentials is an interface that defines the methods for credentials. +// It is used to provide the credentials for authentication. type Credentials interface { + // BasicAuth returns the username and password for basic authentication. BasicAuth() (username string, password string) + // RawCredentials returns the raw credentials as a string. + // This can be used to extract the username and password from the raw credentials or + // additional information if present in the token. RawCredentials() string } @@ -23,15 +39,18 @@ type basicAuth struct { password string } +// RawCredentials returns the raw credentials as a string. func (b *basicAuth) RawCredentials() string { return b.username + ":" + b.password } +// BasicAuth returns the username and password for basic authentication. func (b *basicAuth) BasicAuth() (username string, password string) { return b.username, b.password } -func NewCredentials(username, password string) Credentials { +// NewBasicCredentials creates a new Credentials object from the given username and password. +func NewBasicCredentials(username, password string) Credentials { return &basicAuth{ username: username, password: password, diff --git a/redis.go b/redis.go index c2a18051..2026ff9d 100644 --- a/redis.go +++ b/redis.go @@ -336,7 +336,7 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error { } if !authenticated && password != "" { - err = c.reAuth(ctx, conn, auth.NewCredentials(username, password)) + err = c.reAuth(ctx, conn, auth.NewBasicCredentials(username, password)) if err != nil { return err }