traefik/old/configuration/convert.go

243 lines
6.1 KiB
Go
Raw Normal View History

package configuration
2018-11-14 09:18:03 +00:00
import (
"github.com/containous/traefik/config/static"
"github.com/containous/traefik/old/api"
"github.com/containous/traefik/old/middlewares/tracing"
"github.com/containous/traefik/old/provider/file"
"github.com/containous/traefik/old/types"
2018-11-14 09:18:03 +00:00
"github.com/containous/traefik/ping"
"github.com/containous/traefik/provider"
file2 "github.com/containous/traefik/provider/file"
2018-11-14 09:18:03 +00:00
"github.com/containous/traefik/tracing/datadog"
"github.com/containous/traefik/tracing/jaeger"
"github.com/containous/traefik/tracing/zipkin"
types2 "github.com/containous/traefik/types"
2018-11-14 09:18:03 +00:00
)
// ConvertStaticConf FIXME sugar
// Deprecated
func ConvertStaticConf(globalConfiguration GlobalConfiguration) static.Configuration {
staticConfiguration := static.Configuration{}
2018-11-14 09:18:03 +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 {
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.Providers.File = convertFile(globalConfiguration.File)
2018-11-14 09:18:03 +00:00
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 *types.AccessLog) *types2.AccessLog {
2018-11-14 09:18:03 +00:00
if old == nil {
return nil
}
accessLog := &types2.AccessLog{
2018-11-14 09:18:03 +00:00
FilePath: old.FilePath,
Format: old.Format,
BufferingSize: old.BufferingSize,
}
if old.Filters != nil {
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 {
accessLog.Fields = &types2.AccessLogFields{
2018-11-14 09:18:03 +00:00
DefaultMode: old.Fields.DefaultMode,
Names: types2.FieldNames(old.Fields.Names),
2018-11-14 09:18:03 +00:00
}
if old.Fields.Headers != nil {
accessLog.Fields.Headers = &types2.FieldHeaders{
2018-11-14 09:18:03 +00:00
DefaultMode: old.Fields.Headers.DefaultMode,
Names: types2.FieldHeaderNames(old.Fields.Headers.Names),
2018-11-14 09:18:03 +00:00
}
}
}
return accessLog
}
// ConvertMetrics FIXME sugar
// Deprecated
func ConvertMetrics(old *types.Metrics) *types2.Metrics {
2018-11-14 09:18:03 +00:00
if old == nil {
return nil
}
metrics := &types2.Metrics{}
2018-11-14 09:18:03 +00:00
if old.Prometheus != nil {
metrics.Prometheus = &types2.Prometheus{
2018-11-14 09:18:03 +00:00
EntryPoint: old.Prometheus.EntryPoint,
Buckets: types2.Buckets(old.Prometheus.Buckets),
2018-11-14 09:18:03 +00:00
}
}
if old.Datadog != nil {
metrics.Datadog = &types2.Datadog{
2018-11-14 09:18:03 +00:00
Address: old.Datadog.Address,
PushInterval: old.Datadog.PushInterval,
}
}
if old.StatsD != nil {
metrics.StatsD = &types2.Statsd{
2018-11-14 09:18:03 +00:00
Address: old.StatsD.Address,
PushInterval: old.StatsD.PushInterval,
}
}
if old.InfluxDB != nil {
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
func ConvertTracing(old *tracing.Tracing) *static.Tracing {
2018-11-14 09:18:03 +00:00
if old == nil {
return nil
}
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
}
func convertAPI(old *api.Handler) *static.API {
2018-11-14 09:18:03 +00:00
if old == nil {
return nil
}
api := &static.API{
2018-11-14 09:18:03 +00:00
EntryPoint: old.EntryPoint,
Dashboard: old.Dashboard,
DashboardAssets: old.DashboardAssets,
}
if old.Statistics != nil {
api.Statistics = &types2.Statistics{
2018-11-14 09:18:03 +00:00
RecentErrors: old.Statistics.RecentErrors,
}
}
return api
}
func convertConstraints(oldConstraints types.Constraints) types2.Constraints {
constraints := types2.Constraints{}
2018-11-14 09:18:03 +00:00
for _, value := range oldConstraints {
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
}
func convertFile(old *file.Provider) *file2.Provider {
2018-11-14 09:18:03 +00:00
if old == nil {
return nil
}
f := &file2.Provider{
2018-11-14 09:18:03 +00:00
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 *HostResolverConfig) *static.HostResolverConfig {
2018-11-14 09:18:03 +00:00
if oldconfig == nil {
return nil
}
return &static.HostResolverConfig{
2018-11-14 09:18:03 +00:00
CnameFlattening: oldconfig.CnameFlattening,
ResolvConfig: oldconfig.ResolvConfig,
ResolvDepth: oldconfig.ResolvDepth,
}
}