2018-11-27 16:42:04 +00:00
|
|
|
package configuration
|
2018-11-14 09:18:03 +00:00
|
|
|
|
|
|
|
import (
|
2018-11-27 16:42:04 +00:00
|
|
|
"github.com/containous/traefik/config/static"
|
|
|
|
"github.com/containous/traefik/old/api"
|
|
|
|
"github.com/containous/traefik/old/middlewares/tracing"
|
|
|
|
"github.com/containous/traefik/old/types"
|
2018-11-14 09:18:03 +00:00
|
|
|
"github.com/containous/traefik/ping"
|
|
|
|
"github.com/containous/traefik/tracing/datadog"
|
|
|
|
"github.com/containous/traefik/tracing/jaeger"
|
|
|
|
"github.com/containous/traefik/tracing/zipkin"
|
2018-11-27 16:42:04 +00:00
|
|
|
types2 "github.com/containous/traefik/types"
|
2018-11-14 09:18:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ConvertStaticConf FIXME sugar
|
|
|
|
// Deprecated
|
2018-11-27 16:42:04 +00:00
|
|
|
func ConvertStaticConf(globalConfiguration GlobalConfiguration) static.Configuration {
|
|
|
|
staticConfiguration := static.Configuration{}
|
2018-11-14 09:18:03 +00:00
|
|
|
|
2018-11-27 16:42:04 +00:00
|
|
|
staticConfiguration.EntryPoints = make(static.EntryPoints)
|
2018-11-14 09:18:03 +00:00
|
|
|
|
|
|
|
if globalConfiguration.EntryPoints != nil {
|
|
|
|
for name, ep := range globalConfiguration.EntryPoints {
|
2018-11-27 16:42:04 +00:00
|
|
|
staticConfiguration.EntryPoints[name] = &static.EntryPoint{
|
2018-11-14 09:18:03 +00:00
|
|
|
Address: ep.Address,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if globalConfiguration.Ping != nil {
|
|
|
|
old := globalConfiguration.Ping
|
|
|
|
staticConfiguration.Ping = &ping.Handler{
|
|
|
|
EntryPoint: old.EntryPoint,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
staticConfiguration.API = convertAPI(globalConfiguration.API)
|
|
|
|
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
|
2018-11-27 16:42:04 +00:00
|
|
|
func ConvertAccessLog(old *types.AccessLog) *types2.AccessLog {
|
2018-11-14 09:18:03 +00:00
|
|
|
if old == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-11-27 16:42:04 +00:00
|
|
|
accessLog := &types2.AccessLog{
|
2018-11-14 09:18:03 +00:00
|
|
|
FilePath: old.FilePath,
|
|
|
|
Format: old.Format,
|
|
|
|
BufferingSize: old.BufferingSize,
|
|
|
|
}
|
|
|
|
|
|
|
|
if old.Filters != nil {
|
2018-11-27 16:42:04 +00:00
|
|
|
accessLog.Filters = &types2.AccessLogFilters{
|
|
|
|
StatusCodes: types2.StatusCodes(old.Filters.StatusCodes),
|
2018-11-14 09:18:03 +00:00
|
|
|
RetryAttempts: old.Filters.RetryAttempts,
|
|
|
|
MinDuration: old.Filters.MinDuration,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if old.Fields != nil {
|
2018-11-27 16:42:04 +00:00
|
|
|
accessLog.Fields = &types2.AccessLogFields{
|
2018-11-14 09:18:03 +00:00
|
|
|
DefaultMode: old.Fields.DefaultMode,
|
2018-11-27 16:42:04 +00:00
|
|
|
Names: types2.FieldNames(old.Fields.Names),
|
2018-11-14 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if old.Fields.Headers != nil {
|
2018-11-27 16:42:04 +00:00
|
|
|
accessLog.Fields.Headers = &types2.FieldHeaders{
|
2018-11-14 09:18:03 +00:00
|
|
|
DefaultMode: old.Fields.Headers.DefaultMode,
|
2018-11-27 16:42:04 +00:00
|
|
|
Names: types2.FieldHeaderNames(old.Fields.Headers.Names),
|
2018-11-14 09:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return accessLog
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConvertMetrics FIXME sugar
|
|
|
|
// Deprecated
|
2018-11-27 16:42:04 +00:00
|
|
|
func ConvertMetrics(old *types.Metrics) *types2.Metrics {
|
2018-11-14 09:18:03 +00:00
|
|
|
if old == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-11-27 16:42:04 +00:00
|
|
|
metrics := &types2.Metrics{}
|
2018-11-14 09:18:03 +00:00
|
|
|
|
|
|
|
if old.Prometheus != nil {
|
2018-11-27 16:42:04 +00:00
|
|
|
metrics.Prometheus = &types2.Prometheus{
|
2018-11-14 09:18:03 +00:00
|
|
|
EntryPoint: old.Prometheus.EntryPoint,
|
2018-11-27 16:42:04 +00:00
|
|
|
Buckets: types2.Buckets(old.Prometheus.Buckets),
|
2018-11-14 09:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if old.Datadog != nil {
|
2018-11-27 16:42:04 +00:00
|
|
|
metrics.Datadog = &types2.Datadog{
|
2018-11-14 09:18:03 +00:00
|
|
|
Address: old.Datadog.Address,
|
|
|
|
PushInterval: old.Datadog.PushInterval,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if old.StatsD != nil {
|
2018-11-27 16:42:04 +00:00
|
|
|
metrics.StatsD = &types2.Statsd{
|
2018-11-14 09:18:03 +00:00
|
|
|
Address: old.StatsD.Address,
|
|
|
|
PushInterval: old.StatsD.PushInterval,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if old.InfluxDB != nil {
|
2018-11-27 16:42:04 +00:00
|
|
|
metrics.InfluxDB = &types2.InfluxDB{
|
2018-11-14 09:18:03 +00:00
|
|
|
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
|
2018-11-27 16:42:04 +00:00
|
|
|
func ConvertTracing(old *tracing.Tracing) *static.Tracing {
|
2018-11-14 09:18:03 +00:00
|
|
|
if old == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-11-27 16:42:04 +00:00
|
|
|
tra := &static.Tracing{
|
2018-11-14 09:18:03 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-11-27 16:42:04 +00:00
|
|
|
func convertAPI(old *api.Handler) *static.API {
|
2018-11-14 09:18:03 +00:00
|
|
|
if old == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-11-27 16:42:04 +00:00
|
|
|
api := &static.API{
|
2018-11-14 09:18:03 +00:00
|
|
|
EntryPoint: old.EntryPoint,
|
|
|
|
Dashboard: old.Dashboard,
|
|
|
|
DashboardAssets: old.DashboardAssets,
|
|
|
|
}
|
|
|
|
|
|
|
|
if old.Statistics != nil {
|
2018-11-27 16:42:04 +00:00
|
|
|
api.Statistics = &types2.Statistics{
|
2018-11-14 09:18:03 +00:00
|
|
|
RecentErrors: old.Statistics.RecentErrors,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return api
|
|
|
|
}
|
|
|
|
|
2018-11-27 16:42:04 +00:00
|
|
|
func convertConstraints(oldConstraints types.Constraints) types2.Constraints {
|
|
|
|
constraints := types2.Constraints{}
|
2018-11-14 09:18:03 +00:00
|
|
|
for _, value := range oldConstraints {
|
2018-11-27 16:42:04 +00:00
|
|
|
constraint := &types2.Constraint{
|
2018-11-14 09:18:03 +00:00
|
|
|
Key: value.Key,
|
|
|
|
MustMatch: value.MustMatch,
|
|
|
|
Regex: value.Regex,
|
|
|
|
}
|
|
|
|
|
|
|
|
constraints = append(constraints, constraint)
|
|
|
|
}
|
|
|
|
return constraints
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConvertHostResolverConfig FIXME
|
|
|
|
// Deprecated
|
2019-01-30 15:24:07 +00:00
|
|
|
func ConvertHostResolverConfig(oldconfig *HostResolverConfig) *types2.HostResolverConfig {
|
2018-11-14 09:18:03 +00:00
|
|
|
if oldconfig == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-30 15:24:07 +00:00
|
|
|
return &types2.HostResolverConfig{
|
2018-11-14 09:18:03 +00:00
|
|
|
CnameFlattening: oldconfig.CnameFlattening,
|
|
|
|
ResolvConfig: oldconfig.ResolvConfig,
|
|
|
|
ResolvDepth: oldconfig.ResolvDepth,
|
|
|
|
}
|
|
|
|
}
|