Move dynamic config into a dedicated package.
This commit is contained in:
parent
09cc1161c9
commit
c8bf8e896a
102 changed files with 3170 additions and 3166 deletions
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
)
|
||||
|
||||
|
@ -13,7 +13,7 @@ const (
|
|||
)
|
||||
|
||||
// NewRedirectRegex creates a redirect middleware.
|
||||
func NewRedirectRegex(ctx context.Context, next http.Handler, conf config.RedirectRegex, name string) (http.Handler, error) {
|
||||
func NewRedirectRegex(ctx context.Context, next http.Handler, conf dynamic.RedirectRegex, name string) (http.Handler, error) {
|
||||
logger := middlewares.GetLogger(ctx, name, typeRegexName)
|
||||
logger.Debug("Creating middleware")
|
||||
logger.Debugf("Setting up redirection from %s to %s", conf.Regex, conf.Replacement)
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/testhelpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -16,7 +16,7 @@ import (
|
|||
func TestRedirectRegexHandler(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
config config.RedirectRegex
|
||||
config dynamic.RedirectRegex
|
||||
method string
|
||||
url string
|
||||
secured bool
|
||||
|
@ -26,7 +26,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
desc: "simple redirection",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
|
||||
Replacement: "https://${1}bar$2:443$4",
|
||||
},
|
||||
|
@ -36,7 +36,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "use request header",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
|
||||
Replacement: `https://${1}{{ .Request.Header.Get "X-Foo" }}$2:443$4`,
|
||||
},
|
||||
|
@ -46,7 +46,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "URL doesn't match regex",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
|
||||
Replacement: "https://${1}bar$2:443$4",
|
||||
},
|
||||
|
@ -55,7 +55,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "invalid rewritten URL",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^(.*)$`,
|
||||
Replacement: "http://192.168.0.%31/",
|
||||
},
|
||||
|
@ -64,7 +64,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "invalid regex",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^(.*`,
|
||||
Replacement: "$1",
|
||||
},
|
||||
|
@ -73,7 +73,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTPS permanent",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^http://`,
|
||||
Replacement: "https://$1",
|
||||
Permanent: true,
|
||||
|
@ -84,7 +84,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTPS to HTTP permanent",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `https://foo`,
|
||||
Replacement: "http://foo",
|
||||
Permanent: true,
|
||||
|
@ -96,7 +96,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTPS",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `http://foo:80`,
|
||||
Replacement: "https://foo:443",
|
||||
},
|
||||
|
@ -106,7 +106,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTPS to HTTP",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `https://foo:443`,
|
||||
Replacement: "http://foo:80",
|
||||
},
|
||||
|
@ -117,7 +117,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTP",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `http://foo:80`,
|
||||
Replacement: "http://foo:88",
|
||||
},
|
||||
|
@ -127,7 +127,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTP POST",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^http://`,
|
||||
Replacement: "https://$1",
|
||||
},
|
||||
|
@ -138,7 +138,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTP POST permanent",
|
||||
config: config.RedirectRegex{
|
||||
config: dynamic.RedirectRegex{
|
||||
Regex: `^http://`,
|
||||
Replacement: "https://$1",
|
||||
Permanent: true,
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares"
|
||||
)
|
||||
|
||||
|
@ -15,7 +15,7 @@ const (
|
|||
)
|
||||
|
||||
// NewRedirectScheme creates a new RedirectScheme middleware.
|
||||
func NewRedirectScheme(ctx context.Context, next http.Handler, conf config.RedirectScheme, name string) (http.Handler, error) {
|
||||
func NewRedirectScheme(ctx context.Context, next http.Handler, conf dynamic.RedirectScheme, name string) (http.Handler, error) {
|
||||
logger := middlewares.GetLogger(ctx, name, typeSchemeName)
|
||||
logger.Debug("Creating middleware")
|
||||
logger.Debugf("Setting up redirection to %s %s", conf.Scheme, conf.Port)
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -16,7 +16,7 @@ import (
|
|||
func TestRedirectSchemeHandler(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
config config.RedirectScheme
|
||||
config dynamic.RedirectScheme
|
||||
method string
|
||||
url string
|
||||
secured bool
|
||||
|
@ -26,13 +26,13 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
desc: "Without scheme",
|
||||
config: config.RedirectScheme{},
|
||||
config: dynamic.RedirectScheme{},
|
||||
url: "http://foo",
|
||||
errorExpected: true,
|
||||
},
|
||||
{
|
||||
desc: "HTTP to HTTPS",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
},
|
||||
url: "http://foo",
|
||||
|
@ -41,7 +41,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP with port to HTTPS without port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
},
|
||||
url: "http://foo:8080",
|
||||
|
@ -50,7 +50,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP without port to HTTPS with port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
Port: "8443",
|
||||
},
|
||||
|
@ -60,7 +60,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP with port to HTTPS with port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
Port: "8443",
|
||||
},
|
||||
|
@ -70,7 +70,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTPS with port to HTTPS with port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
Port: "8443",
|
||||
},
|
||||
|
@ -80,7 +80,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTPS with port to HTTPS without port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
},
|
||||
url: "https://foo:8000",
|
||||
|
@ -89,7 +89,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "redirection to HTTPS without port from an URL already in https",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
},
|
||||
url: "https://foo:8000/theother",
|
||||
|
@ -98,7 +98,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTPS permanent",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
Port: "8443",
|
||||
Permanent: true,
|
||||
|
@ -109,7 +109,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "to HTTP 80",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "http",
|
||||
Port: "80",
|
||||
},
|
||||
|
@ -119,7 +119,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to wss",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "wss",
|
||||
Port: "9443",
|
||||
},
|
||||
|
@ -129,7 +129,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to wss without port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "wss",
|
||||
},
|
||||
url: "http://foo",
|
||||
|
@ -138,7 +138,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP with port to wss without port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "wss",
|
||||
},
|
||||
url: "http://foo:5678",
|
||||
|
@ -147,7 +147,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP to HTTPS without port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
},
|
||||
url: "http://foo:443",
|
||||
|
@ -156,7 +156,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTP port redirection",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "http",
|
||||
Port: "8181",
|
||||
},
|
||||
|
@ -166,7 +166,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "HTTPS with port 80 to HTTPS without port",
|
||||
config: config.RedirectScheme{
|
||||
config: dynamic.RedirectScheme{
|
||||
Scheme: "https",
|
||||
},
|
||||
url: "https://foo:80",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue