2017-04-17 20:47:53 +00:00
package server
2015-09-07 08:38:58 +00:00
2015-09-25 09:44:19 +00:00
import (
2016-06-27 10:19:14 +00:00
"crypto/tls"
2016-01-23 16:41:56 +00:00
"fmt"
2017-06-23 13:15:07 +00:00
"io/ioutil"
2016-06-27 10:19:14 +00:00
"os"
2016-05-03 14:52:14 +00:00
"regexp"
"strings"
"time"
2016-08-05 14:02:46 +00:00
2017-03-27 09:51:53 +00:00
"github.com/containous/flaeg"
2016-08-05 14:02:46 +00:00
"github.com/containous/traefik/acme"
2017-05-25 11:25:53 +00:00
"github.com/containous/traefik/middlewares/accesslog"
2017-04-17 10:50:02 +00:00
"github.com/containous/traefik/provider/boltdb"
"github.com/containous/traefik/provider/consul"
2017-04-15 13:49:53 +00:00
"github.com/containous/traefik/provider/docker"
2017-04-17 10:50:02 +00:00
"github.com/containous/traefik/provider/dynamodb"
"github.com/containous/traefik/provider/ecs"
"github.com/containous/traefik/provider/etcd"
"github.com/containous/traefik/provider/eureka"
"github.com/containous/traefik/provider/file"
"github.com/containous/traefik/provider/kubernetes"
"github.com/containous/traefik/provider/marathon"
"github.com/containous/traefik/provider/mesos"
"github.com/containous/traefik/provider/rancher"
"github.com/containous/traefik/provider/zk"
2016-08-05 14:02:46 +00:00
"github.com/containous/traefik/types"
2015-09-25 09:44:19 +00:00
)
2017-08-18 13:34:04 +00:00
const (
// DefaultHealthCheckInterval is the default health check interval.
DefaultHealthCheckInterval = 30 * time . Second
// DefaultDialTimeout when connecting to a backend server.
DefaultDialTimeout = 30 * time . Second
// DefaultIdleTimeout before closing an idle connection.
DefaultIdleTimeout = 180 * time . Second
)
2017-03-24 08:36:33 +00:00
2016-05-03 14:52:14 +00:00
// TraefikConfiguration holds GlobalConfiguration and other stuff
type TraefikConfiguration struct {
2016-06-24 07:58:42 +00:00
GlobalConfiguration ` mapstructure:",squash" `
ConfigFile string ` short:"c" description:"Configuration file to use (TOML)." `
2016-05-03 14:52:14 +00:00
}
2015-11-06 17:11:57 +00:00
// GlobalConfiguration holds global configuration (with providers, etc.).
// It's populated from the traefik configuration file passed as an argument to the binary.
2015-09-10 13:13:35 +00:00
type GlobalConfiguration struct {
2017-07-18 09:50:07 +00:00
GraceTimeOut flaeg . Duration ` short:"g" description:"Duration to give active requests a chance to finish before Traefik stops" `
2016-08-18 12:20:11 +00:00
Debug bool ` short:"d" description:"Enable debug mode" `
2016-10-27 14:17:02 +00:00
CheckNewVersion bool ` description:"Periodically check if a new version has been released" `
2017-05-25 11:25:53 +00:00
AccessLogsFile string ` description:"(Deprecated) Access logs file" ` // Deprecated
AccessLog * types . AccessLog ` description:"Access log settings" `
2017-05-30 10:06:49 +00:00
TraefikLogsFile string ` description:"Traefik logs file. Stdout is used when omitted or empty" `
2016-08-18 12:20:11 +00:00
LogLevel string ` short:"l" description:"Log level" `
2016-10-21 11:41:11 +00:00
EntryPoints EntryPoints ` description:"Entrypoints definition using format: --entryPoints='Name:http Address::8000 Redirect.EntryPoint:https' --entryPoints='Name:https Address::4442 TLS:tests/traefik.crt,tests/traefik.key;prod/traefik.crt,prod/traefik.key'" `
2016-08-18 12:20:11 +00:00
Cluster * types . Cluster ` description:"Enable clustering" `
Constraints types . Constraints ` description:"Filter services by constraint, matching with service tags" `
2016-05-25 15:06:34 +00:00
ACME * acme . ACME ` description:"Enable ACME (Let's Encrypt): automatic SSL" `
DefaultEntryPoints DefaultEntryPoints ` description:"Entrypoints to be used by frontends that do not specify any entrypoint" `
2017-03-27 09:51:53 +00:00
ProvidersThrottleDuration flaeg . 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." `
2016-05-25 15:06:34 +00:00
MaxIdleConnsPerHost int ` description:"If non-zero, controls the maximum idle (keep-alive) to keep per-host. If zero, DefaultMaxIdleConnsPerHost is used" `
2017-08-18 13:34:04 +00:00
IdleTimeout flaeg . Duration ` description:"(Deprecated) maximum amount of time an idle (keep-alive) connection will remain idle before closing itself." ` // Deprecated
2016-07-23 14:54:37 +00:00
InsecureSkipVerify bool ` description:"Disable SSL certificate verification" `
2017-06-23 13:15:07 +00:00
RootCAs RootCAs ` description:"Add cert file for self-signed certicate" `
2016-05-25 15:06:34 +00:00
Retry * Retry ` description:"Enable retry sending request if network error" `
2017-03-24 08:36:33 +00:00
HealthCheck * HealthCheckConfig ` description:"Health check parameters" `
2017-08-18 13:34:04 +00:00
RespondingTimeouts * RespondingTimeouts ` description:"Timeouts for incoming requests to the Traefik instance" `
ForwardingTimeouts * ForwardingTimeouts ` description:"Timeouts for requests forwarded to the backend servers" `
2017-07-05 21:14:06 +00:00
Docker * docker . Provider ` description:"Enable Docker backend with default settings" `
File * file . Provider ` description:"Enable File backend with default settings" `
Web * WebProvider ` description:"Enable Web backend with default settings" `
Marathon * marathon . Provider ` description:"Enable Marathon backend with default settings" `
Consul * consul . Provider ` description:"Enable Consul backend with default settings" `
ConsulCatalog * consul . CatalogProvider ` description:"Enable Consul catalog backend with default settings" `
Etcd * etcd . Provider ` description:"Enable Etcd backend with default settings" `
Zookeeper * zk . Provider ` description:"Enable Zookeeper backend with default settings" `
Boltdb * boltdb . Provider ` description:"Enable Boltdb backend with default settings" `
Kubernetes * kubernetes . Provider ` description:"Enable Kubernetes backend with default settings" `
Mesos * mesos . Provider ` description:"Enable Mesos backend with default settings" `
Eureka * eureka . Provider ` description:"Enable Eureka backend with default settings" `
ECS * ecs . Provider ` description:"Enable ECS backend with default settings" `
Rancher * rancher . Provider ` description:"Enable Rancher backend with default settings" `
DynamoDB * dynamodb . Provider ` description:"Enable DynamoDB backend with default settings" `
2015-09-10 13:13:35 +00:00
}
2016-01-29 19:34:17 +00:00
// DefaultEntryPoints holds default entry points
type DefaultEntryPoints [ ] string
// String is the method to format the flag's value, part of the flag.Value interface.
// The String method's output will be used in diagnostics.
func ( dep * DefaultEntryPoints ) String ( ) string {
2016-05-27 09:13:34 +00:00
return strings . Join ( * dep , "," )
2016-01-29 19:34:17 +00:00
}
// Set is the method to set the flag value, part of the flag.Value interface.
// Set's argument is a string to be parsed to set the flag.
// It's a comma-separated list, so we split it.
func ( dep * DefaultEntryPoints ) Set ( value string ) error {
entrypoints := strings . Split ( value , "," )
if len ( entrypoints ) == 0 {
2017-05-26 15:03:14 +00:00
return fmt . Errorf ( "bad DefaultEntryPoints format: %s" , value )
2016-01-29 19:34:17 +00:00
}
for _ , entrypoint := range entrypoints {
* dep = append ( * dep , entrypoint )
}
return nil
}
2016-05-03 14:52:14 +00:00
// Get return the EntryPoints map
2016-08-16 17:13:18 +00:00
func ( dep * DefaultEntryPoints ) Get ( ) interface { } {
return DefaultEntryPoints ( * dep )
}
2016-05-03 14:52:14 +00:00
// SetValue sets the EntryPoints map with val
func ( dep * DefaultEntryPoints ) SetValue ( val interface { } ) {
* dep = DefaultEntryPoints ( val . ( DefaultEntryPoints ) )
}
2016-01-29 19:34:17 +00:00
// Type is type of the struct
func ( dep * DefaultEntryPoints ) Type ( ) string {
2017-06-23 13:15:07 +00:00
return "defaultentrypoints"
}
// RootCAs hold the CA we want to have in root
type RootCAs [ ] FileOrContent
// FileOrContent hold a file path or content
type FileOrContent string
func ( f FileOrContent ) String ( ) string {
return string ( f )
}
func ( f FileOrContent ) Read ( ) ( [ ] byte , error ) {
var content [ ] byte
if _ , err := os . Stat ( f . String ( ) ) ; err == nil {
content , err = ioutil . ReadFile ( f . String ( ) )
if err != nil {
return nil , err
}
} else {
content = [ ] byte ( f )
}
return content , nil
}
// String is the method to format the flag's value, part of the flag.Value interface.
// The String method's output will be used in diagnostics.
func ( r * RootCAs ) String ( ) string {
sliceOfString := make ( [ ] string , len ( [ ] FileOrContent ( * r ) ) )
for key , value := range * r {
sliceOfString [ key ] = value . String ( )
}
return strings . Join ( sliceOfString , "," )
}
// Set is the method to set the flag value, part of the flag.Value interface.
// Set's argument is a string to be parsed to set the flag.
// It's a comma-separated list, so we split it.
func ( r * RootCAs ) Set ( value string ) error {
rootCAs := strings . Split ( value , "," )
if len ( rootCAs ) == 0 {
return fmt . Errorf ( "bad RootCAs format: %s" , value )
}
for _ , rootCA := range rootCAs {
* r = append ( * r , FileOrContent ( rootCA ) )
}
return nil
}
// Get return the EntryPoints map
func ( r * RootCAs ) Get ( ) interface { } {
return RootCAs ( * r )
}
// SetValue sets the EntryPoints map with val
func ( r * RootCAs ) SetValue ( val interface { } ) {
* r = RootCAs ( val . ( RootCAs ) )
}
// Type is type of the struct
func ( r * RootCAs ) Type ( ) string {
return "rootcas"
2016-01-29 19:34:17 +00:00
}
// EntryPoints holds entry points configuration of the reverse proxy (ip, port, TLS...)
type EntryPoints map [ string ] * EntryPoint
// String is the method to format the flag's value, part of the flag.Value interface.
// The String method's output will be used in diagnostics.
func ( ep * EntryPoints ) String ( ) string {
2016-05-25 15:06:34 +00:00
return fmt . Sprintf ( "%+v" , * ep )
2016-01-29 19:34:17 +00:00
}
// Set is the method to set the flag value, part of the flag.Value interface.
// Set's argument is a string to be parsed to set the flag.
// It's a comma-separated list, so we split it.
func ( ep * EntryPoints ) Set ( value string ) error {
2017-08-18 00:18:02 +00:00
regex := regexp . MustCompile ( ` (?:Name:(?P<Name>\S*))\s*(?:Address:(?P<Address>\S*))?\s*(?:TLS:(?P<TLS>\S*))?\s*((?P<TLSACME>TLS))?\s*(?:CA:(?P<CA>\S*))?\s*(?:Redirect.EntryPoint:(?P<RedirectEntryPoint>\S*))?\s*(?:Redirect.Regex:(?P<RedirectRegex>\\S*))?\s*(?:Redirect.Replacement:(?P<RedirectReplacement>\S*))?\s*(?:Compress:(?P<Compress>\S*))?\s*(?:WhiteListSourceRange:(?P<WhiteListSourceRange>\S*))? ` )
2016-01-29 19:34:17 +00:00
match := regex . FindAllStringSubmatch ( value , - 1 )
if match == nil {
2017-05-26 15:03:14 +00:00
return fmt . Errorf ( "bad EntryPoints format: %s" , value )
2016-01-29 19:34:17 +00:00
}
matchResult := match [ 0 ]
result := make ( map [ string ] string )
for i , name := range regex . SubexpNames ( ) {
if i != 0 {
result [ name ] = matchResult [ i ]
}
}
var tls * TLS
if len ( result [ "TLS" ] ) > 0 {
certs := Certificates { }
2016-03-22 00:32:02 +00:00
if err := certs . Set ( result [ "TLS" ] ) ; err != nil {
return err
}
2016-01-29 19:34:17 +00:00
tls = & TLS {
Certificates : certs ,
}
2016-07-05 08:54:58 +00:00
} else if len ( result [ "TLSACME" ] ) > 0 {
tls = & TLS {
Certificates : Certificates { } ,
}
2016-01-29 19:34:17 +00:00
}
2016-06-15 20:38:40 +00:00
if len ( result [ "CA" ] ) > 0 {
files := strings . Split ( result [ "CA" ] , "," )
tls . ClientCAFiles = files
}
2016-01-29 19:34:17 +00:00
var redirect * Redirect
if len ( result [ "RedirectEntryPoint" ] ) > 0 || len ( result [ "RedirectRegex" ] ) > 0 || len ( result [ "RedirectReplacement" ] ) > 0 {
redirect = & Redirect {
EntryPoint : result [ "RedirectEntryPoint" ] ,
Regex : result [ "RedirectRegex" ] ,
Replacement : result [ "RedirectReplacement" ] ,
}
}
2016-09-28 21:07:06 +00:00
compress := false
if len ( result [ "Compress" ] ) > 0 {
compress = strings . EqualFold ( result [ "Compress" ] , "enable" ) || strings . EqualFold ( result [ "Compress" ] , "on" )
}
2017-07-08 10:21:14 +00:00
whiteListSourceRange := [ ] string { }
if len ( result [ "WhiteListSourceRange" ] ) > 0 {
whiteListSourceRange = strings . Split ( result [ "WhiteListSourceRange" ] , "," )
}
2016-01-29 19:34:17 +00:00
( * ep ) [ result [ "Name" ] ] = & EntryPoint {
2017-07-08 10:21:14 +00:00
Address : result [ "Address" ] ,
TLS : tls ,
Redirect : redirect ,
Compress : compress ,
WhitelistSourceRange : whiteListSourceRange ,
2016-01-29 19:34:17 +00:00
}
return nil
}
2016-05-03 14:52:14 +00:00
// Get return the EntryPoints map
2016-08-16 17:13:18 +00:00
func ( ep * EntryPoints ) Get ( ) interface { } {
return EntryPoints ( * ep )
}
2016-05-03 14:52:14 +00:00
// SetValue sets the EntryPoints map with val
func ( ep * EntryPoints ) SetValue ( val interface { } ) {
* ep = EntryPoints ( val . ( EntryPoints ) )
}
2016-01-29 19:34:17 +00:00
// Type is type of the struct
func ( ep * EntryPoints ) Type ( ) string {
2017-06-23 13:15:07 +00:00
return "entrypoints"
2016-05-31 07:54:42 +00:00
}
2016-01-29 19:34:17 +00:00
// EntryPoint holds an entry point configuration of the reverse proxy (ip, port, TLS...)
type EntryPoint struct {
2017-07-08 10:21:14 +00:00
Network string
Address string
TLS * TLS
Redirect * Redirect
Auth * types . Auth
WhitelistSourceRange [ ] string
Compress bool
2016-01-29 19:34:17 +00:00
}
// Redirect configures a redirection of an entry point to another, or to an URL
type Redirect struct {
EntryPoint string
Regex string
Replacement string
}
// TLS configures TLS for an entry point
type TLS struct {
2016-09-20 06:06:06 +00:00
MinVersion string
CipherSuites [ ] string
2016-06-15 20:38:40 +00:00
Certificates Certificates
ClientCAFiles [ ] string
2016-01-29 19:34:17 +00:00
}
2016-09-20 06:06:06 +00:00
// Map of allowed TLS minimum versions
var minVersion = map [ string ] uint16 {
` VersionTLS10 ` : tls . VersionTLS10 ,
` VersionTLS11 ` : tls . VersionTLS11 ,
` VersionTLS12 ` : tls . VersionTLS12 ,
}
// Map of TLS CipherSuites from crypto/tls
2017-03-13 05:18:00 +00:00
// Available CipherSuites defined at https://golang.org/pkg/crypto/tls/#pkg-constants
2016-09-20 06:06:06 +00:00
var cipherSuites = map [ string ] uint16 {
2017-03-13 05:18:00 +00:00
` TLS_RSA_WITH_RC4_128_SHA ` : tls . TLS_RSA_WITH_RC4_128_SHA ,
` TLS_RSA_WITH_3DES_EDE_CBC_SHA ` : tls . TLS_RSA_WITH_3DES_EDE_CBC_SHA ,
` TLS_RSA_WITH_AES_128_CBC_SHA ` : tls . TLS_RSA_WITH_AES_128_CBC_SHA ,
` TLS_RSA_WITH_AES_256_CBC_SHA ` : tls . TLS_RSA_WITH_AES_256_CBC_SHA ,
` TLS_RSA_WITH_AES_128_CBC_SHA256 ` : tls . TLS_RSA_WITH_AES_128_CBC_SHA256 ,
` TLS_RSA_WITH_AES_128_GCM_SHA256 ` : tls . TLS_RSA_WITH_AES_128_GCM_SHA256 ,
` TLS_RSA_WITH_AES_256_GCM_SHA384 ` : tls . TLS_RSA_WITH_AES_256_GCM_SHA384 ,
` TLS_ECDHE_ECDSA_WITH_RC4_128_SHA ` : tls . TLS_ECDHE_ECDSA_WITH_RC4_128_SHA ,
` TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA ` : tls . TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA ,
` TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA ` : tls . TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA ,
` TLS_ECDHE_RSA_WITH_RC4_128_SHA ` : tls . TLS_ECDHE_RSA_WITH_RC4_128_SHA ,
` TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA ` : tls . TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA ,
` TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA ` : tls . TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA ,
` TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA ` : tls . TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA ,
` TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 ` : tls . TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 ,
` TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ` : tls . TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ,
` TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ` : tls . TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ,
` TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 ` : tls . TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 ,
` TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ` : tls . TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ,
` TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 ` : tls . TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 ,
` TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305 ` : tls . TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305 ,
` TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 ` : tls . TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 ,
2016-09-20 06:06:06 +00:00
}
2016-01-13 21:46:44 +00:00
// Certificates defines traefik certificates type
2016-07-13 15:18:55 +00:00
// Certs and Keys could be either a file path, or the file content itself
2016-01-13 21:46:44 +00:00
type Certificates [ ] Certificate
2016-06-27 10:19:14 +00:00
//CreateTLSConfig creates a TLS config from Certificate structures
func ( certs * Certificates ) CreateTLSConfig ( ) ( * tls . Config , error ) {
config := & tls . Config { }
config . Certificates = [ ] tls . Certificate { }
certsSlice := [ ] Certificate ( * certs )
for _ , v := range certsSlice {
cert := tls . Certificate { }
2017-06-23 13:15:07 +00:00
2016-06-27 10:19:14 +00:00
var err error
2017-06-23 13:15:07 +00:00
certContent , err := v . CertFile . Read ( )
if err != nil {
return nil , err
2016-06-27 10:19:14 +00:00
}
2017-06-23 13:15:07 +00:00
keyContent , err := v . KeyFile . Read ( )
if err != nil {
return nil , err
}
cert , err = tls . X509KeyPair ( certContent , keyContent )
if err != nil {
return nil , err
}
2016-06-27 10:19:14 +00:00
config . Certificates = append ( config . Certificates , cert )
}
return config , nil
}
2016-01-13 21:46:44 +00:00
// String is the method to format the flag's value, part of the flag.Value interface.
// The String method's output will be used in diagnostics.
func ( certs * Certificates ) String ( ) string {
if len ( * certs ) == 0 {
return ""
}
2016-10-21 11:41:11 +00:00
var result [ ] string
for _ , certificate := range * certs {
2017-06-23 13:15:07 +00:00
result = append ( result , certificate . CertFile . String ( ) + "," + certificate . KeyFile . String ( ) )
2016-10-21 11:41:11 +00:00
}
return strings . Join ( result , ";" )
2016-01-13 21:46:44 +00:00
}
// Set is the method to set the flag value, part of the flag.Value interface.
// Set's argument is a string to be parsed to set the flag.
// It's a comma-separated list, so we split it.
func ( certs * Certificates ) Set ( value string ) error {
2016-10-21 11:41:11 +00:00
certificates := strings . Split ( value , ";" )
for _ , certificate := range certificates {
files := strings . Split ( certificate , "," )
if len ( files ) != 2 {
2017-05-26 15:03:14 +00:00
return fmt . Errorf ( "bad certificates format: %s" , value )
2016-10-21 11:41:11 +00:00
}
* certs = append ( * certs , Certificate {
2017-06-23 13:15:07 +00:00
CertFile : FileOrContent ( files [ 0 ] ) ,
KeyFile : FileOrContent ( files [ 1 ] ) ,
2016-10-21 11:41:11 +00:00
} )
2016-01-13 21:46:44 +00:00
}
return nil
}
// Type is type of the struct
func ( certs * Certificates ) Type ( ) string {
2017-06-23 13:15:07 +00:00
return "certificates"
2016-01-13 21:46:44 +00:00
}
2015-11-21 01:59:49 +00:00
// Certificate holds a SSL cert/key pair
2016-07-13 15:18:55 +00:00
// Certs and Key could be either a file path, or the file content itself
2015-11-21 01:59:49 +00:00
type Certificate struct {
2017-06-23 13:15:07 +00:00
CertFile FileOrContent
KeyFile FileOrContent
2015-11-21 01:59:49 +00:00
}
2016-03-29 20:25:32 +00:00
// Retry contains request retry config
type Retry struct {
2016-06-15 17:07:33 +00:00
Attempts int ` description:"Number of attempts" `
2016-03-29 20:25:32 +00:00
}
2017-03-24 08:36:33 +00:00
// HealthCheckConfig contains health check configuration parameters.
type HealthCheckConfig struct {
Interval flaeg . Duration ` description:"Default periodicity of enabled health checks" `
}
2017-08-18 13:34:04 +00:00
// RespondingTimeouts contains timeout configurations for incoming requests to the Traefik instance.
type RespondingTimeouts struct {
ReadTimeout flaeg . Duration ` description:"ReadTimeout is the maximum duration for reading the entire request, including the body. If zero, no timeout is set" `
WriteTimeout flaeg . Duration ` description:"WriteTimeout is the maximum duration before timing out writes of the response. If zero, no timeout is set" `
IdleTimeout flaeg . 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" `
}
// ForwardingTimeouts contains timeout configurations for forwarding requests to the backend servers.
type ForwardingTimeouts struct {
DialTimeout flaeg . 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" `
ResponseHeaderTimeout flaeg . 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" `
}
2016-05-25 15:06:34 +00:00
// NewTraefikDefaultPointersConfiguration creates a TraefikConfiguration with pointers default values
func NewTraefikDefaultPointersConfiguration ( ) * TraefikConfiguration {
2016-05-03 14:52:14 +00:00
//default Docker
2017-04-15 13:49:53 +00:00
var defaultDocker docker . Provider
2016-05-03 14:52:14 +00:00
defaultDocker . Watch = true
2016-07-14 09:32:15 +00:00
defaultDocker . ExposedByDefault = true
2016-05-03 14:52:14 +00:00
defaultDocker . Endpoint = "unix:///var/run/docker.sock"
2016-08-05 14:02:46 +00:00
defaultDocker . SwarmMode = false
2016-05-03 14:52:14 +00:00
// default File
2017-04-17 10:50:02 +00:00
var defaultFile file . Provider
2016-05-03 14:52:14 +00:00
defaultFile . Watch = true
defaultFile . Filename = "" //needs equivalent to viper.ConfigFileUsed()
// default Web
var defaultWeb WebProvider
defaultWeb . Address = ":8080"
2016-10-21 08:36:07 +00:00
defaultWeb . Statistics = & types . Statistics {
RecentErrors : 10 ,
}
2016-05-03 14:52:14 +00:00
2017-01-12 13:34:54 +00:00
// default Metrics
defaultWeb . Metrics = & types . Metrics {
Prometheus : & types . Prometheus {
2017-01-17 17:14:13 +00:00
Buckets : types . Buckets { 0.1 , 0.3 , 1.2 , 5 } ,
2017-01-12 13:34:54 +00:00
} ,
2017-07-20 22:26:43 +00:00
Datadog : & types . Datadog {
Address : "localhost:8125" ,
PushInterval : "10s" ,
} ,
StatsD : & types . Statsd {
Address : "localhost:8125" ,
PushInterval : "10s" ,
} ,
2017-01-12 13:34:54 +00:00
}
2016-05-03 14:52:14 +00:00
// default Marathon
2017-04-17 10:50:02 +00:00
var defaultMarathon marathon . Provider
2016-05-03 14:52:14 +00:00
defaultMarathon . Watch = true
defaultMarathon . Endpoint = "http://127.0.0.1:8080"
defaultMarathon . ExposedByDefault = true
2016-11-09 18:27:04 +00:00
defaultMarathon . Constraints = types . Constraints { }
2017-04-07 08:21:47 +00:00
defaultMarathon . DialerTimeout = flaeg . Duration ( 60 * time . Second )
defaultMarathon . KeepAlive = flaeg . Duration ( 10 * time . Second )
2016-05-03 14:52:14 +00:00
// default Consul
2017-04-17 10:50:02 +00:00
var defaultConsul consul . Provider
2016-05-03 14:52:14 +00:00
defaultConsul . Watch = true
defaultConsul . Endpoint = "127.0.0.1:8500"
2016-06-09 21:44:49 +00:00
defaultConsul . Prefix = "traefik"
2016-11-09 18:27:04 +00:00
defaultConsul . Constraints = types . Constraints { }
2016-05-03 14:52:14 +00:00
2017-04-17 10:50:02 +00:00
// default CatalogProvider
var defaultConsulCatalog consul . CatalogProvider
2016-05-03 14:52:14 +00:00
defaultConsulCatalog . Endpoint = "127.0.0.1:8500"
2016-11-09 18:27:04 +00:00
defaultConsulCatalog . Constraints = types . Constraints { }
2017-04-24 13:09:28 +00:00
defaultConsulCatalog . Prefix = "traefik"
2017-05-08 17:46:53 +00:00
defaultConsulCatalog . FrontEndRule = "Host:{{.ServiceName}}.{{.Domain}}"
2016-05-03 14:52:14 +00:00
// default Etcd
2017-04-17 10:50:02 +00:00
var defaultEtcd etcd . Provider
2016-05-03 14:52:14 +00:00
defaultEtcd . Watch = true
2016-07-11 11:36:35 +00:00
defaultEtcd . Endpoint = "127.0.0.1:2379"
2016-05-03 14:52:14 +00:00
defaultEtcd . Prefix = "/traefik"
2016-11-09 18:27:04 +00:00
defaultEtcd . Constraints = types . Constraints { }
2016-05-03 14:52:14 +00:00
//default Zookeeper
2017-04-17 10:50:02 +00:00
var defaultZookeeper zk . Provider
2016-05-03 14:52:14 +00:00
defaultZookeeper . Watch = true
defaultZookeeper . Endpoint = "127.0.0.1:2181"
defaultZookeeper . Prefix = "/traefik"
2016-11-09 18:27:04 +00:00
defaultZookeeper . Constraints = types . Constraints { }
2016-05-03 14:52:14 +00:00
//default Boltdb
2017-04-17 10:50:02 +00:00
var defaultBoltDb boltdb . Provider
2016-05-03 14:52:14 +00:00
defaultBoltDb . Watch = true
defaultBoltDb . Endpoint = "127.0.0.1:4001"
defaultBoltDb . Prefix = "/traefik"
2016-11-09 18:27:04 +00:00
defaultBoltDb . Constraints = types . Constraints { }
2016-05-03 14:52:14 +00:00
2017-06-01 20:10:19 +00:00
//default Kubernetes
2017-04-17 10:50:02 +00:00
var defaultKubernetes kubernetes . Provider
2016-05-03 14:52:14 +00:00
defaultKubernetes . Watch = true
2016-07-11 19:39:20 +00:00
defaultKubernetes . Endpoint = ""
2016-07-12 05:25:01 +00:00
defaultKubernetes . LabelSelector = ""
2016-11-09 18:27:04 +00:00
defaultKubernetes . Constraints = types . Constraints { }
2016-05-03 14:52:14 +00:00
2016-07-20 09:56:14 +00:00
// default Mesos
2017-04-17 10:50:02 +00:00
var defaultMesos mesos . Provider
2016-07-20 09:56:14 +00:00
defaultMesos . Watch = true
defaultMesos . Endpoint = "http://127.0.0.1:5050"
defaultMesos . ExposedByDefault = true
2016-11-09 18:27:04 +00:00
defaultMesos . Constraints = types . Constraints { }
2017-03-14 14:57:49 +00:00
defaultMesos . RefreshSeconds = 30
defaultMesos . ZkDetectionTimeout = 30
defaultMesos . StateTimeoutSecond = 30
2016-07-20 09:56:14 +00:00
2017-01-05 14:24:17 +00:00
//default ECS
2017-04-17 10:50:02 +00:00
var defaultECS ecs . Provider
2017-01-05 14:24:17 +00:00
defaultECS . Watch = true
defaultECS . ExposedByDefault = true
2017-08-22 09:46:03 +00:00
defaultECS . AutoDiscoverClusters = false
defaultECS . Clusters = ecs . Clusters { "default" }
2017-01-05 14:24:17 +00:00
defaultECS . RefreshSeconds = 15
defaultECS . Constraints = types . Constraints { }
2017-02-06 15:30:21 +00:00
//default Rancher
2017-04-17 10:50:02 +00:00
var defaultRancher rancher . Provider
2017-02-06 15:30:21 +00:00
defaultRancher . Watch = true
defaultRancher . ExposedByDefault = true
2017-04-29 19:37:54 +00:00
defaultRancher . RefreshSeconds = 15
2017-02-06 15:30:21 +00:00
2017-03-09 01:53:34 +00:00
// default DynamoDB
2017-04-17 10:50:02 +00:00
var defaultDynamoDB dynamodb . Provider
2017-03-09 01:53:34 +00:00
defaultDynamoDB . Constraints = types . Constraints { }
defaultDynamoDB . RefreshSeconds = 15
defaultDynamoDB . TableName = "traefik"
defaultDynamoDB . Watch = true
2017-05-25 11:25:53 +00:00
// default AccessLog
defaultAccessLog := types . AccessLog {
Format : accesslog . CommonFormat ,
FilePath : "" ,
}
2016-05-03 14:52:14 +00:00
defaultConfiguration := GlobalConfiguration {
Docker : & defaultDocker ,
File : & defaultFile ,
Web : & defaultWeb ,
Marathon : & defaultMarathon ,
Consul : & defaultConsul ,
ConsulCatalog : & defaultConsulCatalog ,
Etcd : & defaultEtcd ,
Zookeeper : & defaultZookeeper ,
Boltdb : & defaultBoltDb ,
Kubernetes : & defaultKubernetes ,
2016-07-20 09:56:14 +00:00
Mesos : & defaultMesos ,
2017-01-05 14:24:17 +00:00
ECS : & defaultECS ,
2017-02-06 15:30:21 +00:00
Rancher : & defaultRancher ,
2017-03-09 01:53:34 +00:00
DynamoDB : & defaultDynamoDB ,
2016-06-15 17:07:33 +00:00
Retry : & Retry { } ,
2017-03-24 08:36:33 +00:00
HealthCheck : & HealthCheckConfig { } ,
2017-05-25 11:25:53 +00:00
AccessLog : & defaultAccessLog ,
2016-05-03 14:52:14 +00:00
}
2017-01-28 23:01:56 +00:00
2016-05-03 14:52:14 +00:00
return & TraefikConfiguration {
GlobalConfiguration : defaultConfiguration ,
2016-01-29 19:34:17 +00:00
}
2015-11-06 17:11:57 +00:00
}
2016-05-03 14:52:14 +00:00
// NewTraefikConfiguration creates a TraefikConfiguration with default values
func NewTraefikConfiguration ( ) * TraefikConfiguration {
return & TraefikConfiguration {
GlobalConfiguration : GlobalConfiguration {
2017-03-27 09:51:53 +00:00
GraceTimeOut : flaeg . Duration ( 10 * time . Second ) ,
2016-05-19 15:12:36 +00:00
AccessLogsFile : "" ,
TraefikLogsFile : "" ,
2016-05-03 14:52:14 +00:00
LogLevel : "ERROR" ,
2016-05-24 12:58:25 +00:00
EntryPoints : map [ string ] * EntryPoint { } ,
2016-11-09 18:27:04 +00:00
Constraints : types . Constraints { } ,
2016-05-24 12:58:25 +00:00
DefaultEntryPoints : [ ] string { } ,
2017-03-27 09:51:53 +00:00
ProvidersThrottleDuration : flaeg . Duration ( 2 * time . Second ) ,
2016-05-03 14:52:14 +00:00
MaxIdleConnsPerHost : 200 ,
2017-08-18 13:34:04 +00:00
IdleTimeout : flaeg . Duration ( 0 ) ,
2017-03-24 08:36:33 +00:00
HealthCheck : & HealthCheckConfig {
Interval : flaeg . Duration ( DefaultHealthCheckInterval ) ,
} ,
2017-08-18 13:34:04 +00:00
RespondingTimeouts : & RespondingTimeouts {
IdleTimeout : flaeg . Duration ( DefaultIdleTimeout ) ,
} ,
ForwardingTimeouts : & ForwardingTimeouts {
DialTimeout : flaeg . Duration ( DefaultDialTimeout ) ,
} ,
2017-03-24 08:36:33 +00:00
CheckNewVersion : true ,
2016-05-03 14:52:14 +00:00
} ,
ConfigFile : "" ,
2016-01-13 21:46:44 +00:00
}
}
2015-11-01 15:35:01 +00:00
type configs map [ string ] * types . Configuration