2019-11-28 20:56:04 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
2022-01-12 13:42:21 +00:00
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/kvtools/valkeyrie/store"
|
2020-09-16 13:46:04 +00:00
|
|
|
"github.com/traefik/traefik/v2/pkg/provider"
|
|
|
|
"github.com/traefik/traefik/v2/pkg/provider/kv"
|
2019-11-28 20:56:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ provider.Provider = (*Provider)(nil)
|
|
|
|
|
|
|
|
// Provider holds configurations of the provider.
|
|
|
|
type Provider struct {
|
2020-10-30 11:44:05 +00:00
|
|
|
kv.Provider `export:"true"`
|
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:8500"}
|
|
|
|
}
|
|
|
|
|
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-01-12 13:42:21 +00:00
|
|
|
// Wildcard namespace allows fetching KV values from any namespace for recursive requests (see https://www.consul.io/api/kv#ns).
|
|
|
|
// As we are not supporting multiple namespaces at the same time, wildcard namespace is not allowed.
|
|
|
|
if p.Namespace == "*" {
|
|
|
|
return errors.New("wildcard namespace is not supported")
|
|
|
|
}
|
|
|
|
|
2019-11-28 20:56:04 +00:00
|
|
|
return p.Provider.Init(store.CONSUL, "consul")
|
|
|
|
}
|