2019-11-28 20:56:04 +00:00
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
2022-09-12 15:40:09 +00:00
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/kvtools/redis"
|
2020-09-16 13:46:04 +00:00
|
|
|
"github.com/traefik/traefik/v2/pkg/provider"
|
|
|
|
"github.com/traefik/traefik/v2/pkg/provider/kv"
|
2022-09-12 15:40:09 +00:00
|
|
|
"github.com/traefik/traefik/v2/pkg/types"
|
2019-11-28 20:56:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ provider.Provider = (*Provider)(nil)
|
|
|
|
|
|
|
|
// Provider holds configurations of the provider.
|
|
|
|
type Provider struct {
|
2022-09-12 15:40:09 +00:00
|
|
|
kv.Provider `yaml:",inline" export:"true"`
|
|
|
|
|
|
|
|
TLS *types.ClientTLS `description:"Enable TLS support." json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" export:"true"`
|
|
|
|
Username string `description:"Username for authentication." json:"username,omitempty" toml:"username,omitempty" yaml:"username,omitempty" loggable:"false"`
|
|
|
|
Password string `description:"Password for authentication." json:"password,omitempty" toml:"password,omitempty" yaml:"password,omitempty" loggable:"false"`
|
|
|
|
DB int `description:"Database to be selected after connecting to the server." json:"db,omitempty" toml:"db,omitempty" yaml:"db,omitempty"`
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetDefaults sets the default values.
|
|
|
|
func (p *Provider) SetDefaults() {
|
|
|
|
p.Provider.SetDefaults()
|
|
|
|
p.Endpoints = []string{"127.0.0.1:6379"}
|
|
|
|
}
|
|
|
|
|
2020-05-11 10:06:07 +00:00
|
|
|
// Init the provider.
|
2019-11-28 20:56:04 +00:00
|
|
|
func (p *Provider) Init() error {
|
2022-09-12 15:40:09 +00:00
|
|
|
config := redis.Config{
|
|
|
|
Username: p.Username,
|
|
|
|
Password: p.Password,
|
|
|
|
DB: p.DB,
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.TLS != nil {
|
|
|
|
var err error
|
|
|
|
config.TLS, err = p.TLS.CreateTLSConfig(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("unable to create client TLS configuration: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.Provider.Init(redis.StoreName, "redis", config)
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|