chore: move the parser to a dedicated package.
This commit is contained in:
parent
eecc2f4dd7
commit
1502d20def
90 changed files with 191 additions and 14278 deletions
|
@ -10,13 +10,14 @@ import (
|
|||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/containous/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/v2/pkg/config/file"
|
||||
"github.com/containous/traefik/v2/pkg/job"
|
||||
"github.com/containous/traefik/v2/pkg/log"
|
||||
"github.com/containous/traefik/v2/pkg/provider"
|
||||
"github.com/containous/traefik/v2/pkg/safe"
|
||||
"github.com/containous/traefik/v2/pkg/tls"
|
||||
"github.com/containous/traefik/v2/pkg/types"
|
||||
"github.com/traefik/paerser/file"
|
||||
ptypes "github.com/traefik/paerser/types"
|
||||
)
|
||||
|
||||
var _ provider.Provider = (*Provider)(nil)
|
||||
|
@ -24,8 +25,8 @@ var _ provider.Provider = (*Provider)(nil)
|
|||
// Provider is a provider.Provider implementation that queries an HTTP(s) endpoint for a configuration.
|
||||
type Provider struct {
|
||||
Endpoint string `description:"Load configuration from this endpoint." json:"endpoint" toml:"endpoint" yaml:"endpoint" export:"true"`
|
||||
PollInterval types.Duration `description:"Polling interval for endpoint." json:"pollInterval,omitempty" toml:"pollInterval,omitempty" yaml:"pollInterval,omitempty"`
|
||||
PollTimeout types.Duration `description:"Polling timeout for endpoint." json:"pollTimeout,omitempty" toml:"pollTimeout,omitempty" yaml:"pollTimeout,omitempty"`
|
||||
PollInterval ptypes.Duration `description:"Polling interval for endpoint." json:"pollInterval,omitempty" toml:"pollInterval,omitempty" yaml:"pollInterval,omitempty"`
|
||||
PollTimeout ptypes.Duration `description:"Polling timeout for endpoint." json:"pollTimeout,omitempty" toml:"pollTimeout,omitempty" yaml:"pollTimeout,omitempty"`
|
||||
TLS *types.ClientTLS `description:"Enable TLS support." json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" export:"true"`
|
||||
httpClient *http.Client
|
||||
lastConfigurationHash uint64
|
||||
|
@ -33,8 +34,8 @@ type Provider struct {
|
|||
|
||||
// SetDefaults sets the default values.
|
||||
func (p *Provider) SetDefaults() {
|
||||
p.PollInterval = types.Duration(5 * time.Second)
|
||||
p.PollTimeout = types.Duration(5 * time.Second)
|
||||
p.PollInterval = ptypes.Duration(5 * time.Second)
|
||||
p.PollTimeout = ptypes.Duration(5 * time.Second)
|
||||
}
|
||||
|
||||
// Init the provider.
|
||||
|
|
|
@ -11,16 +11,16 @@ import (
|
|||
"github.com/containous/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/v2/pkg/safe"
|
||||
"github.com/containous/traefik/v2/pkg/tls"
|
||||
"github.com/containous/traefik/v2/pkg/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
ptypes "github.com/traefik/paerser/types"
|
||||
)
|
||||
|
||||
func TestProvider_Init(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
endpoint string
|
||||
pollInterval types.Duration
|
||||
pollInterval ptypes.Duration
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ func TestProvider_Init(t *testing.T) {
|
|||
{
|
||||
desc: "should not return an error",
|
||||
endpoint: "http://localhost:8080",
|
||||
pollInterval: types.Duration(time.Second),
|
||||
pollInterval: ptypes.Duration(time.Second),
|
||||
expErr: false,
|
||||
},
|
||||
}
|
||||
|
@ -63,8 +63,8 @@ func TestProvider_SetDefaults(t *testing.T) {
|
|||
|
||||
provider.SetDefaults()
|
||||
|
||||
assert.Equal(t, provider.PollInterval, types.Duration(5*time.Second))
|
||||
assert.Equal(t, provider.PollTimeout, types.Duration(5*time.Second))
|
||||
assert.Equal(t, provider.PollInterval, ptypes.Duration(5*time.Second))
|
||||
assert.Equal(t, provider.PollTimeout, ptypes.Duration(5*time.Second))
|
||||
}
|
||||
|
||||
func TestProvider_fetchConfigurationData(t *testing.T) {
|
||||
|
@ -98,8 +98,8 @@ func TestProvider_fetchConfigurationData(t *testing.T) {
|
|||
|
||||
provider := Provider{
|
||||
Endpoint: server.URL,
|
||||
PollInterval: types.Duration(1 * time.Second),
|
||||
PollTimeout: types.Duration(1 * time.Second),
|
||||
PollInterval: ptypes.Duration(1 * time.Second),
|
||||
PollTimeout: ptypes.Duration(1 * time.Second),
|
||||
}
|
||||
|
||||
err := provider.Init()
|
||||
|
@ -181,8 +181,8 @@ func TestProvider_Provide(t *testing.T) {
|
|||
|
||||
provider := Provider{
|
||||
Endpoint: server.URL,
|
||||
PollTimeout: types.Duration(1 * time.Second),
|
||||
PollInterval: types.Duration(100 * time.Millisecond),
|
||||
PollTimeout: ptypes.Duration(1 * time.Second),
|
||||
PollInterval: ptypes.Duration(100 * time.Millisecond),
|
||||
}
|
||||
|
||||
err := provider.Init()
|
||||
|
@ -235,8 +235,8 @@ func TestProvider_ProvideConfigurationOnlyOnceIfUnchanged(t *testing.T) {
|
|||
|
||||
provider := Provider{
|
||||
Endpoint: server.URL + "/endpoint",
|
||||
PollTimeout: types.Duration(1 * time.Second),
|
||||
PollInterval: types.Duration(100 * time.Millisecond),
|
||||
PollTimeout: ptypes.Duration(1 * time.Second),
|
||||
PollInterval: ptypes.Duration(100 * time.Millisecond),
|
||||
}
|
||||
|
||||
err := provider.Init()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue