Dynamic Configuration Refactoring
This commit is contained in:
parent
d3ae88f108
commit
a09dfa3ce1
452 changed files with 21023 additions and 9419 deletions
160
config/dyn_config.go
Normal file
160
config/dyn_config.go
Normal file
|
@ -0,0 +1,160 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
traefiktls "github.com/containous/traefik/tls"
|
||||
)
|
||||
|
||||
// Router holds the router configuration.
|
||||
type Router struct {
|
||||
EntryPoints []string `json:"entryPoints"`
|
||||
Middlewares []string `json:"middlewares,omitempty" toml:",omitempty"`
|
||||
Service string `json:"service,omitempty" toml:",omitempty"`
|
||||
Rule string `json:"rule,omitempty" toml:",omitempty"`
|
||||
Priority int `json:"priority,omitempty" toml:"priority,omitzero"`
|
||||
}
|
||||
|
||||
// LoadBalancerService holds the LoadBalancerService configuration.
|
||||
type LoadBalancerService struct {
|
||||
Stickiness *Stickiness `json:"stickiness,omitempty" toml:",omitempty"`
|
||||
Servers []Server `json:"servers,omitempty" toml:",omitempty"`
|
||||
Method string `json:"method,omitempty" toml:",omitempty"`
|
||||
HealthCheck *HealthCheck `json:"healthCheck,omitempty" toml:",omitempty"`
|
||||
PassHostHeader bool `json:"passHostHeader" toml:",omitempty"`
|
||||
ResponseForwarding *ResponseForwarding `json:"forwardingResponse,omitempty" toml:",omitempty"`
|
||||
}
|
||||
|
||||
// ResponseForwarding holds configuration for the forward of the response.
|
||||
type ResponseForwarding struct {
|
||||
FlushInterval string `json:"flushInterval,omitempty" toml:",omitempty"`
|
||||
}
|
||||
|
||||
// Stickiness holds the stickiness configuration.
|
||||
type Stickiness struct {
|
||||
CookieName string `json:"cookieName,omitempty" toml:",omitempty"`
|
||||
}
|
||||
|
||||
// Server holds the server configuration.
|
||||
type Server struct {
|
||||
URL string `json:"url"`
|
||||
Weight int `json:"weight"`
|
||||
}
|
||||
|
||||
// HealthCheck holds the HealthCheck configuration.
|
||||
type HealthCheck struct {
|
||||
Scheme string `json:"scheme,omitempty" toml:",omitempty"`
|
||||
Path string `json:"path,omitempty" toml:",omitempty"`
|
||||
Port int `json:"port,omitempty" toml:",omitempty,omitzero"`
|
||||
// FIXME change string to parse.Duration
|
||||
Interval string `json:"interval,omitempty" toml:",omitempty"`
|
||||
// FIXME change string to parse.Duration
|
||||
Timeout string `json:"timeout,omitempty" toml:",omitempty"`
|
||||
Hostname string `json:"hostname,omitempty" toml:",omitempty"`
|
||||
Headers map[string]string `json:"headers,omitempty" toml:",omitempty"`
|
||||
}
|
||||
|
||||
// ClientTLS holds the TLS specific configurations as client
|
||||
// CA, Cert and Key can be either path or file contents.
|
||||
type ClientTLS struct {
|
||||
CA string `description:"TLS CA" json:"ca,omitempty"`
|
||||
CAOptional bool `description:"TLS CA.Optional" json:"caOptional,omitempty"`
|
||||
Cert string `description:"TLS cert" json:"cert,omitempty"`
|
||||
Key string `description:"TLS key" json:"key,omitempty"`
|
||||
InsecureSkipVerify bool `description:"TLS insecure skip verify" json:"insecureSkipVerify,omitempty"`
|
||||
}
|
||||
|
||||
// CreateTLSConfig creates a TLS config from ClientTLS structures.
|
||||
func (clientTLS *ClientTLS) CreateTLSConfig() (*tls.Config, error) {
|
||||
if clientTLS == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var err error
|
||||
caPool := x509.NewCertPool()
|
||||
clientAuth := tls.NoClientCert
|
||||
if clientTLS.CA != "" {
|
||||
var ca []byte
|
||||
if _, errCA := os.Stat(clientTLS.CA); errCA == nil {
|
||||
ca, err = ioutil.ReadFile(clientTLS.CA)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read CA. %s", err)
|
||||
}
|
||||
} else {
|
||||
ca = []byte(clientTLS.CA)
|
||||
}
|
||||
|
||||
if !caPool.AppendCertsFromPEM(ca) {
|
||||
return nil, fmt.Errorf("failed to parse CA")
|
||||
}
|
||||
|
||||
if clientTLS.CAOptional {
|
||||
clientAuth = tls.VerifyClientCertIfGiven
|
||||
} else {
|
||||
clientAuth = tls.RequireAndVerifyClientCert
|
||||
}
|
||||
}
|
||||
|
||||
cert := tls.Certificate{}
|
||||
_, errKeyIsFile := os.Stat(clientTLS.Key)
|
||||
|
||||
if !clientTLS.InsecureSkipVerify && (len(clientTLS.Cert) == 0 || len(clientTLS.Key) == 0) {
|
||||
return nil, fmt.Errorf("TLS Certificate or Key file must be set when TLS configuration is created")
|
||||
}
|
||||
|
||||
if len(clientTLS.Cert) > 0 && len(clientTLS.Key) > 0 {
|
||||
if _, errCertIsFile := os.Stat(clientTLS.Cert); errCertIsFile == nil {
|
||||
if errKeyIsFile == nil {
|
||||
cert, err = tls.LoadX509KeyPair(clientTLS.Cert, clientTLS.Key)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load TLS keypair: %v", err)
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("tls cert is a file, but tls key is not")
|
||||
}
|
||||
} else {
|
||||
if errKeyIsFile != nil {
|
||||
cert, err = tls.X509KeyPair([]byte(clientTLS.Cert), []byte(clientTLS.Key))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load TLS keypair: %v", err)
|
||||
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("TLS key is a file, but tls cert is not")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &tls.Config{
|
||||
Certificates: []tls.Certificate{cert},
|
||||
RootCAs: caPool,
|
||||
InsecureSkipVerify: clientTLS.InsecureSkipVerify,
|
||||
ClientAuth: clientAuth,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Message holds configuration information exchanged between parts of traefik.
|
||||
type Message struct {
|
||||
ProviderName string
|
||||
Configuration *Configuration
|
||||
}
|
||||
|
||||
// Configurations is for currentConfigurations Map.
|
||||
type Configurations map[string]*Configuration
|
||||
|
||||
// Configuration FIXME better name?
|
||||
type Configuration struct {
|
||||
Routers map[string]*Router `json:"routers,omitempty" toml:",omitempty"`
|
||||
Middlewares map[string]*Middleware `json:"middlewares,omitempty" toml:",omitempty"`
|
||||
Services map[string]*Service `json:"services,omitempty" toml:",omitempty"`
|
||||
TLS []*traefiktls.Configuration `json:"-"`
|
||||
}
|
||||
|
||||
// Service holds a service configuration (can only be of one type at the same time).
|
||||
type Service struct {
|
||||
LoadBalancer *LoadBalancerService `json:"loadbalancer,omitempty" toml:",omitempty,omitzero"`
|
||||
}
|
274
config/middlewares.go
Normal file
274
config/middlewares.go
Normal file
|
@ -0,0 +1,274 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"github.com/containous/flaeg/parse"
|
||||
"github.com/containous/traefik/ip"
|
||||
)
|
||||
|
||||
// Middleware holds the Middleware configuration.
|
||||
type Middleware struct {
|
||||
AddPrefix *AddPrefix `json:"addPrefix,omitempty"`
|
||||
StripPrefix *StripPrefix `json:"stripPrefix,omitempty"`
|
||||
StripPrefixRegex *StripPrefixRegex `json:"stripPrefixRegex,omitempty"`
|
||||
ReplacePath *ReplacePath `json:"replacePath,omitempty"`
|
||||
ReplacePathRegex *ReplacePathRegex `json:"replacePathRegex,omitempty"`
|
||||
Chain *Chain `json:"chain,omitempty"`
|
||||
IPWhiteList *IPWhiteList `json:"ipWhiteList,omitempty"`
|
||||
Headers *Headers `json:"headers,omitempty"`
|
||||
Errors *ErrorPage `json:"errors,omitempty"`
|
||||
RateLimit *RateLimit `json:"rateLimit,omitempty"`
|
||||
Redirect *Redirect `json:"redirect,omitempty"`
|
||||
BasicAuth *BasicAuth `json:"basicAuth,omitempty"`
|
||||
DigestAuth *DigestAuth `json:"digestAuth,omitempty"`
|
||||
ForwardAuth *ForwardAuth `json:"forwardAuth,omitempty"`
|
||||
MaxConn *MaxConn `json:"maxConn,omitempty"`
|
||||
Buffering *Buffering `json:"buffering,omitempty"`
|
||||
CircuitBreaker *CircuitBreaker `json:"circuitBreaker,omitempty"`
|
||||
Compress *Compress `json:"compress,omitempty"`
|
||||
PassTLSClientCert *PassTLSClientCert `json:"passTLSClientCert,omitempty"`
|
||||
Retry *Retry `json:"retry,omitempty"`
|
||||
}
|
||||
|
||||
// AddPrefix holds the AddPrefix configuration.
|
||||
type AddPrefix struct {
|
||||
Prefix string `json:"prefix,omitempty"`
|
||||
}
|
||||
|
||||
// Auth holds the authentication configuration (BASIC, DIGEST, users).
|
||||
type Auth struct {
|
||||
Basic *BasicAuth `json:"basic,omitempty" export:"true"`
|
||||
Digest *DigestAuth `json:"digest,omitempty" export:"true"`
|
||||
Forward *ForwardAuth `json:"forward,omitempty" export:"true"`
|
||||
}
|
||||
|
||||
// BasicAuth holds the HTTP basic authentication configuration.
|
||||
type BasicAuth struct {
|
||||
Users `json:"users,omitempty" mapstructure:","`
|
||||
UsersFile string `json:"usersFile,omitempty"`
|
||||
Realm string `json:"realm,omitempty"`
|
||||
RemoveHeader bool `json:"removeHeader,omitempty"`
|
||||
HeaderField string `json:"headerField,omitempty" export:"true"`
|
||||
}
|
||||
|
||||
// Buffering holds the request/response buffering configuration.
|
||||
type Buffering struct {
|
||||
MaxRequestBodyBytes int64 `json:"maxRequestBodyBytes,omitempty"`
|
||||
MemRequestBodyBytes int64 `json:"memRequestBodyBytes,omitempty"`
|
||||
MaxResponseBodyBytes int64 `json:"maxResponseBodyBytes,omitempty"`
|
||||
MemResponseBodyBytes int64 `json:"memResponseBodyBytes,omitempty"`
|
||||
RetryExpression string `json:"retryExpression,omitempty"`
|
||||
}
|
||||
|
||||
// Chain holds a chain of middlewares
|
||||
type Chain struct {
|
||||
Middlewares []string `json:"middlewares"`
|
||||
}
|
||||
|
||||
// CircuitBreaker holds the circuit breaker configuration.
|
||||
type CircuitBreaker struct {
|
||||
Expression string `json:"expression,omitempty"`
|
||||
}
|
||||
|
||||
// Compress holds the compress configuration.
|
||||
type Compress struct{}
|
||||
|
||||
// DigestAuth holds the Digest HTTP authentication configuration.
|
||||
type DigestAuth struct {
|
||||
Users `json:"users,omitempty" mapstructure:","`
|
||||
UsersFile string `json:"usersFile,omitempty"`
|
||||
RemoveHeader bool `json:"removeHeader,omitempty"`
|
||||
Realm string `json:"realm,omitempty" mapstructure:","`
|
||||
HeaderField string `json:"headerField,omitempty" export:"true"`
|
||||
}
|
||||
|
||||
// ErrorPage holds the custom error page configuration.
|
||||
type ErrorPage struct {
|
||||
Status []string `json:"status,omitempty"`
|
||||
Service string `json:"service,omitempty"`
|
||||
Query string `json:"query,omitempty"`
|
||||
}
|
||||
|
||||
// ForwardAuth holds the http forward authentication configuration.
|
||||
type ForwardAuth struct {
|
||||
Address string `description:"Authentication server address" json:"address,omitempty"`
|
||||
TLS *ClientTLS `description:"Enable TLS support" json:"tls,omitempty" export:"true"`
|
||||
TrustForwardHeader bool `description:"Trust X-Forwarded-* headers" json:"trustForwardHeader,omitempty" export:"true"`
|
||||
AuthResponseHeaders []string `description:"Headers to be forwarded from auth response" json:"authResponseHeaders,omitempty"`
|
||||
}
|
||||
|
||||
// Headers holds the custom header configuration.
|
||||
type Headers struct {
|
||||
CustomRequestHeaders map[string]string `json:"customRequestHeaders,omitempty"`
|
||||
CustomResponseHeaders map[string]string `json:"customResponseHeaders,omitempty"`
|
||||
|
||||
AllowedHosts []string `json:"allowedHosts,omitempty"`
|
||||
HostsProxyHeaders []string `json:"hostsProxyHeaders,omitempty"`
|
||||
SSLRedirect bool `json:"sslRedirect,omitempty"`
|
||||
SSLTemporaryRedirect bool `json:"sslTemporaryRedirect,omitempty"`
|
||||
SSLHost string `json:"sslHost,omitempty"`
|
||||
SSLProxyHeaders map[string]string `json:"sslProxyHeaders,omitempty"`
|
||||
SSLForceHost bool `json:"sslForceHost,omitempty"`
|
||||
STSSeconds int64 `json:"stsSeconds,omitempty"`
|
||||
STSIncludeSubdomains bool `json:"stsIncludeSubdomains,omitempty"`
|
||||
STSPreload bool `json:"stsPreload,omitempty"`
|
||||
ForceSTSHeader bool `json:"forceSTSHeader,omitempty"`
|
||||
FrameDeny bool `json:"frameDeny,omitempty"`
|
||||
CustomFrameOptionsValue string `json:"customFrameOptionsValue,omitempty"`
|
||||
ContentTypeNosniff bool `json:"contentTypeNosniff,omitempty"`
|
||||
BrowserXSSFilter bool `json:"browserXssFilter,omitempty"`
|
||||
CustomBrowserXSSValue string `json:"customBrowserXSSValue,omitempty"`
|
||||
ContentSecurityPolicy string `json:"contentSecurityPolicy,omitempty"`
|
||||
PublicKey string `json:"publicKey,omitempty"`
|
||||
ReferrerPolicy string `json:"referrerPolicy,omitempty"`
|
||||
IsDevelopment bool `json:"isDevelopment,omitempty"`
|
||||
}
|
||||
|
||||
// HasCustomHeadersDefined checks to see if any of the custom header elements have been set
|
||||
func (h *Headers) HasCustomHeadersDefined() bool {
|
||||
return h != nil && (len(h.CustomResponseHeaders) != 0 ||
|
||||
len(h.CustomRequestHeaders) != 0)
|
||||
}
|
||||
|
||||
// HasSecureHeadersDefined checks to see if any of the secure header elements have been set
|
||||
func (h *Headers) HasSecureHeadersDefined() bool {
|
||||
return h != nil && (len(h.AllowedHosts) != 0 ||
|
||||
len(h.HostsProxyHeaders) != 0 ||
|
||||
h.SSLRedirect ||
|
||||
h.SSLTemporaryRedirect ||
|
||||
h.SSLForceHost ||
|
||||
h.SSLHost != "" ||
|
||||
len(h.SSLProxyHeaders) != 0 ||
|
||||
h.STSSeconds != 0 ||
|
||||
h.STSIncludeSubdomains ||
|
||||
h.STSPreload ||
|
||||
h.ForceSTSHeader ||
|
||||
h.FrameDeny ||
|
||||
h.CustomFrameOptionsValue != "" ||
|
||||
h.ContentTypeNosniff ||
|
||||
h.BrowserXSSFilter ||
|
||||
h.CustomBrowserXSSValue != "" ||
|
||||
h.ContentSecurityPolicy != "" ||
|
||||
h.PublicKey != "" ||
|
||||
h.ReferrerPolicy != "" ||
|
||||
h.IsDevelopment)
|
||||
}
|
||||
|
||||
// IPStrategy holds the ip strategy configuration.
|
||||
type IPStrategy struct {
|
||||
Depth int `json:"depth,omitempty" export:"true"`
|
||||
ExcludedIPs []string `json:"excludedIPs,omitempty"`
|
||||
}
|
||||
|
||||
// Get an IP selection strategy
|
||||
// if nil return the RemoteAddr strategy
|
||||
// else return a strategy base on the configuration using the X-Forwarded-For Header.
|
||||
// Depth override the ExcludedIPs
|
||||
func (s *IPStrategy) Get() (ip.Strategy, error) {
|
||||
if s == nil {
|
||||
return &ip.RemoteAddrStrategy{}, nil
|
||||
}
|
||||
|
||||
if s.Depth > 0 {
|
||||
return &ip.DepthStrategy{
|
||||
Depth: s.Depth,
|
||||
}, nil
|
||||
}
|
||||
|
||||
if len(s.ExcludedIPs) > 0 {
|
||||
checker, err := ip.NewChecker(s.ExcludedIPs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ip.CheckerStrategy{
|
||||
Checker: checker,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &ip.RemoteAddrStrategy{}, nil
|
||||
}
|
||||
|
||||
// IPWhiteList holds the ip white list configuration.
|
||||
type IPWhiteList struct {
|
||||
SourceRange []string `json:"sourceRange,omitempty"`
|
||||
IPStrategy *IPStrategy `json:"ipStrategy,omitempty"`
|
||||
}
|
||||
|
||||
// MaxConn holds maximum connection configuration.
|
||||
type MaxConn struct {
|
||||
Amount int64 `json:"amount,omitempty"`
|
||||
ExtractorFunc string `json:"extractorFunc,omitempty"`
|
||||
}
|
||||
|
||||
// PassTLSClientCert holds the TLS client cert headers configuration.
|
||||
type PassTLSClientCert struct {
|
||||
PEM bool `description:"Enable header with escaped client pem" json:"pem"`
|
||||
Infos *TLSClientCertificateInfos `description:"Enable header with configured client cert infos" json:"infos,omitempty"`
|
||||
}
|
||||
|
||||
// Rate holds the rate limiting configuration for a specific time period.
|
||||
type Rate struct {
|
||||
Period parse.Duration `json:"period,omitempty"`
|
||||
Average int64 `json:"average,omitempty"`
|
||||
Burst int64 `json:"burst,omitempty"`
|
||||
}
|
||||
|
||||
// RateLimit holds the rate limiting configuration for a given frontend.
|
||||
type RateLimit struct {
|
||||
RateSet map[string]*Rate `json:"rateset,omitempty"`
|
||||
// FIXME replace by ipStrategy see oxy and replace
|
||||
ExtractorFunc string `json:"extractorFunc,omitempty"`
|
||||
}
|
||||
|
||||
// Redirect holds the redirection configuration of an entry point to another, or to an URL.
|
||||
type Redirect struct {
|
||||
Regex string `json:"regex,omitempty"`
|
||||
Replacement string `json:"replacement,omitempty"`
|
||||
Permanent bool `json:"permanent,omitempty"`
|
||||
}
|
||||
|
||||
// ReplacePath holds the ReplacePath configuration.
|
||||
type ReplacePath struct {
|
||||
Path string `json:"path,omitempty"`
|
||||
}
|
||||
|
||||
// ReplacePathRegex holds the ReplacePathRegex configuration.
|
||||
type ReplacePathRegex struct {
|
||||
Regex string `json:"regex,omitempty"`
|
||||
Replacement string `json:"replacement,omitempty"`
|
||||
}
|
||||
|
||||
// Retry contains request retry config
|
||||
type Retry struct {
|
||||
Attempts int `description:"Number of attempts" export:"true"`
|
||||
}
|
||||
|
||||
// StripPrefix holds the StripPrefix configuration.
|
||||
type StripPrefix struct {
|
||||
Prefixes []string `json:"prefixes,omitempty"`
|
||||
}
|
||||
|
||||
// StripPrefixRegex holds the StripPrefixRegex configuration.
|
||||
type StripPrefixRegex struct {
|
||||
Regex []string `json:"regex,omitempty"`
|
||||
}
|
||||
|
||||
// TLSClientCertificateInfos holds the client TLS certificate infos configuration.
|
||||
type TLSClientCertificateInfos struct {
|
||||
NotAfter bool `description:"Add NotAfter info in header" json:"notAfter"`
|
||||
NotBefore bool `description:"Add NotBefore info in header" json:"notBefore"`
|
||||
Subject *TLSCLientCertificateSubjectInfos `description:"Add Subject info in header" json:"subject,omitempty"`
|
||||
Sans bool `description:"Add Sans info in header" json:"sans"`
|
||||
}
|
||||
|
||||
// TLSCLientCertificateSubjectInfos holds the client TLS certificate subject infos configuration.
|
||||
type TLSCLientCertificateSubjectInfos struct {
|
||||
Country bool `description:"Add Country info in header" json:"country"`
|
||||
Province bool `description:"Add Province info in header" json:"province"`
|
||||
Locality bool `description:"Add Locality info in header" json:"locality"`
|
||||
Organization bool `description:"Add Organization info in header" json:"organization"`
|
||||
CommonName bool `description:"Add CommonName info in header" json:"commonName"`
|
||||
SerialNumber bool `description:"Add SerialNumber info in header" json:"serialNumber"`
|
||||
}
|
||||
|
||||
// Users holds a list of users
|
||||
type Users []string
|
246
config/static/convert.go
Normal file
246
config/static/convert.go
Normal file
|
@ -0,0 +1,246 @@
|
|||
package static
|
||||
|
||||
import (
|
||||
oldapi "github.com/containous/traefik/old/api"
|
||||
"github.com/containous/traefik/old/configuration"
|
||||
oldtracing "github.com/containous/traefik/old/middlewares/tracing"
|
||||
oldfile "github.com/containous/traefik/old/provider/file"
|
||||
oldtypes "github.com/containous/traefik/old/types"
|
||||
"github.com/containous/traefik/ping"
|
||||
"github.com/containous/traefik/provider"
|
||||
"github.com/containous/traefik/provider/file"
|
||||
"github.com/containous/traefik/tracing/datadog"
|
||||
"github.com/containous/traefik/tracing/jaeger"
|
||||
"github.com/containous/traefik/tracing/zipkin"
|
||||
"github.com/containous/traefik/types"
|
||||
)
|
||||
|
||||
// ConvertStaticConf FIXME sugar
|
||||
// Deprecated
|
||||
func ConvertStaticConf(globalConfiguration configuration.GlobalConfiguration) Configuration {
|
||||
staticConfiguration := Configuration{}
|
||||
|
||||
staticConfiguration.EntryPoints = &EntryPoints{
|
||||
EntryPointList: make(EntryPointList),
|
||||
Defaults: globalConfiguration.DefaultEntryPoints,
|
||||
}
|
||||
|
||||
if globalConfiguration.EntryPoints != nil {
|
||||
for name, ep := range globalConfiguration.EntryPoints {
|
||||
staticConfiguration.EntryPoints.EntryPointList[name] = EntryPoint{
|
||||
Address: ep.Address,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if globalConfiguration.Ping != nil {
|
||||
old := globalConfiguration.Ping
|
||||
staticConfiguration.Ping = &ping.Handler{
|
||||
EntryPoint: old.EntryPoint,
|
||||
}
|
||||
}
|
||||
|
||||
staticConfiguration.API = convertAPI(globalConfiguration.API)
|
||||
staticConfiguration.Constraints = convertConstraints(globalConfiguration.Constraints)
|
||||
staticConfiguration.File = convertFile(globalConfiguration.File)
|
||||
staticConfiguration.Metrics = ConvertMetrics(globalConfiguration.Metrics)
|
||||
staticConfiguration.AccessLog = ConvertAccessLog(globalConfiguration.AccessLog)
|
||||
staticConfiguration.Tracing = ConvertTracing(globalConfiguration.Tracing)
|
||||
staticConfiguration.HostResolver = ConvertHostResolverConfig(globalConfiguration.HostResolver)
|
||||
|
||||
return staticConfiguration
|
||||
}
|
||||
|
||||
// ConvertAccessLog FIXME sugar
|
||||
// Deprecated
|
||||
func ConvertAccessLog(old *oldtypes.AccessLog) *types.AccessLog {
|
||||
if old == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
accessLog := &types.AccessLog{
|
||||
FilePath: old.FilePath,
|
||||
Format: old.Format,
|
||||
BufferingSize: old.BufferingSize,
|
||||
}
|
||||
|
||||
if old.Filters != nil {
|
||||
accessLog.Filters = &types.AccessLogFilters{
|
||||
StatusCodes: types.StatusCodes(old.Filters.StatusCodes),
|
||||
RetryAttempts: old.Filters.RetryAttempts,
|
||||
MinDuration: old.Filters.MinDuration,
|
||||
}
|
||||
}
|
||||
|
||||
if old.Fields != nil {
|
||||
accessLog.Fields = &types.AccessLogFields{
|
||||
DefaultMode: old.Fields.DefaultMode,
|
||||
Names: types.FieldNames(old.Fields.Names),
|
||||
}
|
||||
|
||||
if old.Fields.Headers != nil {
|
||||
accessLog.Fields.Headers = &types.FieldHeaders{
|
||||
DefaultMode: old.Fields.Headers.DefaultMode,
|
||||
Names: types.FieldHeaderNames(old.Fields.Headers.Names),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return accessLog
|
||||
}
|
||||
|
||||
// ConvertMetrics FIXME sugar
|
||||
// Deprecated
|
||||
func ConvertMetrics(old *oldtypes.Metrics) *types.Metrics {
|
||||
if old == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
metrics := &types.Metrics{}
|
||||
|
||||
if old.Prometheus != nil {
|
||||
metrics.Prometheus = &types.Prometheus{
|
||||
EntryPoint: old.Prometheus.EntryPoint,
|
||||
Buckets: types.Buckets(old.Prometheus.Buckets),
|
||||
}
|
||||
}
|
||||
|
||||
if old.Datadog != nil {
|
||||
metrics.Datadog = &types.Datadog{
|
||||
Address: old.Datadog.Address,
|
||||
PushInterval: old.Datadog.PushInterval,
|
||||
}
|
||||
}
|
||||
|
||||
if old.StatsD != nil {
|
||||
metrics.StatsD = &types.Statsd{
|
||||
Address: old.StatsD.Address,
|
||||
PushInterval: old.StatsD.PushInterval,
|
||||
}
|
||||
}
|
||||
if old.InfluxDB != nil {
|
||||
metrics.InfluxDB = &types.InfluxDB{
|
||||
Address: old.InfluxDB.Address,
|
||||
Protocol: old.InfluxDB.Protocol,
|
||||
PushInterval: old.InfluxDB.PushInterval,
|
||||
Database: old.InfluxDB.Database,
|
||||
RetentionPolicy: old.InfluxDB.RetentionPolicy,
|
||||
Username: old.InfluxDB.Username,
|
||||
Password: old.InfluxDB.Password,
|
||||
}
|
||||
}
|
||||
|
||||
return metrics
|
||||
}
|
||||
|
||||
// ConvertTracing FIXME sugar
|
||||
// Deprecated
|
||||
func ConvertTracing(old *oldtracing.Tracing) *Tracing {
|
||||
if old == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
tra := &Tracing{
|
||||
Backend: old.Backend,
|
||||
ServiceName: old.ServiceName,
|
||||
SpanNameLimit: old.SpanNameLimit,
|
||||
}
|
||||
|
||||
if old.Jaeger != nil {
|
||||
tra.Jaeger = &jaeger.Config{
|
||||
SamplingServerURL: old.Jaeger.SamplingServerURL,
|
||||
SamplingType: old.Jaeger.SamplingType,
|
||||
SamplingParam: old.Jaeger.SamplingParam,
|
||||
LocalAgentHostPort: old.Jaeger.LocalAgentHostPort,
|
||||
Gen128Bit: old.Jaeger.Gen128Bit,
|
||||
Propagation: old.Jaeger.Propagation,
|
||||
}
|
||||
}
|
||||
|
||||
if old.Zipkin != nil {
|
||||
tra.Zipkin = &zipkin.Config{
|
||||
HTTPEndpoint: old.Zipkin.HTTPEndpoint,
|
||||
SameSpan: old.Zipkin.SameSpan,
|
||||
ID128Bit: old.Zipkin.ID128Bit,
|
||||
Debug: old.Zipkin.Debug,
|
||||
}
|
||||
}
|
||||
|
||||
if old.DataDog != nil {
|
||||
tra.DataDog = &datadog.Config{
|
||||
LocalAgentHostPort: old.DataDog.LocalAgentHostPort,
|
||||
GlobalTag: old.DataDog.GlobalTag,
|
||||
Debug: old.DataDog.Debug,
|
||||
}
|
||||
}
|
||||
|
||||
return tra
|
||||
}
|
||||
|
||||
func convertAPI(old *oldapi.Handler) *API {
|
||||
if old == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
api := &API{
|
||||
EntryPoint: old.EntryPoint,
|
||||
Dashboard: old.Dashboard,
|
||||
DashboardAssets: old.DashboardAssets,
|
||||
}
|
||||
|
||||
if old.Statistics != nil {
|
||||
api.Statistics = &types.Statistics{
|
||||
RecentErrors: old.Statistics.RecentErrors,
|
||||
}
|
||||
}
|
||||
|
||||
return api
|
||||
}
|
||||
|
||||
func convertConstraints(oldConstraints oldtypes.Constraints) types.Constraints {
|
||||
constraints := types.Constraints{}
|
||||
for _, value := range oldConstraints {
|
||||
constraint := &types.Constraint{
|
||||
Key: value.Key,
|
||||
MustMatch: value.MustMatch,
|
||||
Regex: value.Regex,
|
||||
}
|
||||
|
||||
constraints = append(constraints, constraint)
|
||||
}
|
||||
return constraints
|
||||
}
|
||||
|
||||
func convertFile(old *oldfile.Provider) *file.Provider {
|
||||
if old == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
f := &file.Provider{
|
||||
BaseProvider: provider.BaseProvider{
|
||||
Watch: old.Watch,
|
||||
Filename: old.Filename,
|
||||
Trace: old.Trace,
|
||||
},
|
||||
Directory: old.Directory,
|
||||
TraefikFile: old.TraefikFile,
|
||||
}
|
||||
f.DebugLogGeneratedTemplate = old.DebugLogGeneratedTemplate
|
||||
f.Constraints = convertConstraints(old.Constraints)
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
// ConvertHostResolverConfig FIXME
|
||||
// Deprecated
|
||||
func ConvertHostResolverConfig(oldconfig *configuration.HostResolverConfig) *HostResolverConfig {
|
||||
if oldconfig == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &HostResolverConfig{
|
||||
CnameFlattening: oldconfig.CnameFlattening,
|
||||
ResolvConfig: oldconfig.ResolvConfig,
|
||||
ResolvDepth: oldconfig.ResolvDepth,
|
||||
}
|
||||
}
|
113
config/static/static_config.go
Normal file
113
config/static/static_config.go
Normal file
|
@ -0,0 +1,113 @@
|
|||
package static
|
||||
|
||||
import (
|
||||
"github.com/containous/flaeg/parse"
|
||||
"github.com/containous/traefik/ping"
|
||||
"github.com/containous/traefik/provider/file"
|
||||
"github.com/containous/traefik/tls"
|
||||
"github.com/containous/traefik/tracing/datadog"
|
||||
"github.com/containous/traefik/tracing/jaeger"
|
||||
"github.com/containous/traefik/tracing/zipkin"
|
||||
"github.com/containous/traefik/types"
|
||||
"github.com/elazarl/go-bindata-assetfs"
|
||||
)
|
||||
|
||||
// Configuration FIXME temp static configuration
|
||||
type Configuration struct {
|
||||
Global *Global
|
||||
EntryPoints *EntryPoints
|
||||
|
||||
API *API `description:"Enable api/dashboard" export:"true"`
|
||||
Metrics *types.Metrics `description:"Enable a metrics exporter" export:"true"`
|
||||
Ping *ping.Handler `description:"Enable ping" export:"true"`
|
||||
// Rest *rest.Provider `description:"Enable Rest backend with default settings" export:"true"`
|
||||
|
||||
Log *types.TraefikLog
|
||||
AccessLog *types.AccessLog `description:"Access log settings" export:"true"`
|
||||
Tracing *Tracing `description:"OpenTracing configuration" export:"true"`
|
||||
|
||||
File *file.Provider `description:"Enable File backend with default settings" export:"true"`
|
||||
Constraints types.Constraints `description:"Filter services by constraint, matching with service tags" export:"true"`
|
||||
|
||||
HostResolver *HostResolverConfig `description:"Enable CNAME Flattening" export:"true"`
|
||||
|
||||
// TODO
|
||||
// ACME *acme.ACME `description:"Enable ACME (Let's Encrypt): automatic SSL" export:"true"`
|
||||
// Retry *Retry `description:"Enable retry sending request if network error" export:"true"`
|
||||
// HealthCheck *HealthCheckConfig `description:"Health check parameters" export:"true"`
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
// Global holds the global configuration.
|
||||
type Global struct {
|
||||
Debug bool `short:"d" description:"Enable debug mode" export:"true"`
|
||||
CheckNewVersion bool `description:"Periodically check if a new version has been released" export:"true"`
|
||||
SendAnonymousUsage bool `description:"send periodically anonymous usage statistics" export:"true"`
|
||||
InsecureSkipVerify bool `description:"Disable SSL certificate verification" export:"true"`
|
||||
RootCAs tls.FilesOrContents `description:"Add cert file for self-signed certificate"`
|
||||
ProvidersThrottleDuration parse.Duration `description:"Backends throttle duration: minimum duration between 2 events from providers before applying a new configuration. It avoids unnecessary reloads if multiples events are sent in a short amount of time." export:"true"`
|
||||
LifeCycle *LifeCycle `description:"Timeouts influencing the server life cycle" export:"true"`
|
||||
RespondingTimeouts *RespondingTimeouts `description:"Timeouts for incoming requests to the Traefik instance" export:"true"`
|
||||
ForwardingTimeouts *ForwardingTimeouts `description:"Timeouts for requests forwarded to the backend servers" export:"true"`
|
||||
MaxIdleConnsPerHost int `description:"If non-zero, controls the maximum idle (keep-alive) to keep per-host. If zero, DefaultMaxIdleConnsPerHost is used" export:"true"`
|
||||
}
|
||||
|
||||
// API holds the API configuration
|
||||
type API struct {
|
||||
EntryPoint string `description:"EntryPoint" export:"true"`
|
||||
Dashboard bool `description:"Activate dashboard" export:"true"`
|
||||
Statistics *types.Statistics `description:"Enable more detailed statistics" export:"true"`
|
||||
Middlewares []string `description:"Middleware list" export:"true"`
|
||||
DashboardAssets *assetfs.AssetFS `json:"-"`
|
||||
}
|
||||
|
||||
// RespondingTimeouts contains timeout configurations for incoming requests to the Traefik instance.
|
||||
type RespondingTimeouts struct {
|
||||
ReadTimeout parse.Duration `description:"ReadTimeout is the maximum duration for reading the entire request, including the body. If zero, no timeout is set" export:"true"`
|
||||
WriteTimeout parse.Duration `description:"WriteTimeout is the maximum duration before timing out writes of the response. If zero, no timeout is set" export:"true"`
|
||||
IdleTimeout parse.Duration `description:"IdleTimeout is the maximum amount duration an idle (keep-alive) connection will remain idle before closing itself. Defaults to 180 seconds. If zero, no timeout is set" export:"true"`
|
||||
}
|
||||
|
||||
// ForwardingTimeouts contains timeout configurations for forwarding requests to the backend servers.
|
||||
type ForwardingTimeouts struct {
|
||||
DialTimeout parse.Duration `description:"The amount of time to wait until a connection to a backend server can be established. Defaults to 30 seconds. If zero, no timeout exists" export:"true"`
|
||||
ResponseHeaderTimeout parse.Duration `description:"The amount of time to wait for a server's response headers after fully writing the request (including its body, if any). If zero, no timeout exists" export:"true"`
|
||||
}
|
||||
|
||||
// LifeCycle contains configurations relevant to the lifecycle (such as the shutdown phase) of Traefik.
|
||||
type LifeCycle struct {
|
||||
RequestAcceptGraceTimeout parse.Duration `description:"Duration to keep accepting requests before Traefik initiates the graceful shutdown procedure"`
|
||||
GraceTimeOut parse.Duration `description:"Duration to give active requests a chance to finish before Traefik stops"`
|
||||
}
|
||||
|
||||
// EntryPoint holds the entry point configuration
|
||||
type EntryPoint struct {
|
||||
Address string
|
||||
}
|
||||
|
||||
// EntryPointList holds the HTTP entry point list type.
|
||||
type EntryPointList map[string]EntryPoint
|
||||
|
||||
// EntryPoints holds the entry points configuration.
|
||||
type EntryPoints struct {
|
||||
EntryPointList
|
||||
Defaults []string
|
||||
}
|
||||
|
||||
// Tracing holds the tracing configuration.
|
||||
type Tracing struct {
|
||||
Backend string `description:"Selects the tracking backend ('jaeger','zipkin', 'datadog')." export:"true"`
|
||||
ServiceName string `description:"Set the name for this service" export:"true"`
|
||||
SpanNameLimit int `description:"Set the maximum character limit for Span names (default 0 = no limit)" export:"true"`
|
||||
Jaeger *jaeger.Config `description:"Settings for jaeger"`
|
||||
Zipkin *zipkin.Config `description:"Settings for zipkin"`
|
||||
DataDog *datadog.Config `description:"Settings for DataDog"`
|
||||
}
|
||||
|
||||
// HostResolverConfig contain configuration for CNAME Flattening.
|
||||
type HostResolverConfig struct {
|
||||
CnameFlattening bool `description:"A flag to enable/disable CNAME flattening" export:"true"`
|
||||
ResolvConfig string `description:"resolv.conf used for DNS resolving" export:"true"`
|
||||
ResolvDepth int `description:"The maximal depth of DNS recursive resolving" export:"true"`
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue