fix: validation system
This commit is contained in:
parent
d6c9f51082
commit
da20db862d
18 changed files with 235 additions and 324 deletions
|
@ -1,8 +1,6 @@
|
|||
[run]
|
||||
deadline = "10m"
|
||||
skip-files = [
|
||||
"^old/.*",
|
||||
]
|
||||
skip-files = []
|
||||
|
||||
[linters-settings]
|
||||
|
||||
|
@ -52,12 +50,6 @@
|
|||
[[issues.exclude-rules]]
|
||||
path = ".+_test.go"
|
||||
linters = ["goconst"]
|
||||
[[issues.exclude-rules]]
|
||||
path = "provider/label/internal/.+_test.go"
|
||||
text = "U1000: field `(foo|fuu)` is unused"
|
||||
[[issues.exclude-rules]]
|
||||
path = "middlewares/recovery/recovery.go"
|
||||
text = "`logger` can be `github.com/containous/traefik/vendor/github.com/stretchr/testify/assert.TestingT`"
|
||||
[[issues.exclude-rules]]
|
||||
path = "integration/.+_test.go"
|
||||
text = "Error return value of `cmd\\.Process\\.Kill` is not checked"
|
||||
|
@ -68,23 +60,26 @@
|
|||
path = "integration/grpc_test.go"
|
||||
text = "Error return value of `closer` is not checked"
|
||||
[[issues.exclude-rules]]
|
||||
path = "provider/kubernetes/builder_(endpoint|service)_test.go"
|
||||
path = "pkg/h2c/h2c.go"
|
||||
text = "Error return value of `rw.Write` is not checked"
|
||||
[[issues.exclude-rules]]
|
||||
path = "pkg/middlewares/recovery/recovery.go"
|
||||
text = "`logger` can be `github.com/containous/traefik/vendor/github.com/stretchr/testify/assert.TestingT`"
|
||||
[[issues.exclude-rules]]
|
||||
path = "pkg/provider/docker/builder_test.go"
|
||||
text = "(U1000: func )?`(.+)` is unused"
|
||||
[[issues.exclude-rules]]
|
||||
path = "provider/docker/builder_test.go"
|
||||
path = "pkg/provider/kubernetes/builder_(endpoint|service)_test.go"
|
||||
text = "(U1000: func )?`(.+)` is unused"
|
||||
[[issues.exclude-rules]]
|
||||
path = "pkg/provider/label/internal/.+_test.go"
|
||||
text = "U1000: field `(foo|fuu)` is unused"
|
||||
[[issues.exclude-rules]]
|
||||
path = "pkg/server/service/bufferpool.go"
|
||||
text = "SA6002: argument should be pointer-like to avoid allocations"
|
||||
[[issues.exclude-rules]]
|
||||
path = "cmd/configuration.go"
|
||||
text = "string `traefik` has (\\d) occurrences, make it a constant"
|
||||
[[issues.exclude-rules]]
|
||||
path = "h2c/h2c.go"
|
||||
text = "Error return value of `rw.Write` is not checked"
|
||||
[[issues.exclude-rules]]
|
||||
path = "server/service/bufferpool.go"
|
||||
text = "SA6002: argument should be pointer-like to avoid allocations"
|
||||
[[issues.exclude-rules]] # FIXME must be fixed
|
||||
path = "acme/.+.go"
|
||||
text = "(assignment copies lock value to domainsCerts|literal copies lock value from)"
|
||||
[[issues.exclude-rules]] # FIXME must be fixed
|
||||
path = "cmd/context.go"
|
||||
text = "S1000: should use a simple channel send/receive instead of `select` with a single case"
|
||||
|
|
|
@ -171,7 +171,7 @@
|
|||
- **[acme]** Updates lego. ([#4376](https://github.com/containous/traefik/pull/4376) by [ldez](https://github.com/ldez))
|
||||
- **[docker]** Fixes docker swarm mode refresh second for KV. ([#4420](https://github.com/containous/traefik/pull/4420) by [ldez](https://github.com/ldez))
|
||||
- **[ecs]** Generic awsvpc support, not just Fargate ([#4360](https://github.com/containous/traefik/pull/4360) by [maartenvanderhoef](https://github.com/maartenvanderhoef))
|
||||
- **[ecs]** Cache exising task definitions to avoid rate limiting ([#4177](https://github.com/containous/traefik/pull/4177) by [hwhelan-CB](https://github.com/hwhelan-CB))
|
||||
- **[ecs]** Cache existing task definitions to avoid rate limiting ([#4177](https://github.com/containous/traefik/pull/4177) by [hwhelan-CB](https://github.com/hwhelan-CB))
|
||||
- **[tls]** Check for dynamic tls updates on configuration preload ([#4022](https://github.com/containous/traefik/pull/4022) by [ffilippopoulos](https://github.com/ffilippopoulos))
|
||||
- **[tracing]** Support Datadog tracer priority sampling ([#4359](https://github.com/containous/traefik/pull/4359) by [jcassee](https://github.com/jcassee))
|
||||
- Update to Go 1.11.5 [CVE-2019-6486](https://nvd.nist.gov/vuln/detail/CVE-2019-6486)
|
||||
|
@ -296,7 +296,7 @@
|
|||
**Bug fixes:**
|
||||
- **[acme]** DNS challenge Cloudflare auth zone ([#4042](https://github.com/containous/traefik/pull/4042) by [ldez](https://github.com/ldez))
|
||||
- **[acme]** ACME DNS challenges ([#3998](https://github.com/containous/traefik/pull/3998) by [ldez](https://github.com/ldez))
|
||||
- **[acme]** Don't initalize ACME provider if storage is empty ([#3988](https://github.com/containous/traefik/pull/3988) by [nmengin](https://github.com/nmengin))
|
||||
- **[acme]** Don't initialize ACME provider if storage is empty ([#3988](https://github.com/containous/traefik/pull/3988) by [nmengin](https://github.com/nmengin))
|
||||
- **[acme]** Fix: acme DNS providers ([#4021](https://github.com/containous/traefik/pull/4021) by [ldez](https://github.com/ldez))
|
||||
- **[acme]** Prevent some malformed errors in LE. ([#4015](https://github.com/containous/traefik/pull/4015) by [ldez](https://github.com/ldez))
|
||||
- **[authentication,consulcatalog,docker,ecs,etcd,kv,marathon,mesos,rancher]** Add the AuthResponseHeaders to the labels ([#3973](https://github.com/containous/traefik/pull/3973) by [Crypto89](https://github.com/Crypto89))
|
||||
|
@ -371,7 +371,7 @@
|
|||
- **[healthcheck]** Support all 2xx HTTP status code for health check. ([#3362](https://github.com/containous/traefik/pull/3362) by [ldez](https://github.com/ldez))
|
||||
- **[healthcheck]** Add HTTP headers to healthcheck. ([#3047](https://github.com/containous/traefik/pull/3047) by [zetaab](https://github.com/zetaab))
|
||||
- **[k8s]** Add more k8s tests ([#3491](https://github.com/containous/traefik/pull/3491) by [dtomcej](https://github.com/dtomcej))
|
||||
- **[k8s]** Substitude hardcoded "<namespace>/<name>" with k8s ListerGetter ([#3470](https://github.com/containous/traefik/pull/3470) by [yue9944882](https://github.com/yue9944882))
|
||||
- **[k8s]** Substitute hardcoded "<namespace>/<name>" with k8s ListerGetter ([#3470](https://github.com/containous/traefik/pull/3470) by [yue9944882](https://github.com/yue9944882))
|
||||
- **[k8s]** Custom frontend name for test helper ([#3444](https://github.com/containous/traefik/pull/3444) by [ldez](https://github.com/ldez))
|
||||
- **[k8s]** Add annotation to allow modifiers to be used properly in kubernetes ([#3481](https://github.com/containous/traefik/pull/3481) by [dtomcej](https://github.com/dtomcej))
|
||||
- **[k8s]** Create Global Backend Ingress ([#3404](https://github.com/containous/traefik/pull/3404) by [dtomcej](https://github.com/dtomcej))
|
||||
|
@ -668,7 +668,7 @@
|
|||
- **[healthcheck]** Support all 2xx HTTP status code for health check. ([#3362](https://github.com/containous/traefik/pull/3362) by [ldez](https://github.com/ldez))
|
||||
- **[healthcheck]** Add HTTP headers to healthcheck. ([#3047](https://github.com/containous/traefik/pull/3047) by [zetaab](https://github.com/zetaab))
|
||||
- **[k8s]** Add more k8s tests ([#3491](https://github.com/containous/traefik/pull/3491) by [dtomcej](https://github.com/dtomcej))
|
||||
- **[k8s]** Substitude hardcoded "<namespace>/<name>" with k8s ListerGetter ([#3470](https://github.com/containous/traefik/pull/3470) by [yue9944882](https://github.com/yue9944882))
|
||||
- **[k8s]** Substitute hardcoded "<namespace>/<name>" with k8s ListerGetter ([#3470](https://github.com/containous/traefik/pull/3470) by [yue9944882](https://github.com/yue9944882))
|
||||
- **[k8s]** Custom frontend name for test helper ([#3444](https://github.com/containous/traefik/pull/3444) by [ldez](https://github.com/ldez))
|
||||
- **[k8s]** Add annotation to allow modifiers to be used properly in kubernetes ([#3481](https://github.com/containous/traefik/pull/3481) by [dtomcej](https://github.com/dtomcej))
|
||||
- **[k8s]** Create Global Backend Ingress ([#3404](https://github.com/containous/traefik/pull/3404) by [dtomcej](https://github.com/dtomcej))
|
||||
|
|
1
Gopkg.lock
generated
1
Gopkg.lock
generated
|
@ -2222,7 +2222,6 @@
|
|||
"github.com/opentracing/opentracing-go/log",
|
||||
"github.com/openzipkin/zipkin-go-opentracing",
|
||||
"github.com/patrickmn/go-cache",
|
||||
"github.com/pkg/errors",
|
||||
"github.com/prometheus/client_golang/prometheus",
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp",
|
||||
"github.com/prometheus/client_model/go",
|
||||
|
|
46
Gopkg.toml
46
Gopkg.toml
|
@ -36,17 +36,17 @@ required = [
|
|||
non-go = false
|
||||
unused-packages = false
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/ArthurHlt/go-eureka-client"
|
||||
#[[constraint]]
|
||||
# branch = "master"
|
||||
# name = "github.com/ArthurHlt/go-eureka-client"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/BurntSushi/toml"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/BurntSushi/ty"
|
||||
#[[constraint]]
|
||||
# branch = "master"
|
||||
# name = "github.com/BurntSushi/ty"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
|
@ -61,9 +61,9 @@ required = [
|
|||
branch = "master"
|
||||
name = "github.com/armon/go-proxyproto"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/aws/aws-sdk-go"
|
||||
version = "1.13.11"
|
||||
#[[constraint]]
|
||||
# name = "github.com/aws/aws-sdk-go"
|
||||
# version = "1.13.11"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/cenkalti/backoff"
|
||||
|
@ -94,10 +94,10 @@ required = [
|
|||
name = "github.com/coreos/go-systemd"
|
||||
version = "14.0.0"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/docker/leadership"
|
||||
source = "github.com/containous/leadership"
|
||||
#[[constraint]]
|
||||
# branch = "master"
|
||||
# name = "github.com/docker/leadership"
|
||||
# source = "github.com/containous/leadership"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/eapache/channels"
|
||||
|
@ -125,9 +125,9 @@ required = [
|
|||
branch = "master"
|
||||
name = "github.com/gorilla/websocket"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/hashicorp/consul"
|
||||
version = "1.0.6"
|
||||
#[[constraint]]
|
||||
# name = "github.com/hashicorp/consul"
|
||||
# version = "1.0.6"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/influxdata/influxdb"
|
||||
|
@ -141,18 +141,18 @@ required = [
|
|||
branch = "master"
|
||||
name = "github.com/abronan/valkeyrie"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/mesosphere/mesos-dns"
|
||||
source = "https://github.com/containous/mesos-dns.git"
|
||||
#[[constraint]]
|
||||
# name = "github.com/mesosphere/mesos-dns"
|
||||
# source = "https://github.com/containous/mesos-dns.git"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/opentracing/opentracing-go"
|
||||
version = "1.0.2"
|
||||
|
||||
[[constraint]]
|
||||
branch = "containous-fork"
|
||||
name = "github.com/rancher/go-rancher-metadata"
|
||||
source = "github.com/containous/go-rancher-metadata"
|
||||
#[[constraint]]
|
||||
# branch = "containous-fork"
|
||||
# name = "github.com/rancher/go-rancher-metadata"
|
||||
# source = "github.com/containous/go-rancher-metadata"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
|
|
6
Makefile
6
Makefile
|
@ -93,7 +93,11 @@ test-integration: $(PRE_TARGET)
|
|||
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK),TEST_CONTAINER=1) ./script/make.sh generate binary test-integration
|
||||
TEST_HOST=1 ./script/make.sh test-integration
|
||||
|
||||
## Validate code, vendor
|
||||
## Validate code and docs
|
||||
validate-files: $(PRE_TARGET)
|
||||
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK)) ./script/make.sh generate validate-lint validate-misspell
|
||||
|
||||
## Validate code, docs, and vendor
|
||||
validate: $(PRE_TARGET)
|
||||
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK)) ./script/make.sh generate validate-lint validate-misspell validate-vendor
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package ipwhitelist
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
|
@ -10,7 +11,6 @@ import (
|
|||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/containous/traefik/pkg/tracing"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
|
|
@ -2,12 +2,11 @@ package redirect
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
fmtlog "log"
|
||||
|
@ -29,7 +30,6 @@ import (
|
|||
legolog "github.com/go-acme/lego/log"
|
||||
"github.com/go-acme/lego/providers/dns"
|
||||
"github.com/go-acme/lego/registration"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package file
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -18,7 +19,6 @@ import (
|
|||
"github.com/containous/traefik/pkg/provider"
|
||||
"github.com/containous/traefik/pkg/safe"
|
||||
"github.com/containous/traefik/pkg/tls"
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/fsnotify.v1"
|
||||
)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package crd
|
|||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -20,7 +21,6 @@ import (
|
|||
"github.com/containous/traefik/pkg/provider/kubernetes/k8s"
|
||||
"github.com/containous/traefik/pkg/safe"
|
||||
"github.com/containous/traefik/pkg/tls"
|
||||
"github.com/pkg/errors"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
)
|
||||
|
|
|
@ -2,6 +2,7 @@ package ingress
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"math"
|
||||
|
@ -19,7 +20,6 @@ import (
|
|||
"github.com/containous/traefik/pkg/provider/kubernetes/k8s"
|
||||
"github.com/containous/traefik/pkg/safe"
|
||||
"github.com/containous/traefik/pkg/tls"
|
||||
"github.com/pkg/errors"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/api/extensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package rules
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/vulcand/predicate"
|
||||
)
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package middleware
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -28,7 +29,6 @@ import (
|
|||
"github.com/containous/traefik/pkg/middlewares/stripprefixregex"
|
||||
"github.com/containous/traefik/pkg/middlewares/tracing"
|
||||
"github.com/containous/traefik/pkg/server/internal"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type middlewareStackType int
|
||||
|
@ -65,7 +65,7 @@ func (b *Builder) BuildChain(ctx context.Context, middlewares []string) *alice.C
|
|||
}
|
||||
|
||||
var err error
|
||||
if constructorContext, err = checkRecursivity(constructorContext, middlewareName); err != nil {
|
||||
if constructorContext, err = checkRecursion(constructorContext, middlewareName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ func (b *Builder) BuildChain(ctx context.Context, middlewares []string) *alice.C
|
|||
return &chain
|
||||
}
|
||||
|
||||
func checkRecursivity(ctx context.Context, middlewareName string) (context.Context, error) {
|
||||
func checkRecursion(ctx context.Context, middlewareName string) (context.Context, error) {
|
||||
currentStack, ok := ctx.Value(middlewareStackKey).([]string)
|
||||
if !ok {
|
||||
currentStack = []string{}
|
||||
|
@ -92,242 +92,218 @@ func checkRecursivity(ctx context.Context, middlewareName string) (context.Conte
|
|||
|
||||
func (b *Builder) buildConstructor(ctx context.Context, middlewareName string, config config.Middleware) (alice.Constructor, error) {
|
||||
var middleware alice.Constructor
|
||||
badConf := errors.New("cannot create middleware %q: multi-types middleware not supported, consider declaring two different pieces of middleware instead")
|
||||
badConf := errors.New("cannot create middleware: multi-types middleware not supported, consider declaring two different pieces of middleware instead")
|
||||
|
||||
// AddPrefix
|
||||
if config.AddPrefix != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return addprefix.New(ctx, next, *config.AddPrefix, middlewareName)
|
||||
}
|
||||
} else {
|
||||
return nil, badConf
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return addprefix.New(ctx, next, *config.AddPrefix, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// BasicAuth
|
||||
if config.BasicAuth != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return auth.NewBasic(ctx, next, *config.BasicAuth, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return auth.NewBasic(ctx, next, *config.BasicAuth, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// Buffering
|
||||
if config.Buffering != nil && config.MaxConn.Amount != 0 {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return buffering.New(ctx, next, *config.Buffering, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return buffering.New(ctx, next, *config.Buffering, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// Chain
|
||||
if config.Chain != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return chain.New(ctx, next, *config.Chain, b, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return chain.New(ctx, next, *config.Chain, b, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// CircuitBreaker
|
||||
if config.CircuitBreaker != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return circuitbreaker.New(ctx, next, *config.CircuitBreaker, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return circuitbreaker.New(ctx, next, *config.CircuitBreaker, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// Compress
|
||||
if config.Compress != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return compress.New(ctx, next, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return compress.New(ctx, next, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// CustomErrors
|
||||
if config.Errors != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return customerrors.New(ctx, next, *config.Errors, b.serviceBuilder, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return customerrors.New(ctx, next, *config.Errors, b.serviceBuilder, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// DigestAuth
|
||||
if config.DigestAuth != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return auth.NewDigest(ctx, next, *config.DigestAuth, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return auth.NewDigest(ctx, next, *config.DigestAuth, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// ForwardAuth
|
||||
if config.ForwardAuth != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return auth.NewForward(ctx, next, *config.ForwardAuth, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return auth.NewForward(ctx, next, *config.ForwardAuth, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// Headers
|
||||
if config.Headers != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return headers.New(ctx, next, *config.Headers, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return headers.New(ctx, next, *config.Headers, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// IPWhiteList
|
||||
if config.IPWhiteList != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return ipwhitelist.New(ctx, next, *config.IPWhiteList, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return ipwhitelist.New(ctx, next, *config.IPWhiteList, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// MaxConn
|
||||
if config.MaxConn != nil && config.MaxConn.Amount != 0 {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return maxconnection.New(ctx, next, *config.MaxConn, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return maxconnection.New(ctx, next, *config.MaxConn, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// PassTLSClientCert
|
||||
if config.PassTLSClientCert != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return passtlsclientcert.New(ctx, next, *config.PassTLSClientCert, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return passtlsclientcert.New(ctx, next, *config.PassTLSClientCert, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// RateLimit
|
||||
if config.RateLimit != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return ratelimiter.New(ctx, next, *config.RateLimit, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return ratelimiter.New(ctx, next, *config.RateLimit, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// RedirectRegex
|
||||
if config.RedirectRegex != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return redirect.NewRedirectRegex(ctx, next, *config.RedirectRegex, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return redirect.NewRedirectRegex(ctx, next, *config.RedirectRegex, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// RedirectScheme
|
||||
if config.RedirectScheme != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return redirect.NewRedirectScheme(ctx, next, *config.RedirectScheme, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return redirect.NewRedirectScheme(ctx, next, *config.RedirectScheme, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// ReplacePath
|
||||
if config.ReplacePath != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return replacepath.New(ctx, next, *config.ReplacePath, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return replacepath.New(ctx, next, *config.ReplacePath, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// ReplacePathRegex
|
||||
if config.ReplacePathRegex != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return replacepathregex.New(ctx, next, *config.ReplacePathRegex, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return replacepathregex.New(ctx, next, *config.ReplacePathRegex, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// Retry
|
||||
if config.Retry != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
// FIXME missing metrics / accessLog
|
||||
return retry.New(ctx, next, *config.Retry, retry.Listeners{}, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
// FIXME missing metrics / accessLog
|
||||
return retry.New(ctx, next, *config.Retry, retry.Listeners{}, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// StripPrefix
|
||||
if config.StripPrefix != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return stripprefix.New(ctx, next, *config.StripPrefix, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return stripprefix.New(ctx, next, *config.StripPrefix, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
// StripPrefixRegex
|
||||
if config.StripPrefixRegex != nil {
|
||||
if middleware == nil {
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return stripprefixregex.New(ctx, next, *config.StripPrefixRegex, middlewareName)
|
||||
}
|
||||
} else {
|
||||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return stripprefixregex.New(ctx, next, *config.StripPrefixRegex, middlewareName)
|
||||
}
|
||||
}
|
||||
|
||||
if middleware == nil {
|
||||
return nil, fmt.Errorf("middleware %q does not exist", middlewareName)
|
||||
return nil, errors.New("middleware does not exist")
|
||||
}
|
||||
|
||||
return tracing.Wrap(ctx, middleware), nil
|
||||
|
|
|
@ -13,58 +13,6 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestBuilder_buildConstructorCircuitBreaker(t *testing.T) {
|
||||
testConfig := map[string]*config.Middleware{
|
||||
"empty": {
|
||||
CircuitBreaker: &config.CircuitBreaker{
|
||||
Expression: "",
|
||||
},
|
||||
},
|
||||
"foo": {
|
||||
CircuitBreaker: &config.CircuitBreaker{
|
||||
Expression: "NetworkErrorRatio() > 0.5",
|
||||
},
|
||||
},
|
||||
}
|
||||
middlewaresBuilder := NewBuilder(testConfig, nil)
|
||||
|
||||
emptyHandler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {})
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
middlewareID string
|
||||
expectedError bool
|
||||
}{
|
||||
{
|
||||
desc: "Should fail at creating a circuit breaker with an empty expression",
|
||||
expectedError: true,
|
||||
middlewareID: "empty",
|
||||
}, {
|
||||
desc: "Should create a circuit breaker with a valid expression",
|
||||
expectedError: false,
|
||||
middlewareID: "foo",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
constructor, err := middlewaresBuilder.buildConstructor(context.Background(), test.middlewareID, *testConfig[test.middlewareID])
|
||||
require.NoError(t, err)
|
||||
|
||||
middleware, err2 := constructor(emptyHandler)
|
||||
|
||||
if test.expectedError {
|
||||
require.Error(t, err2)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, middleware)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilder_BuildChainNilConfig(t *testing.T) {
|
||||
testConfig := map[string]*config.Middleware{
|
||||
"empty": {},
|
||||
|
@ -87,59 +35,7 @@ func TestBuilder_BuildChainNonExistentChain(t *testing.T) {
|
|||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestBuilder_buildConstructorAddPrefix(t *testing.T) {
|
||||
testConfig := map[string]*config.Middleware{
|
||||
"empty": {
|
||||
AddPrefix: &config.AddPrefix{
|
||||
Prefix: "",
|
||||
},
|
||||
},
|
||||
"foo": {
|
||||
AddPrefix: &config.AddPrefix{
|
||||
Prefix: "foo/",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
middlewaresBuilder := NewBuilder(testConfig, nil)
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
middlewareID string
|
||||
expectedError bool
|
||||
}{
|
||||
{
|
||||
desc: "Should not create an empty AddPrefix middleware when given an empty prefix",
|
||||
middlewareID: "empty",
|
||||
expectedError: true,
|
||||
}, {
|
||||
desc: "Should create an AddPrefix middleware when given a valid configuration",
|
||||
middlewareID: "foo",
|
||||
expectedError: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
constructor, err := middlewaresBuilder.buildConstructor(context.Background(), test.middlewareID, *testConfig[test.middlewareID])
|
||||
require.NoError(t, err)
|
||||
|
||||
middleware, err2 := constructor(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}))
|
||||
|
||||
if test.expectedError {
|
||||
require.Error(t, err2)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, middleware)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuild_BuildChainWithContext(t *testing.T) {
|
||||
func TestBuilder_BuildChainWithContext(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
buildChain []string
|
||||
|
@ -389,3 +285,76 @@ func TestBuild_BuildChainWithContext(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilder_buildConstructor(t *testing.T) {
|
||||
testConfig := map[string]*config.Middleware{
|
||||
"cb-empty": {
|
||||
CircuitBreaker: &config.CircuitBreaker{
|
||||
Expression: "",
|
||||
},
|
||||
},
|
||||
"cb-foo": {
|
||||
CircuitBreaker: &config.CircuitBreaker{
|
||||
Expression: "NetworkErrorRatio() > 0.5",
|
||||
},
|
||||
},
|
||||
"ap-empty": {
|
||||
AddPrefix: &config.AddPrefix{
|
||||
Prefix: "",
|
||||
},
|
||||
},
|
||||
"ap-foo": {
|
||||
AddPrefix: &config.AddPrefix{
|
||||
Prefix: "foo/",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
middlewaresBuilder := NewBuilder(testConfig, nil)
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
middlewareID string
|
||||
expectedError bool
|
||||
}{
|
||||
{
|
||||
desc: "Should fail at creating a circuit breaker with an empty expression",
|
||||
middlewareID: "cb-empty",
|
||||
expectedError: true,
|
||||
},
|
||||
{
|
||||
desc: "Should create a circuit breaker with a valid expression",
|
||||
middlewareID: "cb-foo",
|
||||
expectedError: false,
|
||||
},
|
||||
{
|
||||
desc: "Should not create an empty AddPrefix middleware when given an empty prefix",
|
||||
middlewareID: "ap-empty",
|
||||
expectedError: true,
|
||||
},
|
||||
{
|
||||
desc: "Should create an AddPrefix middleware when given a valid configuration",
|
||||
middlewareID: "ap-foo",
|
||||
expectedError: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
constructor, err := middlewaresBuilder.buildConstructor(context.Background(), test.middlewareID, *testConfig[test.middlewareID])
|
||||
require.NoError(t, err)
|
||||
|
||||
middleware, err2 := constructor(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {}))
|
||||
|
||||
if test.expectedError {
|
||||
require.Error(t, err2)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, middleware)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package server
|
|||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
@ -10,7 +11,6 @@ import (
|
|||
"github.com/containous/traefik/pkg/config/static"
|
||||
"github.com/containous/traefik/pkg/log"
|
||||
traefiktls "github.com/containous/traefik/pkg/tls"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/http2"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [ -z "${VALIDATE_UPSTREAM:-}" ]; then
|
||||
# this is kind of an expensive check, so let's not do this twice if we
|
||||
# are running more than one validate bundlescript
|
||||
|
||||
VALIDATE_REPO='https://github.com/containous/traefik.git'
|
||||
## FIXME wrong assumption
|
||||
VALIDATE_BRANCH='master'
|
||||
|
||||
VALIDATE_HEAD="$(git rev-parse --verify HEAD)"
|
||||
|
||||
git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH"
|
||||
VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)"
|
||||
|
||||
VALIDATE_COMMIT_LOG="$VALIDATE_UPSTREAM..$VALIDATE_HEAD"
|
||||
VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD"
|
||||
|
||||
validate_diff() {
|
||||
if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then
|
||||
git diff "$VALIDATE_COMMIT_DIFF" "$@"
|
||||
fi
|
||||
}
|
||||
fi
|
|
@ -1,9 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "$(dirname "$BASH_SOURCE")/.validate"
|
||||
|
||||
IFS=$'\n'
|
||||
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'docs/*.md') )
|
||||
files=( $( git ls-files 'docs/*.md' *.md ) )
|
||||
unset IFS
|
||||
|
||||
errors=()
|
||||
|
|
|
@ -4,31 +4,26 @@ set -o pipefail
|
|||
set -o nounset
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; export SCRIPT_DIR
|
||||
source "${SCRIPT_DIR}/.validate"
|
||||
|
||||
vendor_dir="./vendor/"
|
||||
IFS=$'\n' files=( $(validate_diff --diff-filter=ACMR --name-only -- ${vendor_dir} || true) )
|
||||
|
||||
if [[ ${#files[@]} -gt 0 ]]; then
|
||||
# We run dep install to and see if we have a diff afterwards
|
||||
echo "checking ${vendor_dir} for unintentional changes..."
|
||||
# We run dep install to and see if we have a diff afterwards
|
||||
echo "checking ${vendor_dir} for unintentional changes..."
|
||||
|
||||
dep ensure -v
|
||||
(${SCRIPT_DIR}/prune-dep.sh)
|
||||
dep ensure -v
|
||||
(${SCRIPT_DIR}/prune-dep.sh)
|
||||
|
||||
# Let see if the working directory is clean
|
||||
diffs="$(git status --porcelain -- ${vendor_dir} 2>/dev/null)"
|
||||
if [[ "$diffs" ]]; then
|
||||
{
|
||||
echo "The result of 'dep ensure' for vendor directory '${vendor_dir}' differs"
|
||||
echo
|
||||
echo "$diffs"
|
||||
echo
|
||||
echo 'Please vendor your package(s) with dep.'
|
||||
echo
|
||||
} >&2
|
||||
exit 2
|
||||
fi
|
||||
# Let see if the working directory is clean
|
||||
diffs="$(git status --porcelain -- ${vendor_dir} 2>/dev/null)"
|
||||
if [[ "$diffs" ]]; then
|
||||
{
|
||||
echo "The result of 'dep ensure' for vendor directory '${vendor_dir}' differs"
|
||||
echo
|
||||
echo "$diffs"
|
||||
echo
|
||||
echo 'Please vendor your package(s) with dep.'
|
||||
echo
|
||||
} >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
echo 'Congratulations! All vendoring changes are done the right way.'
|
||||
|
|
Loading…
Reference in a new issue