Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all available configuration to KV Backend #2652

Merged
merged 11 commits into from
Jan 4, 2018
99 changes: 99 additions & 0 deletions autogen/gentemplates/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 69 additions & 2 deletions provider/kv/filler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,35 @@ func withPair(key string, value string) func(map[string]string) {
}
}

func withErrorPage(name string, backend, query, status string) func(map[string]string) {
return func(pairs map[string]string) {
if len(name) == 0 {
return
}

withPair(pathFrontendErrorPages+name+pathFrontendErrorPagesBackend, backend)(pairs)
withPair(pathFrontendErrorPages+name+pathFrontendErrorPagesQuery, query)(pairs)
withPair(pathFrontendErrorPages+name+pathFrontendErrorPagesStatus, status)(pairs)
}
}

func withRateLimit(extractorFunc string, opts ...func(map[string]string)) func(map[string]string) {
return func(pairs map[string]string) {
pairs[pathFrontendRateLimitExtractorFunc] = extractorFunc
for _, opt := range opts {
opt(pairs)
}
}
}

func withLimit(name string, average, burst, period string) func(map[string]string) {
return func(pairs map[string]string) {
pairs[pathFrontendRateLimitRateSet+name+pathFrontendRateLimitAverage] = average
pairs[pathFrontendRateLimitRateSet+name+pathFrontendRateLimitBurst] = burst
pairs[pathFrontendRateLimitRateSet+name+pathFrontendRateLimitPeriod] = period
}
}

func TestFiller(t *testing.T) {
expected := []*store.KVPair{
{Key: "traefik/backends/backend.with.dot.too", Value: []byte("")},
Expand All @@ -92,6 +121,26 @@ func TestFiller(t *testing.T) {
{Key: "traefik/backends/backend.with.dot.too/servers/server.with.dot/weight", Value: []byte("0")},
{Key: "traefik/frontends/frontend.with.dot", Value: []byte("")},
{Key: "traefik/frontends/frontend.with.dot/backend", Value: []byte("backend.with.dot.too")},
{Key: "traefik/frontends/frontend.with.dot/errors", Value: []byte("")},
{Key: "traefik/frontends/frontend.with.dot/errors/bar", Value: []byte("")},
{Key: "traefik/frontends/frontend.with.dot/errors/bar/backend", Value: []byte("error")},
{Key: "traefik/frontends/frontend.with.dot/errors/bar/query", Value: []byte("/test2")},
{Key: "traefik/frontends/frontend.with.dot/errors/bar/status", Value: []byte("400-405")},
{Key: "traefik/frontends/frontend.with.dot/errors/foo", Value: []byte("")},
{Key: "traefik/frontends/frontend.with.dot/errors/foo/backend", Value: []byte("error")},
{Key: "traefik/frontends/frontend.with.dot/errors/foo/query", Value: []byte("/test1")},
{Key: "traefik/frontends/frontend.with.dot/errors/foo/status", Value: []byte("500-501, 503-599")},
{Key: "traefik/frontends/frontend.with.dot/ratelimit", Value: []byte("")},
{Key: "traefik/frontends/frontend.with.dot/ratelimit/extractorfunc", Value: []byte("client.ip")},
{Key: "traefik/frontends/frontend.with.dot/ratelimit/rateset", Value: []byte("")},
{Key: "traefik/frontends/frontend.with.dot/ratelimit/rateset/bar", Value: []byte("")},
{Key: "traefik/frontends/frontend.with.dot/ratelimit/rateset/bar/average", Value: []byte("3")},
{Key: "traefik/frontends/frontend.with.dot/ratelimit/rateset/bar/burst", Value: []byte("6")},
{Key: "traefik/frontends/frontend.with.dot/ratelimit/rateset/bar/period", Value: []byte("9")},
{Key: "traefik/frontends/frontend.with.dot/ratelimit/rateset/foo", Value: []byte("")},
{Key: "traefik/frontends/frontend.with.dot/ratelimit/rateset/foo/average", Value: []byte("6")},
{Key: "traefik/frontends/frontend.with.dot/ratelimit/rateset/foo/burst", Value: []byte("12")},
{Key: "traefik/frontends/frontend.with.dot/ratelimit/rateset/foo/period", Value: []byte("18")},
{Key: "traefik/frontends/frontend.with.dot/routes", Value: []byte("")},
{Key: "traefik/frontends/frontend.with.dot/routes/route.with.dot", Value: []byte("")},
{Key: "traefik/frontends/frontend.with.dot/routes/route.with.dot/rule", Value: []byte("Host:test.localhost")},
Expand All @@ -100,7 +149,12 @@ func TestFiller(t *testing.T) {
pairs1 := filler("traefik",
frontend("frontend.with.dot",
withPair("backend", "backend.with.dot.too"),
withPair("routes/route.with.dot/rule", "Host:test.localhost")),
withPair("routes/route.with.dot/rule", "Host:test.localhost"),
withErrorPage("foo", "error", "/test1", "500-501, 503-599"),
withErrorPage("bar", "error", "/test2", "400-405"),
withRateLimit("client.ip",
withLimit("foo", "6", "12", "18"),
withLimit("bar", "3", "6", "9"))),
backend("backend.with.dot.too",
withPair("servers/server.with.dot/url", "http://172.17.0.2:80"),
withPair("servers/server.with.dot/weight", "0"),
Expand All @@ -111,7 +165,20 @@ func TestFiller(t *testing.T) {
pairs2 := filler("traefik",
entry("frontends/frontend.with.dot",
withPair("backend", "backend.with.dot.too"),
withPair("routes/route.with.dot/rule", "Host:test.localhost")),
withPair("routes/route.with.dot/rule", "Host:test.localhost"),
withPair("errors/foo/backend", "error"),
withPair("errors/foo/query", "/test1"),
withPair("errors/foo/status", "500-501, 503-599"),
withPair("errors/bar/backend", "error"),
withPair("errors/bar/query", "/test2"),
withPair("errors/bar/status", "400-405"),
withPair("ratelimit/extractorfunc", "client.ip"),
withPair("ratelimit/rateset/foo/average", "6"),
withPair("ratelimit/rateset/foo/burst", "12"),
withPair("ratelimit/rateset/foo/period", "18"),
withPair("ratelimit/rateset/bar/average", "3"),
withPair("ratelimit/rateset/bar/burst", "6"),
withPair("ratelimit/rateset/bar/period", "9")),
entry("backends/backend.with.dot.too",
withPair("servers/server.with.dot/url", "http://172.17.0.2:80"),
withPair("servers/server.with.dot/weight", "0"),
Expand Down
59 changes: 54 additions & 5 deletions provider/kv/keynames.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,68 @@ const (
pathBackends = "/backends/"
pathBackendCircuitBreakerExpression = "/circuitbreaker/expression"
pathBackendHealthCheckPath = "/healthcheck/path"
pathBackendHealthCheckPort = "/healthcheck/port"
pathBackendHealthCheckInterval = "/healthcheck/interval"
pathBackendLoadBalancerMethod = "/loadbalancer/method"
pathBackendLoadBalancerSticky = "/loadbalancer/sticky"
pathBackendLoadBalancerStickiness = "/loadbalancer/stickiness"
pathBackendLoadBalancerStickinessCookieName = "/loadbalancer/stickiness/cookiename"
pathBackendMaxConnAmount = "/maxconn/amount"
pathBackendMaxConnExtractorFunc = "/maxconn/extractorfunc"
pathBackendServers = "/servers/"
pathBackendServerURL = "/url"
pathBackendServerWeight = "/weight"

pathFrontends = "/frontends/"
pathFrontendBackend = "/backend"
pathFrontendPriority = "/priority"
pathFrontendPassHostHeader = "/passHostHeader"
pathFrontendEntryPoints = "/entrypoints"
pathFrontends = "/frontends/"
pathFrontendBackend = "/backend"
pathFrontendPriority = "/priority"
pathFrontendPassHostHeader = "/passHostHeader"
pathFrontendPassTLSCert = "/passtlscert"
pathFrontendWhiteListSourceRange = "/whitelistsourcerange"
pathFrontendBasicAuth = "/basicauth"
pathFrontendEntryPoints = "/entrypoints"
pathFrontendRedirectEntryPoint = "/redirect/entrypoint"
pathFrontendRedirectRegex = "/redirect/regex"
pathFrontendRedirectReplacement = "/redirect/replacement"
pathFrontendErrorPages = "/errors/"
pathFrontendErrorPagesBackend = "/backend"
pathFrontendErrorPagesQuery = "/query"
pathFrontendErrorPagesStatus = "/status"
pathFrontendRateLimit = "/ratelimit/"
pathFrontendRateLimitRateSet = pathFrontendRateLimit + "rateset/"
pathFrontendRateLimitExtractorFunc = pathFrontendRateLimit + "extractorfunc"
pathFrontendRateLimitPeriod = "/period"
pathFrontendRateLimitAverage = "/average"
pathFrontendRateLimitBurst = "/burst"

pathFrontendCustomRequestHeaders = "/headers/customrequestheaders/"
pathFrontendCustomResponseHeaders = "/headers/customresponseheaders/"
pathFrontendAllowedHosts = "/headers/allowedhosts"
pathFrontendHostsProxyHeaders = "/headers/hostsproxyheaders"
pathFrontendSSLRedirect = "/headers/sslredirect"
pathFrontendSSLTemporaryRedirect = "/headers/ssltemporaryredirect"
pathFrontendSSLHost = "/headers/sslhost"
pathFrontendSSLProxyHeaders = "/headers/sslproxyheaders/"
pathFrontendSTSSeconds = "/headers/stsseconds"
pathFrontendSTSIncludeSubdomains = "/headers/stsincludesubdomains"
pathFrontendSTSPreload = "/headers/stspreload"
pathFrontendForceSTSHeader = "/headers/forcestsheader"
pathFrontendFrameDeny = "/headers/framedeny"
pathFrontendCustomFrameOptionsValue = "/headers/customframeoptionsvalue"
pathFrontendContentTypeNosniff = "/headers/contenttypenosniff"
pathFrontendBrowserXSSFilter = "/headers/browserxssfilter"
pathFrontendContentSecurityPolicy = "/headers/contentsecuritypolicy"
pathFrontendPublicKey = "/headers/publickey"
pathFrontendReferrerPolicy = "/headers/referrerpolicy"
pathFrontendIsDevelopment = "/headers/isdevelopment"

pathFrontendRoutes = "/routes/"
pathFrontendRule = "/rule"

pathTLSConfiguration = "/tlsconfiguration/"
pathTLSConfigurationEntryPoints = "/entrypoints"
pathTLSConfigurationCertFile = "/certificate/certfile"
pathTLSConfigurationKeyFile = "/certificate/keyfile"

pathTags = "/tags"
pathAlias = "/alias"
Expand Down