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
|
@ -3,12 +3,12 @@ package responsemodifiers
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares/headers"
|
||||
"github.com/unrolled/secure"
|
||||
)
|
||||
|
||||
func buildHeaders(hdrs *config.Headers) func(*http.Response) error {
|
||||
func buildHeaders(hdrs *dynamic.Headers) func(*http.Response) error {
|
||||
opt := secure.Options{
|
||||
BrowserXssFilter: hdrs.BrowserXSSFilter,
|
||||
ContentTypeNosniff: hdrs.ContentTypeNosniff,
|
||||
|
|
|
@ -4,17 +4,17 @@ import (
|
|||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
)
|
||||
|
||||
// NewBuilder creates a builder.
|
||||
func NewBuilder(configs map[string]*config.MiddlewareInfo) *Builder {
|
||||
func NewBuilder(configs map[string]*dynamic.MiddlewareInfo) *Builder {
|
||||
return &Builder{configs: configs}
|
||||
}
|
||||
|
||||
// Builder holds builder configuration.
|
||||
type Builder struct {
|
||||
configs map[string]*config.MiddlewareInfo
|
||||
configs map[string]*dynamic.MiddlewareInfo
|
||||
}
|
||||
|
||||
// Build Builds the response modifier.
|
||||
|
|
|
@ -6,13 +6,13 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/middlewares/headers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func stubResponse(_ map[string]*config.Middleware) *http.Response {
|
||||
func stubResponse(_ map[string]*dynamic.Middleware) *http.Response {
|
||||
return &http.Response{Header: make(http.Header)}
|
||||
}
|
||||
|
||||
|
@ -21,24 +21,24 @@ func TestBuilderBuild(t *testing.T) {
|
|||
desc string
|
||||
middlewares []string
|
||||
// buildResponse is needed because secure use a private context key
|
||||
buildResponse func(map[string]*config.Middleware) *http.Response
|
||||
conf map[string]*config.Middleware
|
||||
buildResponse func(map[string]*dynamic.Middleware) *http.Response
|
||||
conf map[string]*dynamic.Middleware
|
||||
assertResponse func(*testing.T, *http.Response)
|
||||
}{
|
||||
{
|
||||
desc: "no configuration",
|
||||
middlewares: []string{"foo", "bar"},
|
||||
buildResponse: stubResponse,
|
||||
conf: map[string]*config.Middleware{},
|
||||
conf: map[string]*dynamic.Middleware{},
|
||||
assertResponse: func(t *testing.T, resp *http.Response) {},
|
||||
},
|
||||
{
|
||||
desc: "one modifier",
|
||||
middlewares: []string{"foo", "bar"},
|
||||
buildResponse: stubResponse,
|
||||
conf: map[string]*config.Middleware{
|
||||
conf: map[string]*dynamic.Middleware{
|
||||
"foo": {
|
||||
Headers: &config.Headers{
|
||||
Headers: &dynamic.Headers{
|
||||
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
|
||||
},
|
||||
},
|
||||
|
@ -52,7 +52,7 @@ func TestBuilderBuild(t *testing.T) {
|
|||
{
|
||||
desc: "secure: one modifier",
|
||||
middlewares: []string{"foo", "bar"},
|
||||
buildResponse: func(middlewares map[string]*config.Middleware) *http.Response {
|
||||
buildResponse: func(middlewares map[string]*dynamic.Middleware) *http.Response {
|
||||
ctx := context.Background()
|
||||
|
||||
var request *http.Request
|
||||
|
@ -69,14 +69,14 @@ func TestBuilderBuild(t *testing.T) {
|
|||
|
||||
return &http.Response{Header: make(http.Header), Request: request}
|
||||
},
|
||||
conf: map[string]*config.Middleware{
|
||||
conf: map[string]*dynamic.Middleware{
|
||||
"foo": {
|
||||
Headers: &config.Headers{
|
||||
Headers: &dynamic.Headers{
|
||||
ReferrerPolicy: "no-referrer",
|
||||
},
|
||||
},
|
||||
"bar": {
|
||||
Headers: &config.Headers{
|
||||
Headers: &dynamic.Headers{
|
||||
CustomResponseHeaders: map[string]string{"X-Bar": "bar"},
|
||||
},
|
||||
},
|
||||
|
@ -91,14 +91,14 @@ func TestBuilderBuild(t *testing.T) {
|
|||
desc: "two modifiers",
|
||||
middlewares: []string{"foo", "bar"},
|
||||
buildResponse: stubResponse,
|
||||
conf: map[string]*config.Middleware{
|
||||
conf: map[string]*dynamic.Middleware{
|
||||
"foo": {
|
||||
Headers: &config.Headers{
|
||||
Headers: &dynamic.Headers{
|
||||
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
|
||||
},
|
||||
},
|
||||
"bar": {
|
||||
Headers: &config.Headers{
|
||||
Headers: &dynamic.Headers{
|
||||
CustomResponseHeaders: map[string]string{"X-Bar": "bar"},
|
||||
},
|
||||
},
|
||||
|
@ -114,14 +114,14 @@ func TestBuilderBuild(t *testing.T) {
|
|||
desc: "modifier order",
|
||||
middlewares: []string{"foo", "bar"},
|
||||
buildResponse: stubResponse,
|
||||
conf: map[string]*config.Middleware{
|
||||
conf: map[string]*dynamic.Middleware{
|
||||
"foo": {
|
||||
Headers: &config.Headers{
|
||||
Headers: &dynamic.Headers{
|
||||
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
|
||||
},
|
||||
},
|
||||
"bar": {
|
||||
Headers: &config.Headers{
|
||||
Headers: &dynamic.Headers{
|
||||
CustomResponseHeaders: map[string]string{"X-Foo": "bar"},
|
||||
},
|
||||
},
|
||||
|
@ -136,19 +136,19 @@ func TestBuilderBuild(t *testing.T) {
|
|||
desc: "chain",
|
||||
middlewares: []string{"chain"},
|
||||
buildResponse: stubResponse,
|
||||
conf: map[string]*config.Middleware{
|
||||
conf: map[string]*dynamic.Middleware{
|
||||
"foo": {
|
||||
Headers: &config.Headers{
|
||||
Headers: &dynamic.Headers{
|
||||
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
|
||||
},
|
||||
},
|
||||
"bar": {
|
||||
Headers: &config.Headers{
|
||||
Headers: &dynamic.Headers{
|
||||
CustomResponseHeaders: map[string]string{"X-Foo": "bar"},
|
||||
},
|
||||
},
|
||||
"chain": {
|
||||
Chain: &config.Chain{
|
||||
Chain: &dynamic.Chain{
|
||||
Middlewares: []string{"foo", "bar"},
|
||||
},
|
||||
},
|
||||
|
@ -166,8 +166,8 @@ func TestBuilderBuild(t *testing.T) {
|
|||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
rtConf := config.NewRuntimeConfig(config.Configuration{
|
||||
HTTP: &config.HTTPConfiguration{
|
||||
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
|
||||
HTTP: &dynamic.HTTPConfiguration{
|
||||
Middlewares: test.conf,
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue