homogenization of templates: ECS
This commit is contained in:
parent
0d57e2aed9
commit
ee71b4bfef
4 changed files with 1300 additions and 425 deletions
|
@ -543,173 +543,157 @@ func templatesDockerTmpl() (*asset, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var _templatesEcsTmpl = []byte(`[backends]
|
var _templatesEcsTmpl = []byte(`[backends]
|
||||||
{{range $serviceName, $instances := .Services}}
|
{{range $serviceName, $instances := .Services }}
|
||||||
|
{{ $firstInstance := index $instances 0 }}
|
||||||
|
|
||||||
{{if hasCircuitBreakerLabel $instances}}
|
{{ $circuitBreaker := getCircuitBreaker $firstInstance }}
|
||||||
[backends.backend-{{ $serviceName }}.circuitBreaker]
|
{{if $circuitBreaker }}
|
||||||
expression = "{{getCircuitBreakerExpression $instances}}"
|
[backends."backend-{{ $serviceName }}".circuitBreaker]
|
||||||
|
expression = "{{ $circuitBreaker.Expression }}"
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if hasLoadBalancerLabel $instances}}
|
{{ $loadBalancer := getLoadBalancer $firstInstance }}
|
||||||
[backends.backend-{{ $serviceName }}.loadBalancer]
|
{{if $loadBalancer }}
|
||||||
method = "{{ getLoadBalancerMethod $instances}}"
|
[backends."backend-{{ $serviceName }}".loadBalancer]
|
||||||
sticky = {{ getSticky $instances}}
|
method = "{{ $loadBalancer.Method }}"
|
||||||
{{if hasStickinessLabel $instances}}
|
sticky = {{ $loadBalancer.Sticky }}
|
||||||
[backends.backend-{{ $serviceName }}.loadBalancer.stickiness]
|
{{if $loadBalancer.Stickiness }}
|
||||||
cookieName = "{{getStickinessCookieName $instances}}"
|
[backends."backend-{{ $serviceName }}".loadBalancer.stickiness]
|
||||||
|
cookieName = "{{ $loadBalancer.Stickiness.CookieName }}"
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if hasMaxConnLabels $instances}}
|
{{ $maxConn := getMaxConn $firstInstance }}
|
||||||
[backends.backend-{{ $serviceName }}.maxConn]
|
{{if $maxConn }}
|
||||||
amount = {{getMaxConnAmount $instances}}
|
[backends."backend-{{ $serviceName }}".maxConn]
|
||||||
extractorFunc = "{{getMaxConnExtractorFunc $instances}}"
|
extractorFunc = "{{ $maxConn.ExtractorFunc }}"
|
||||||
|
amount = {{ $maxConn.Amount }}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{ if hasHealthCheckLabels $instances }}
|
{{ $healthCheck := getHealthCheck $firstInstance }}
|
||||||
|
{{if $healthCheck }}
|
||||||
[backends.backend-{{ $serviceName }}.healthCheck]
|
[backends.backend-{{ $serviceName }}.healthCheck]
|
||||||
path = "{{getHealthCheckPath $instances }}"
|
path = "{{ $healthCheck.Path }}"
|
||||||
port = {{getHealthCheckPort $instances}}
|
port = {{ $healthCheck.Port }}
|
||||||
interval = "{{getHealthCheckInterval $instances }}"
|
interval = "{{ $healthCheck.Interval }}"
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{range $index, $instance := $instances}}
|
{{range $serverName, $server := getServers $instances }}
|
||||||
[backends.backend-{{ $instance.Name }}.servers.server-{{ $instance.Name }}{{ $instance.ID }}]
|
[backends.backend-{{ $serviceName }}.servers.{{ $serverName }}]
|
||||||
url = "{{ getProtocol $instance }}://{{ getHost $instance }}:{{ getPort $instance }}"
|
url = "{{ $server.URL }}"
|
||||||
weight = {{ getWeight $instance}}
|
weight = {{ $server.Weight }}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
[frontends]
|
[frontends]
|
||||||
{{range $serviceName, $instances := .Services}}
|
{{range $serviceName, $instances := .Services }}
|
||||||
{{range $instance := filterFrontends $instances}}
|
{{range $instance := filterFrontends $instances }}
|
||||||
|
|
||||||
[frontends.frontend-{{ $serviceName }}]
|
[frontends.frontend-{{ $serviceName }}]
|
||||||
backend = "backend-{{ $serviceName }}"
|
backend = "backend-{{ $serviceName }}"
|
||||||
priority = {{ getPriority $instance}}
|
priority = {{ getPriority $instance }}
|
||||||
passHostHeader = {{ getPassHostHeader $instance}}
|
passHostHeader = {{ getPassHostHeader $instance }}
|
||||||
passTLSCert = {{ getPassTLSCert $instance}}
|
passTLSCert = {{ getPassTLSCert $instance }}
|
||||||
|
|
||||||
entryPoints = [{{range getEntryPoints $instance}}
|
entryPoints = [{{range getEntryPoints $instance }}
|
||||||
"{{.}}",
|
"{{.}}",
|
||||||
{{end}}]
|
{{end}}]
|
||||||
|
|
||||||
{{if getWhitelistSourceRange $instance}}
|
{{ $whitelistSourceRange := getWhitelistSourceRange $instance }}
|
||||||
whitelistSourceRange = [{{range getWhitelistSourceRange $instance}}
|
{{if $whitelistSourceRange }}
|
||||||
|
whitelistSourceRange = [{{range $whitelistSourceRange }}
|
||||||
"{{.}}",
|
"{{.}}",
|
||||||
{{end}}]
|
{{end}}]
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
basicAuth = [{{range getBasicAuth $instance}}
|
basicAuth = [{{range getBasicAuth $instance }}
|
||||||
"{{.}}",
|
"{{.}}",
|
||||||
{{end}}]
|
{{end}}]
|
||||||
|
|
||||||
{{if hasRedirect $instance}}
|
|
||||||
|
{{ $redirect := getRedirect $instance }}
|
||||||
|
{{if $redirect }}
|
||||||
[frontends."frontend-{{ $serviceName }}".redirect]
|
[frontends."frontend-{{ $serviceName }}".redirect]
|
||||||
entryPoint = "{{getRedirectEntryPoint $instance}}"
|
entryPoint = "{{ $redirect.EntryPoint }}"
|
||||||
regex = "{{getRedirectRegex $instance}}"
|
regex = "{{ $redirect.Regex }}"
|
||||||
replacement = "{{getRedirectReplacement $instance}}"
|
replacement = "{{ $redirect.Replacement }}"
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{ if hasErrorPages $instance }}
|
{{ $errorPages := getErrorPages $instance }}
|
||||||
|
{{if $errorPages }}
|
||||||
[frontends."frontend-{{ $serviceName }}".errors]
|
[frontends."frontend-{{ $serviceName }}".errors]
|
||||||
{{ range $pageName, $page := getErrorPages $instance }}
|
{{range $pageName, $page := $errorPages }}
|
||||||
[frontends."frontend-{{ $serviceName }}".errors.{{ $pageName }}]
|
[frontends."frontend-{{ $serviceName }}".errors.{{ $pageName }}]
|
||||||
status = [{{range $page.Status}}
|
status = [{{range $page.Status }}
|
||||||
"{{.}}",
|
"{{.}}",
|
||||||
{{end}}]
|
{{end}}]
|
||||||
backend = "{{$page.Backend}}"
|
backend = "{{ $page.Backend }}"
|
||||||
query = "{{$page.Query}}"
|
query = "{{ $page.Query }}"
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{ if hasRateLimits $instance }}
|
{{ $rateLimit := getRateLimit $instance }}
|
||||||
|
{{if $rateLimit }}
|
||||||
[frontends."frontend-{{ $serviceName }}".rateLimit]
|
[frontends."frontend-{{ $serviceName }}".rateLimit]
|
||||||
extractorFunc = "{{ getRateLimitsExtractorFunc $instance }}"
|
extractorFunc = "{{ $rateLimit.ExtractorFunc }}"
|
||||||
[frontends."frontend-{{ $serviceName }}".rateLimit.rateSet]
|
[frontends."frontend-{{ $serviceName }}".rateLimit.rateSet]
|
||||||
{{ range $limitName, $rateLimit := getRateLimits $instance }}
|
{{ range $limitName, $limit := $rateLimit.RateSet }}
|
||||||
[frontends."frontend-{{ $serviceName }}".rateLimit.rateSet.{{ $limitName }}]
|
[frontends."frontend-{{ $serviceName }}".rateLimit.rateSet.{{ $limitName }}]
|
||||||
period = "{{ $rateLimit.Period }}"
|
period = "{{ $limit.Period }}"
|
||||||
average = {{ $rateLimit.Average }}
|
average = {{ $limit.Average }}
|
||||||
burst = {{ $rateLimit.Burst }}
|
burst = {{ $limit.Burst }}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if hasHeaders $instance }}
|
{{ $headers := getHeaders $instance }}
|
||||||
|
{{if $headers }}
|
||||||
[frontends."frontend-{{ $serviceName }}".headers]
|
[frontends."frontend-{{ $serviceName }}".headers]
|
||||||
{{if hasSSLRedirectHeaders $instance}}
|
SSLRedirect = {{ $headers.SSLRedirect }}
|
||||||
SSLRedirect = {{getSSLRedirectHeaders $instance}}
|
SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }}
|
||||||
|
SSLHost = "{{ $headers.SSLHost }}"
|
||||||
|
STSSeconds = {{ $headers.STSSeconds }}
|
||||||
|
STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }}
|
||||||
|
STSPreload = {{ $headers.STSPreload }}
|
||||||
|
ForceSTSHeader = {{ $headers.ForceSTSHeader }}
|
||||||
|
FrameDeny = {{ $headers.FrameDeny }}
|
||||||
|
CustomFrameOptionsValue = "{{ $headers.CustomFrameOptionsValue }}"
|
||||||
|
ContentTypeNosniff = {{ $headers.ContentTypeNosniff }}
|
||||||
|
BrowserXSSFilter = {{ $headers.BrowserXSSFilter }}
|
||||||
|
ContentSecurityPolicy = "{{ $headers.ContentSecurityPolicy }}"
|
||||||
|
PublicKey = "{{ $headers.PublicKey }}"
|
||||||
|
ReferrerPolicy = "{{ $headers.ReferrerPolicy }}"
|
||||||
|
IsDevelopment = {{ $headers.IsDevelopment }}
|
||||||
|
|
||||||
|
{{if $headers.AllowedHosts }}
|
||||||
|
AllowedHosts = [{{range $headers.AllowedHosts }}
|
||||||
|
"{{.}}",
|
||||||
|
{{end}}]
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if hasSSLTemporaryRedirectHeaders $instance}}
|
|
||||||
SSLTemporaryRedirect = {{getSSLTemporaryRedirectHeaders $instance}}
|
{{if $headers.HostsProxyHeaders }}
|
||||||
|
HostsProxyHeaders = [{{range $headers.HostsProxyHeaders }}
|
||||||
|
"{{.}}",
|
||||||
|
{{end}}]
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if hasSSLHostHeaders $instance}}
|
|
||||||
SSLHost = "{{getSSLHostHeaders $instance}}"
|
{{if $headers.CustomRequestHeaders }}
|
||||||
{{end}}
|
[frontends."frontend-{{ $serviceName }}".headers.customRequestHeaders]
|
||||||
{{if hasSTSSecondsHeaders $instance}}
|
{{range $k, $v := $headers.CustomRequestHeaders }}
|
||||||
STSSeconds = {{getSTSSecondsHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasSTSIncludeSubdomainsHeaders $instance}}
|
|
||||||
STSIncludeSubdomains = {{getSTSIncludeSubdomainsHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasSTSPreloadHeaders $instance}}
|
|
||||||
STSPreload = {{getSTSPreloadHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasForceSTSHeaderHeaders $instance}}
|
|
||||||
ForceSTSHeader = {{getForceSTSHeaderHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasFrameDenyHeaders $instance}}
|
|
||||||
FrameDeny = {{getFrameDenyHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasCustomFrameOptionsValueHeaders $instance}}
|
|
||||||
CustomFrameOptionsValue = "{{getCustomFrameOptionsValueHeaders $instance}}"
|
|
||||||
{{end}}
|
|
||||||
{{if hasContentTypeNosniffHeaders $instance}}
|
|
||||||
ContentTypeNosniff = {{getContentTypeNosniffHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasBrowserXSSFilterHeaders $instance}}
|
|
||||||
BrowserXSSFilter = {{getBrowserXSSFilterHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasContentSecurityPolicyHeaders $instance}}
|
|
||||||
ContentSecurityPolicy = "{{getContentSecurityPolicyHeaders $instance}}"
|
|
||||||
{{end}}
|
|
||||||
{{if hasPublicKeyHeaders $instance}}
|
|
||||||
PublicKey = "{{getPublicKeyHeaders $instance}}"
|
|
||||||
{{end}}
|
|
||||||
{{if hasReferrerPolicyHeaders $instance}}
|
|
||||||
ReferrerPolicy = "{{getReferrerPolicyHeaders $instance}}"
|
|
||||||
{{end}}
|
|
||||||
{{if hasIsDevelopmentHeaders $instance}}
|
|
||||||
IsDevelopment = {{getIsDevelopmentHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasRequestHeaders $instance}}
|
|
||||||
[frontends."frontend-{{ $serviceName }}".headers.customRequestHeaders]
|
|
||||||
{{range $k, $v := getRequestHeaders $instance}}
|
|
||||||
{{$k}} = "{{$v}}"
|
{{$k}} = "{{$v}}"
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if hasResponseHeaders $instance}}
|
|
||||||
|
{{if $headers.CustomResponseHeaders }}
|
||||||
[frontends."frontend-{{ $serviceName }}".headers.customResponseHeaders]
|
[frontends."frontend-{{ $serviceName }}".headers.customResponseHeaders]
|
||||||
{{range $k, $v := getResponseHeaders $instance}}
|
{{range $k, $v := $headers.CustomResponseHeaders }}
|
||||||
{{$k}} = "{{$v}}"
|
{{$k}} = "{{$v}}"
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if hasAllowedHostsHeaders $instance}}
|
|
||||||
[frontends."frontend-{{ $serviceName }}".headers.AllowedHosts]
|
{{if $headers.SSLProxyHeaders }}
|
||||||
{{range getAllowedHostsHeaders $instance}}
|
|
||||||
"{{.}}"
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasHostsProxyHeaders $instance}}
|
|
||||||
[frontends."frontend-{{ $serviceName }}".headers.HostsProxyHeaders]
|
|
||||||
{{range getHostsProxyHeaders $instance}}
|
|
||||||
"{{.}}"
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasSSLProxyHeaders $instance}}
|
|
||||||
[frontends."frontend-{{ $serviceName }}".headers.SSLProxyHeaders]
|
[frontends."frontend-{{ $serviceName }}".headers.SSLProxyHeaders]
|
||||||
{{range $k, $v := getSSLProxyHeaders $instance}}
|
{{range $k, $v := $headers.SSLProxyHeaders }}
|
||||||
{{$k}} = "{{$v}}"
|
{{$k}} = "{{$v}}"
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
package ecs
|
package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/BurntSushi/ty/fun"
|
"github.com/BurntSushi/ty/fun"
|
||||||
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/containous/traefik/log"
|
"github.com/containous/traefik/log"
|
||||||
|
"github.com/containous/traefik/provider"
|
||||||
"github.com/containous/traefik/provider/label"
|
"github.com/containous/traefik/provider/label"
|
||||||
"github.com/containous/traefik/types"
|
"github.com/containous/traefik/types"
|
||||||
)
|
)
|
||||||
|
@ -16,90 +19,51 @@ import (
|
||||||
func (p *Provider) buildConfiguration(services map[string][]ecsInstance) (*types.Configuration, error) {
|
func (p *Provider) buildConfiguration(services map[string][]ecsInstance) (*types.Configuration, error) {
|
||||||
var ecsFuncMap = template.FuncMap{
|
var ecsFuncMap = template.FuncMap{
|
||||||
// Backend functions
|
// Backend functions
|
||||||
"getProtocol": getFuncStringValue(label.TraefikProtocol, label.DefaultProtocol),
|
"getHost": getHost,
|
||||||
"getHost": getHost,
|
"getPort": getPort,
|
||||||
"getPort": getPort,
|
"getCircuitBreaker": getCircuitBreaker,
|
||||||
"getWeight": getFuncStringValue(label.TraefikWeight, label.DefaultWeight),
|
"getLoadBalancer": getLoadBalancer,
|
||||||
"hasLoadBalancerLabel": hasLoadBalancerLabel,
|
"getMaxConn": getMaxConn,
|
||||||
"getLoadBalancerMethod": getFuncFirstStringValue(label.TraefikBackendLoadBalancerMethod, label.DefaultBackendLoadBalancerMethod),
|
"getHealthCheck": getHealthCheck,
|
||||||
"getSticky": getSticky,
|
"getServers": getServers,
|
||||||
"hasStickinessLabel": getFuncFirstBoolValue(label.TraefikBackendLoadBalancerStickiness, false),
|
|
||||||
"getStickinessCookieName": getFuncFirstStringValue(label.TraefikBackendLoadBalancerStickinessCookieName, label.DefaultBackendLoadbalancerStickinessCookieName),
|
// TODO Deprecated [breaking]
|
||||||
"hasHealthCheckLabels": hasFuncFirst(label.TraefikBackendHealthCheckPath),
|
"getProtocol": getFuncStringValue(label.TraefikProtocol, label.DefaultProtocol),
|
||||||
"getHealthCheckPath": getFuncFirstStringValue(label.TraefikBackendHealthCheckPath, ""),
|
// TODO Deprecated [breaking]
|
||||||
"getHealthCheckPort": getFuncFirstIntValue(label.TraefikBackendHealthCheckPort, label.DefaultBackendHealthCheckPort),
|
"getWeight": getFuncIntValue(label.TraefikWeight, label.DefaultWeightInt),
|
||||||
"getHealthCheckInterval": getFuncFirstStringValue(label.TraefikBackendHealthCheckInterval, ""),
|
// TODO Deprecated [breaking]
|
||||||
"hasCircuitBreakerLabel": hasFuncFirst(label.TraefikBackendCircuitBreakerExpression),
|
"getLoadBalancerMethod": getFuncFirstStringValue(label.TraefikBackendLoadBalancerMethod, label.DefaultBackendLoadBalancerMethod),
|
||||||
"getCircuitBreakerExpression": getFuncFirstStringValue(label.TraefikBackendCircuitBreakerExpression, label.DefaultCircuitBreakerExpression),
|
// TODO Deprecated [breaking]
|
||||||
"hasMaxConnLabels": hasMaxConnLabels,
|
"getSticky": getSticky,
|
||||||
"getMaxConnAmount": getFuncFirstInt64Value(label.TraefikBackendMaxConnAmount, math.MaxInt64),
|
// TODO Deprecated [breaking]
|
||||||
"getMaxConnExtractorFunc": getFuncFirstStringValue(label.TraefikBackendMaxConnExtractorFunc, label.DefaultBackendMaxconnExtractorFunc),
|
"hasStickinessLabel": getFuncFirstBoolValue(label.TraefikBackendLoadBalancerStickiness, false),
|
||||||
|
// TODO Deprecated [breaking]
|
||||||
|
"getStickinessCookieName": getFuncFirstStringValue(label.TraefikBackendLoadBalancerStickinessCookieName, label.DefaultBackendLoadbalancerStickinessCookieName),
|
||||||
|
// TODO Deprecated [breaking]
|
||||||
|
"hasHealthCheckLabels": hasFuncFirst(label.TraefikBackendHealthCheckPath),
|
||||||
|
// TODO Deprecated [breaking]
|
||||||
|
"getHealthCheckPath": getFuncFirstStringValue(label.TraefikBackendHealthCheckPath, ""),
|
||||||
|
// TODO Deprecated [breaking]
|
||||||
|
"getHealthCheckInterval": getFuncFirstStringValue(label.TraefikBackendHealthCheckInterval, ""),
|
||||||
|
|
||||||
// Frontend functions
|
// Frontend functions
|
||||||
"filterFrontends": filterFrontends,
|
"filterFrontends": filterFrontends,
|
||||||
"getFrontendRule": p.getFrontendRule,
|
"getFrontendRule": p.getFrontendRule,
|
||||||
"getPassHostHeader": getFuncStringValue(label.TraefikFrontendPassHostHeader, label.DefaultPassHostHeader),
|
"getPassHostHeader": getFuncBoolValue(label.TraefikFrontendPassHostHeader, label.DefaultPassHostHeaderBool),
|
||||||
"getPassTLSCert": getFuncBoolValue(label.TraefikFrontendPassTLSCert, label.DefaultPassTLSCert),
|
"getPassTLSCert": getFuncBoolValue(label.TraefikFrontendPassTLSCert, label.DefaultPassTLSCert),
|
||||||
"getPriority": getFuncStringValue(label.TraefikFrontendPriority, label.DefaultFrontendPriority),
|
"getPriority": getFuncIntValue(label.TraefikFrontendPriority, label.DefaultFrontendPriorityInt),
|
||||||
"getBasicAuth": getFuncSliceString(label.TraefikFrontendAuthBasic),
|
"getBasicAuth": getFuncSliceString(label.TraefikFrontendAuthBasic),
|
||||||
"getEntryPoints": getFuncSliceString(label.TraefikFrontendEntryPoints),
|
"getEntryPoints": getFuncSliceString(label.TraefikFrontendEntryPoints),
|
||||||
"getWhitelistSourceRange": getFuncSliceString(label.TraefikFrontendWhitelistSourceRange),
|
"getWhitelistSourceRange": getFuncSliceString(label.TraefikFrontendWhitelistSourceRange),
|
||||||
"hasRedirect": hasRedirect,
|
"getRedirect": getRedirect,
|
||||||
"getRedirectEntryPoint": getFuncStringValue(label.TraefikFrontendRedirectEntryPoint, label.DefaultFrontendRedirectEntryPoint),
|
"getErrorPages": getErrorPages,
|
||||||
"getRedirectRegex": getFuncStringValue(label.TraefikFrontendRedirectRegex, ""),
|
"getRateLimit": getRateLimit,
|
||||||
"getRedirectReplacement": getFuncStringValue(label.TraefikFrontendRedirectReplacement, ""),
|
"getHeaders": getHeaders,
|
||||||
"hasErrorPages": hasPrefixFuncLabel(label.Prefix + label.BaseFrontendErrorPage),
|
|
||||||
"getErrorPages": getErrorPages,
|
|
||||||
"hasRateLimits": hasFuncLabel(label.TraefikFrontendRateLimitExtractorFunc),
|
|
||||||
"getRateLimitsExtractorFunc": getFuncStringValue(label.TraefikFrontendRateLimitExtractorFunc, ""),
|
|
||||||
"getRateLimits": getRateLimits,
|
|
||||||
// Headers
|
|
||||||
"hasHeaders": hasPrefixFuncLabel(label.TraefikFrontendHeaders),
|
|
||||||
"hasRequestHeaders": hasFuncLabel(label.TraefikFrontendRequestHeaders),
|
|
||||||
"getRequestHeaders": getFuncMapValue(label.TraefikFrontendRequestHeaders),
|
|
||||||
"hasResponseHeaders": hasFuncLabel(label.TraefikFrontendResponseHeaders),
|
|
||||||
"getResponseHeaders": getFuncMapValue(label.TraefikFrontendResponseHeaders),
|
|
||||||
"hasAllowedHostsHeaders": hasFuncLabel(label.TraefikFrontendAllowedHosts),
|
|
||||||
"getAllowedHostsHeaders": getFuncSliceString(label.TraefikFrontendAllowedHosts),
|
|
||||||
"hasHostsProxyHeaders": hasFuncLabel(label.TraefikFrontendHostsProxyHeaders),
|
|
||||||
"getHostsProxyHeaders": getFuncSliceString(label.TraefikFrontendHostsProxyHeaders),
|
|
||||||
"hasSSLRedirectHeaders": hasFuncLabel(label.TraefikFrontendSSLRedirect),
|
|
||||||
"getSSLRedirectHeaders": getFuncBoolValue(label.TraefikFrontendSSLRedirect, false),
|
|
||||||
"hasSSLTemporaryRedirectHeaders": hasFuncLabel(label.TraefikFrontendSSLTemporaryRedirect),
|
|
||||||
"getSSLTemporaryRedirectHeaders": getFuncBoolValue(label.TraefikFrontendSSLTemporaryRedirect, false),
|
|
||||||
"hasSSLHostHeaders": hasFuncLabel(label.TraefikFrontendSSLHost),
|
|
||||||
"getSSLHostHeaders": getFuncStringValue(label.TraefikFrontendSSLHost, ""),
|
|
||||||
"hasSSLProxyHeaders": hasFuncLabel(label.TraefikFrontendSSLProxyHeaders),
|
|
||||||
"getSSLProxyHeaders": getFuncMapValue(label.TraefikFrontendSSLProxyHeaders),
|
|
||||||
"hasSTSSecondsHeaders": hasFuncLabel(label.TraefikFrontendSTSSeconds),
|
|
||||||
"getSTSSecondsHeaders": getFuncInt64Value(label.TraefikFrontendSTSSeconds, 0),
|
|
||||||
"hasSTSIncludeSubdomainsHeaders": hasFuncLabel(label.TraefikFrontendSTSIncludeSubdomains),
|
|
||||||
"getSTSIncludeSubdomainsHeaders": getFuncBoolValue(label.TraefikFrontendSTSIncludeSubdomains, false),
|
|
||||||
"hasSTSPreloadHeaders": hasFuncLabel(label.TraefikFrontendSTSPreload),
|
|
||||||
"getSTSPreloadHeaders": getFuncBoolValue(label.TraefikFrontendSTSPreload, false),
|
|
||||||
"hasForceSTSHeaderHeaders": hasFuncLabel(label.TraefikFrontendForceSTSHeader),
|
|
||||||
"getForceSTSHeaderHeaders": getFuncBoolValue(label.TraefikFrontendForceSTSHeader, false),
|
|
||||||
"hasFrameDenyHeaders": hasFuncLabel(label.TraefikFrontendFrameDeny),
|
|
||||||
"getFrameDenyHeaders": getFuncBoolValue(label.TraefikFrontendFrameDeny, false),
|
|
||||||
"hasCustomFrameOptionsValueHeaders": hasFuncLabel(label.TraefikFrontendCustomFrameOptionsValue),
|
|
||||||
"getCustomFrameOptionsValueHeaders": getFuncStringValue(label.TraefikFrontendCustomFrameOptionsValue, ""),
|
|
||||||
"hasContentTypeNosniffHeaders": hasFuncLabel(label.TraefikFrontendContentTypeNosniff),
|
|
||||||
"getContentTypeNosniffHeaders": getFuncBoolValue(label.TraefikFrontendContentTypeNosniff, false),
|
|
||||||
"hasBrowserXSSFilterHeaders": hasFuncLabel(label.TraefikFrontendBrowserXSSFilter),
|
|
||||||
"getBrowserXSSFilterHeaders": getFuncBoolValue(label.TraefikFrontendBrowserXSSFilter, false),
|
|
||||||
"hasContentSecurityPolicyHeaders": hasFuncLabel(label.TraefikFrontendContentSecurityPolicy),
|
|
||||||
"getContentSecurityPolicyHeaders": getFuncStringValue(label.TraefikFrontendContentSecurityPolicy, ""),
|
|
||||||
"hasPublicKeyHeaders": hasFuncLabel(label.TraefikFrontendPublicKey),
|
|
||||||
"getPublicKeyHeaders": getFuncStringValue(label.TraefikFrontendPublicKey, ""),
|
|
||||||
"hasReferrerPolicyHeaders": hasFuncLabel(label.TraefikFrontendReferrerPolicy),
|
|
||||||
"getReferrerPolicyHeaders": getFuncStringValue(label.TraefikFrontendReferrerPolicy, ""),
|
|
||||||
"hasIsDevelopmentHeaders": hasFuncLabel(label.TraefikFrontendIsDevelopment),
|
|
||||||
"getIsDevelopmentHeaders": getFuncBoolValue(label.TraefikFrontendIsDevelopment, false),
|
|
||||||
}
|
}
|
||||||
return p.GetConfiguration("templates/ecs.tmpl", ecsFuncMap, struct {
|
return p.GetConfiguration("templates/ecs.tmpl", ecsFuncMap, struct {
|
||||||
Services map[string][]ecsInstance
|
Services map[string][]ecsInstance
|
||||||
}{
|
}{
|
||||||
services,
|
Services: services,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,23 +73,34 @@ func (p *Provider) getFrontendRule(i ecsInstance) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Deprecated
|
// TODO: Deprecated
|
||||||
// Deprecated replaced by Stickiness
|
// replaced by Stickiness
|
||||||
func getSticky(instances []ecsInstance) string {
|
// Deprecated
|
||||||
|
func getSticky(instances []ecsInstance) bool {
|
||||||
if hasFirst(instances, label.TraefikBackendLoadBalancerSticky) {
|
if hasFirst(instances, label.TraefikBackendLoadBalancerSticky) {
|
||||||
log.Warnf("Deprecated configuration found: %s. Please use %s.", label.TraefikBackendLoadBalancerSticky, label.TraefikBackendLoadBalancerStickiness)
|
log.Warnf("Deprecated configuration found: %s. Please use %s.", label.TraefikBackendLoadBalancerSticky, label.TraefikBackendLoadBalancerStickiness)
|
||||||
}
|
}
|
||||||
return getFirstStringValue(instances, label.TraefikBackendLoadBalancerSticky, "false")
|
return getFirstBoolValue(instances, label.TraefikBackendLoadBalancerSticky, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Deprecated
|
||||||
|
// replaced by Stickiness
|
||||||
|
// Deprecated
|
||||||
|
func getStickyOne(instance ecsInstance) bool {
|
||||||
|
if hasLabel(instance, label.TraefikBackendLoadBalancerSticky) {
|
||||||
|
log.Warnf("Deprecated configuration found: %s. Please use %s.", label.TraefikBackendLoadBalancerSticky, label.TraefikBackendLoadBalancerStickiness)
|
||||||
|
}
|
||||||
|
return getBoolValue(instance, label.TraefikBackendLoadBalancerSticky, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHost(i ecsInstance) string {
|
func getHost(i ecsInstance) string {
|
||||||
return *i.machine.PrivateIpAddress
|
return aws.StringValue(i.machine.PrivateIpAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPort(i ecsInstance) string {
|
func getPort(i ecsInstance) string {
|
||||||
if value := getStringValue(i, label.TraefikPort, ""); len(value) > 0 {
|
if value := getStringValue(i, label.TraefikPort, ""); len(value) > 0 {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
return strconv.FormatInt(*i.container.NetworkBindings[0].HostPort, 10)
|
return strconv.FormatInt(aws.Int64Value(i.container.NetworkBindings[0].HostPort), 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterFrontends(instances []ecsInstance) []ecsInstance {
|
func filterFrontends(instances []ecsInstance) []ecsInstance {
|
||||||
|
@ -140,54 +115,163 @@ func filterFrontends(instances []ecsInstance) []ecsInstance {
|
||||||
}, instances).([]ecsInstance)
|
}, instances).([]ecsInstance)
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasLoadBalancerLabel(instances []ecsInstance) bool {
|
func getCircuitBreaker(instance ecsInstance) *types.CircuitBreaker {
|
||||||
method := hasFirst(instances, label.TraefikBackendLoadBalancerMethod)
|
expression := getStringValue(instance, label.TraefikBackendCircuitBreakerExpression, "")
|
||||||
sticky := hasFirst(instances, label.TraefikBackendLoadBalancerSticky)
|
if len(expression) == 0 {
|
||||||
stickiness := hasFirst(instances, label.TraefikBackendLoadBalancerStickiness)
|
return nil
|
||||||
cookieName := hasFirst(instances, label.TraefikBackendLoadBalancerStickinessCookieName)
|
}
|
||||||
|
|
||||||
return method || sticky || stickiness || cookieName
|
return &types.CircuitBreaker{Expression: expression}
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasMaxConnLabels(instances []ecsInstance) bool {
|
func getLoadBalancer(instance ecsInstance) *types.LoadBalancer {
|
||||||
mca := hasFirst(instances, label.TraefikBackendMaxConnAmount)
|
if !hasPrefix(instance, label.TraefikBackendLoadBalancer) {
|
||||||
mcef := hasFirst(instances, label.TraefikBackendMaxConnExtractorFunc)
|
return nil
|
||||||
return mca && mcef
|
}
|
||||||
|
|
||||||
|
method := getStringValue(instance, label.TraefikBackendLoadBalancerMethod, label.DefaultBackendLoadBalancerMethod)
|
||||||
|
|
||||||
|
lb := &types.LoadBalancer{
|
||||||
|
Method: method,
|
||||||
|
Sticky: getStickyOne(instance),
|
||||||
|
}
|
||||||
|
|
||||||
|
if getBoolValue(instance, label.TraefikBackendLoadBalancerStickiness, false) {
|
||||||
|
cookieName := getStringValue(instance, label.TraefikBackendLoadBalancerStickinessCookieName, label.DefaultBackendLoadbalancerStickinessCookieName)
|
||||||
|
lb.Stickiness = &types.Stickiness{CookieName: cookieName}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lb
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasRedirect(instance ecsInstance) bool {
|
func getMaxConn(instance ecsInstance) *types.MaxConn {
|
||||||
return hasLabel(instance, label.TraefikFrontendRedirectEntryPoint) ||
|
amount := getInt64Value(instance, label.TraefikBackendMaxConnAmount, math.MinInt64)
|
||||||
hasLabel(instance, label.TraefikFrontendRedirectRegex) && hasLabel(instance, label.TraefikFrontendRedirectReplacement)
|
extractorFunc := getStringValue(instance, label.TraefikBackendMaxConnExtractorFunc, label.DefaultBackendMaxconnExtractorFunc)
|
||||||
|
|
||||||
|
if amount == math.MinInt64 || len(extractorFunc) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.MaxConn{
|
||||||
|
Amount: amount,
|
||||||
|
ExtractorFunc: extractorFunc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHealthCheck(instance ecsInstance) *types.HealthCheck {
|
||||||
|
path := getStringValue(instance, label.TraefikBackendHealthCheckPath, "")
|
||||||
|
if len(path) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
port := getIntValue(instance, label.TraefikBackendHealthCheckPort, label.DefaultBackendHealthCheckPort)
|
||||||
|
interval := getStringValue(instance, label.TraefikBackendHealthCheckInterval, "")
|
||||||
|
|
||||||
|
return &types.HealthCheck{
|
||||||
|
Path: path,
|
||||||
|
Port: port,
|
||||||
|
Interval: interval,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getServers(instances []ecsInstance) map[string]types.Server {
|
||||||
|
var servers map[string]types.Server
|
||||||
|
|
||||||
|
for _, instance := range instances {
|
||||||
|
if servers == nil {
|
||||||
|
servers = make(map[string]types.Server)
|
||||||
|
}
|
||||||
|
|
||||||
|
protocol := getStringValue(instance, label.TraefikProtocol, label.DefaultProtocol)
|
||||||
|
host := getHost(instance)
|
||||||
|
port := getPort(instance)
|
||||||
|
|
||||||
|
serverName := provider.Normalize(fmt.Sprintf("server-%s-%s", instance.Name, instance.ID))
|
||||||
|
servers[serverName] = types.Server{
|
||||||
|
URL: fmt.Sprintf("%s://%s:%s", protocol, host, port),
|
||||||
|
Weight: getIntValue(instance, label.TraefikWeight, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return servers
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRedirect(instance ecsInstance) *types.Redirect {
|
||||||
|
if hasLabel(instance, label.TraefikFrontendRedirectEntryPoint) {
|
||||||
|
return &types.Redirect{
|
||||||
|
EntryPoint: getStringValue(instance, label.TraefikFrontendRedirectEntryPoint, ""),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hasLabel(instance, label.TraefikFrontendRedirectRegex) &&
|
||||||
|
hasLabel(instance, label.TraefikFrontendRedirectReplacement) {
|
||||||
|
return &types.Redirect{
|
||||||
|
Regex: getStringValue(instance, label.TraefikFrontendRedirectRegex, ""),
|
||||||
|
Replacement: getStringValue(instance, label.TraefikFrontendRedirectReplacement, ""),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getErrorPages(instance ecsInstance) map[string]*types.ErrorPage {
|
func getErrorPages(instance ecsInstance) map[string]*types.ErrorPage {
|
||||||
labels := mapPToMap(instance.containerDefinition.DockerLabels)
|
labels := mapPToMap(instance.containerDefinition.DockerLabels)
|
||||||
|
if len(labels) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
prefix := label.Prefix + label.BaseFrontendErrorPage
|
prefix := label.Prefix + label.BaseFrontendErrorPage
|
||||||
return label.ParseErrorPages(labels, prefix, label.RegexpFrontendErrorPage)
|
return label.ParseErrorPages(labels, prefix, label.RegexpFrontendErrorPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRateLimits(instance ecsInstance) map[string]*types.Rate {
|
func getRateLimit(instance ecsInstance) *types.RateLimit {
|
||||||
labels := mapPToMap(instance.containerDefinition.DockerLabels)
|
extractorFunc := getStringValue(instance, label.TraefikFrontendRateLimitExtractorFunc, "")
|
||||||
|
if len(extractorFunc) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
labels := mapPToMap(instance.containerDefinition.DockerLabels)
|
||||||
prefix := label.Prefix + label.BaseFrontendRateLimit
|
prefix := label.Prefix + label.BaseFrontendRateLimit
|
||||||
return label.ParseRateSets(labels, prefix, label.RegexpFrontendRateLimit)
|
limits := label.ParseRateSets(labels, prefix, label.RegexpFrontendRateLimit)
|
||||||
|
|
||||||
|
return &types.RateLimit{
|
||||||
|
ExtractorFunc: extractorFunc,
|
||||||
|
RateSet: limits,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHeaders(instance ecsInstance) *types.Headers {
|
||||||
|
headers := &types.Headers{
|
||||||
|
CustomRequestHeaders: getMapString(instance, label.TraefikFrontendRequestHeaders),
|
||||||
|
CustomResponseHeaders: getMapString(instance, label.TraefikFrontendResponseHeaders),
|
||||||
|
SSLProxyHeaders: getMapString(instance, label.TraefikFrontendSSLProxyHeaders),
|
||||||
|
AllowedHosts: getSliceString(instance, label.TraefikFrontendAllowedHosts),
|
||||||
|
HostsProxyHeaders: getSliceString(instance, label.TraefikFrontendHostsProxyHeaders),
|
||||||
|
STSSeconds: getInt64Value(instance, label.TraefikFrontendSTSSeconds, 0),
|
||||||
|
SSLRedirect: getBoolValue(instance, label.TraefikFrontendSSLRedirect, false),
|
||||||
|
SSLTemporaryRedirect: getBoolValue(instance, label.TraefikFrontendSSLTemporaryRedirect, false),
|
||||||
|
STSIncludeSubdomains: getBoolValue(instance, label.TraefikFrontendSTSIncludeSubdomains, false),
|
||||||
|
STSPreload: getBoolValue(instance, label.TraefikFrontendSTSPreload, false),
|
||||||
|
ForceSTSHeader: getBoolValue(instance, label.TraefikFrontendForceSTSHeader, false),
|
||||||
|
FrameDeny: getBoolValue(instance, label.TraefikFrontendFrameDeny, false),
|
||||||
|
ContentTypeNosniff: getBoolValue(instance, label.TraefikFrontendContentTypeNosniff, false),
|
||||||
|
BrowserXSSFilter: getBoolValue(instance, label.TraefikFrontendBrowserXSSFilter, false),
|
||||||
|
IsDevelopment: getBoolValue(instance, label.TraefikFrontendIsDevelopment, false),
|
||||||
|
SSLHost: getStringValue(instance, label.TraefikFrontendSSLHost, ""),
|
||||||
|
CustomFrameOptionsValue: getStringValue(instance, label.TraefikFrontendCustomFrameOptionsValue, ""),
|
||||||
|
ContentSecurityPolicy: getStringValue(instance, label.TraefikFrontendContentSecurityPolicy, ""),
|
||||||
|
PublicKey: getStringValue(instance, label.TraefikFrontendPublicKey, ""),
|
||||||
|
ReferrerPolicy: getStringValue(instance, label.TraefikFrontendReferrerPolicy, ""),
|
||||||
|
}
|
||||||
|
|
||||||
|
if !headers.HasSecureHeadersDefined() && !headers.HasCustomHeadersDefined() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return headers
|
||||||
}
|
}
|
||||||
|
|
||||||
// Label functions
|
// Label functions
|
||||||
|
|
||||||
func hasFuncLabel(labelName string) func(i ecsInstance) bool {
|
|
||||||
return func(i ecsInstance) bool {
|
|
||||||
return hasLabel(i, labelName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func hasPrefixFuncLabel(prefix string) func(i ecsInstance) bool {
|
|
||||||
return func(i ecsInstance) bool {
|
|
||||||
return hasPrefix(i, prefix)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getFuncStringValue(labelName string, defaultValue string) func(i ecsInstance) string {
|
func getFuncStringValue(labelName string, defaultValue string) func(i ecsInstance) string {
|
||||||
return func(i ecsInstance) string {
|
return func(i ecsInstance) string {
|
||||||
return getStringValue(i, labelName, defaultValue)
|
return getStringValue(i, labelName, defaultValue)
|
||||||
|
@ -200,9 +284,9 @@ func getFuncBoolValue(labelName string, defaultValue bool) func(i ecsInstance) b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFuncInt64Value(labelName string, defaultValue int64) func(i ecsInstance) int64 {
|
func getFuncIntValue(labelName string, defaultValue int) func(i ecsInstance) int {
|
||||||
return func(i ecsInstance) int64 {
|
return func(i ecsInstance) int {
|
||||||
return getInt64Value(i, labelName, defaultValue)
|
return getIntValue(i, labelName, defaultValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,42 +296,21 @@ func getFuncSliceString(labelName string) func(i ecsInstance) []string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFuncMapValue(labelName string) func(i ecsInstance) map[string]string {
|
// Deprecated
|
||||||
return func(i ecsInstance) map[string]string {
|
|
||||||
return getMapString(i, labelName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func hasFuncFirst(labelName string) func(instances []ecsInstance) bool {
|
func hasFuncFirst(labelName string) func(instances []ecsInstance) bool {
|
||||||
return func(instances []ecsInstance) bool {
|
return func(instances []ecsInstance) bool {
|
||||||
return hasFirst(instances, labelName)
|
return hasFirst(instances, labelName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated
|
||||||
func getFuncFirstStringValue(labelName string, defaultValue string) func(instances []ecsInstance) string {
|
func getFuncFirstStringValue(labelName string, defaultValue string) func(instances []ecsInstance) string {
|
||||||
return func(instances []ecsInstance) string {
|
return func(instances []ecsInstance) string {
|
||||||
return getFirstStringValue(instances, labelName, defaultValue)
|
return getFirstStringValue(instances, labelName, defaultValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFuncFirstIntValue(labelName string, defaultValue int) func(instances []ecsInstance) int {
|
// Deprecated
|
||||||
return func(instances []ecsInstance) int {
|
|
||||||
if len(instances) < 0 {
|
|
||||||
return defaultValue
|
|
||||||
}
|
|
||||||
return getIntValue(instances[0], labelName, defaultValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getFuncFirstInt64Value(labelName string, defaultValue int64) func(instances []ecsInstance) int64 {
|
|
||||||
return func(instances []ecsInstance) int64 {
|
|
||||||
if len(instances) < 0 {
|
|
||||||
return defaultValue
|
|
||||||
}
|
|
||||||
return getInt64Value(instances[0], labelName, defaultValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getFuncFirstBoolValue(labelName string, defaultValue bool) func(instances []ecsInstance) bool {
|
func getFuncFirstBoolValue(labelName string, defaultValue bool) func(instances []ecsInstance) bool {
|
||||||
return func(instances []ecsInstance) bool {
|
return func(instances []ecsInstance) bool {
|
||||||
if len(instances) < 0 {
|
if len(instances) < 0 {
|
||||||
|
@ -259,12 +322,12 @@ func getFuncFirstBoolValue(labelName string, defaultValue bool) func(instances [
|
||||||
|
|
||||||
func hasLabel(i ecsInstance, labelName string) bool {
|
func hasLabel(i ecsInstance, labelName string) bool {
|
||||||
value, ok := i.containerDefinition.DockerLabels[labelName]
|
value, ok := i.containerDefinition.DockerLabels[labelName]
|
||||||
return ok && value != nil && len(*value) > 0
|
return ok && value != nil && len(aws.StringValue(value)) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasPrefix(i ecsInstance, prefix string) bool {
|
func hasPrefix(i ecsInstance, prefix string) bool {
|
||||||
for name, value := range i.containerDefinition.DockerLabels {
|
for name, value := range i.containerDefinition.DockerLabels {
|
||||||
if strings.HasPrefix(name, prefix) && value != nil && len(*value) > 0 {
|
if strings.HasPrefix(name, prefix) && value != nil && len(aws.StringValue(value)) > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,10 +339,10 @@ func getStringValue(i ecsInstance, labelName string, defaultValue string) string
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
if len(*v) == 0 {
|
if len(aws.StringValue(v)) == 0 {
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
return *v
|
return aws.StringValue(v)
|
||||||
}
|
}
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
|
@ -301,7 +364,7 @@ func getIntValue(i ecsInstance, labelName string, defaultValue int) int {
|
||||||
rawValue, ok := i.containerDefinition.DockerLabels[labelName]
|
rawValue, ok := i.containerDefinition.DockerLabels[labelName]
|
||||||
if ok {
|
if ok {
|
||||||
if rawValue != nil {
|
if rawValue != nil {
|
||||||
v, err := strconv.Atoi(*rawValue)
|
v, err := strconv.Atoi(aws.StringValue(rawValue))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
@ -314,7 +377,7 @@ func getInt64Value(i ecsInstance, labelName string, defaultValue int64) int64 {
|
||||||
rawValue, ok := i.containerDefinition.DockerLabels[labelName]
|
rawValue, ok := i.containerDefinition.DockerLabels[labelName]
|
||||||
if ok {
|
if ok {
|
||||||
if rawValue != nil {
|
if rawValue != nil {
|
||||||
v, err := strconv.ParseInt(*rawValue, 10, 64)
|
v, err := strconv.ParseInt(aws.StringValue(rawValue), 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
@ -328,10 +391,10 @@ func getSliceString(i ecsInstance, labelName string) []string {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if len(*value) == 0 {
|
if len(aws.StringValue(value)) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return label.SplitAndTrimString(*value, ",")
|
return label.SplitAndTrimString(aws.StringValue(value), ",")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -341,14 +404,15 @@ func getMapString(i ecsInstance, labelName string) map[string]string {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if len(*value) == 0 {
|
if len(aws.StringValue(value)) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return label.ParseMapValue(labelName, *value)
|
return label.ParseMapValue(labelName, aws.StringValue(value))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated
|
||||||
func hasFirst(instances []ecsInstance, labelName string) bool {
|
func hasFirst(instances []ecsInstance, labelName string) bool {
|
||||||
if len(instances) == 0 {
|
if len(instances) == 0 {
|
||||||
return false
|
return false
|
||||||
|
@ -356,6 +420,7 @@ func hasFirst(instances []ecsInstance, labelName string) bool {
|
||||||
return hasLabel(instances[0], labelName)
|
return hasLabel(instances[0], labelName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated
|
||||||
func getFirstStringValue(instances []ecsInstance, labelName string, defaultValue string) string {
|
func getFirstStringValue(instances []ecsInstance, labelName string, defaultValue string) string {
|
||||||
if len(instances) == 0 {
|
if len(instances) == 0 {
|
||||||
return defaultValue
|
return defaultValue
|
||||||
|
@ -363,11 +428,19 @@ func getFirstStringValue(instances []ecsInstance, labelName string, defaultValue
|
||||||
return getStringValue(instances[0], labelName, defaultValue)
|
return getStringValue(instances[0], labelName, defaultValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated
|
||||||
|
func getFirstBoolValue(instances []ecsInstance, labelName string, defaultValue bool) bool {
|
||||||
|
if len(instances) == 0 {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
return getBoolValue(instances[0], labelName, defaultValue)
|
||||||
|
}
|
||||||
|
|
||||||
func mapPToMap(src map[string]*string) map[string]string {
|
func mapPToMap(src map[string]*string) map[string]string {
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
for key, value := range src {
|
for key, value := range src {
|
||||||
if value != nil && len(*value) > 0 {
|
if value != nil && len(aws.StringValue(value)) > 0 {
|
||||||
result[key] = *value
|
result[key] = aws.StringValue(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,171 +1,155 @@
|
||||||
[backends]
|
[backends]
|
||||||
{{range $serviceName, $instances := .Services}}
|
{{range $serviceName, $instances := .Services }}
|
||||||
|
{{ $firstInstance := index $instances 0 }}
|
||||||
|
|
||||||
{{if hasCircuitBreakerLabel $instances}}
|
{{ $circuitBreaker := getCircuitBreaker $firstInstance }}
|
||||||
[backends.backend-{{ $serviceName }}.circuitBreaker]
|
{{if $circuitBreaker }}
|
||||||
expression = "{{getCircuitBreakerExpression $instances}}"
|
[backends."backend-{{ $serviceName }}".circuitBreaker]
|
||||||
|
expression = "{{ $circuitBreaker.Expression }}"
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if hasLoadBalancerLabel $instances}}
|
{{ $loadBalancer := getLoadBalancer $firstInstance }}
|
||||||
[backends.backend-{{ $serviceName }}.loadBalancer]
|
{{if $loadBalancer }}
|
||||||
method = "{{ getLoadBalancerMethod $instances}}"
|
[backends."backend-{{ $serviceName }}".loadBalancer]
|
||||||
sticky = {{ getSticky $instances}}
|
method = "{{ $loadBalancer.Method }}"
|
||||||
{{if hasStickinessLabel $instances}}
|
sticky = {{ $loadBalancer.Sticky }}
|
||||||
[backends.backend-{{ $serviceName }}.loadBalancer.stickiness]
|
{{if $loadBalancer.Stickiness }}
|
||||||
cookieName = "{{getStickinessCookieName $instances}}"
|
[backends."backend-{{ $serviceName }}".loadBalancer.stickiness]
|
||||||
|
cookieName = "{{ $loadBalancer.Stickiness.CookieName }}"
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if hasMaxConnLabels $instances}}
|
{{ $maxConn := getMaxConn $firstInstance }}
|
||||||
[backends.backend-{{ $serviceName }}.maxConn]
|
{{if $maxConn }}
|
||||||
amount = {{getMaxConnAmount $instances}}
|
[backends."backend-{{ $serviceName }}".maxConn]
|
||||||
extractorFunc = "{{getMaxConnExtractorFunc $instances}}"
|
extractorFunc = "{{ $maxConn.ExtractorFunc }}"
|
||||||
|
amount = {{ $maxConn.Amount }}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{ if hasHealthCheckLabels $instances }}
|
{{ $healthCheck := getHealthCheck $firstInstance }}
|
||||||
|
{{if $healthCheck }}
|
||||||
[backends.backend-{{ $serviceName }}.healthCheck]
|
[backends.backend-{{ $serviceName }}.healthCheck]
|
||||||
path = "{{getHealthCheckPath $instances }}"
|
path = "{{ $healthCheck.Path }}"
|
||||||
port = {{getHealthCheckPort $instances}}
|
port = {{ $healthCheck.Port }}
|
||||||
interval = "{{getHealthCheckInterval $instances }}"
|
interval = "{{ $healthCheck.Interval }}"
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{range $index, $instance := $instances}}
|
{{range $serverName, $server := getServers $instances }}
|
||||||
[backends.backend-{{ $instance.Name }}.servers.server-{{ $instance.Name }}{{ $instance.ID }}]
|
[backends.backend-{{ $serviceName }}.servers.{{ $serverName }}]
|
||||||
url = "{{ getProtocol $instance }}://{{ getHost $instance }}:{{ getPort $instance }}"
|
url = "{{ $server.URL }}"
|
||||||
weight = {{ getWeight $instance}}
|
weight = {{ $server.Weight }}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
[frontends]
|
[frontends]
|
||||||
{{range $serviceName, $instances := .Services}}
|
{{range $serviceName, $instances := .Services }}
|
||||||
{{range $instance := filterFrontends $instances}}
|
{{range $instance := filterFrontends $instances }}
|
||||||
|
|
||||||
[frontends.frontend-{{ $serviceName }}]
|
[frontends.frontend-{{ $serviceName }}]
|
||||||
backend = "backend-{{ $serviceName }}"
|
backend = "backend-{{ $serviceName }}"
|
||||||
priority = {{ getPriority $instance}}
|
priority = {{ getPriority $instance }}
|
||||||
passHostHeader = {{ getPassHostHeader $instance}}
|
passHostHeader = {{ getPassHostHeader $instance }}
|
||||||
passTLSCert = {{ getPassTLSCert $instance}}
|
passTLSCert = {{ getPassTLSCert $instance }}
|
||||||
|
|
||||||
entryPoints = [{{range getEntryPoints $instance}}
|
entryPoints = [{{range getEntryPoints $instance }}
|
||||||
"{{.}}",
|
"{{.}}",
|
||||||
{{end}}]
|
{{end}}]
|
||||||
|
|
||||||
{{if getWhitelistSourceRange $instance}}
|
{{ $whitelistSourceRange := getWhitelistSourceRange $instance }}
|
||||||
whitelistSourceRange = [{{range getWhitelistSourceRange $instance}}
|
{{if $whitelistSourceRange }}
|
||||||
|
whitelistSourceRange = [{{range $whitelistSourceRange }}
|
||||||
"{{.}}",
|
"{{.}}",
|
||||||
{{end}}]
|
{{end}}]
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
basicAuth = [{{range getBasicAuth $instance}}
|
basicAuth = [{{range getBasicAuth $instance }}
|
||||||
"{{.}}",
|
"{{.}}",
|
||||||
{{end}}]
|
{{end}}]
|
||||||
|
|
||||||
{{if hasRedirect $instance}}
|
|
||||||
|
{{ $redirect := getRedirect $instance }}
|
||||||
|
{{if $redirect }}
|
||||||
[frontends."frontend-{{ $serviceName }}".redirect]
|
[frontends."frontend-{{ $serviceName }}".redirect]
|
||||||
entryPoint = "{{getRedirectEntryPoint $instance}}"
|
entryPoint = "{{ $redirect.EntryPoint }}"
|
||||||
regex = "{{getRedirectRegex $instance}}"
|
regex = "{{ $redirect.Regex }}"
|
||||||
replacement = "{{getRedirectReplacement $instance}}"
|
replacement = "{{ $redirect.Replacement }}"
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{ if hasErrorPages $instance }}
|
{{ $errorPages := getErrorPages $instance }}
|
||||||
|
{{if $errorPages }}
|
||||||
[frontends."frontend-{{ $serviceName }}".errors]
|
[frontends."frontend-{{ $serviceName }}".errors]
|
||||||
{{ range $pageName, $page := getErrorPages $instance }}
|
{{range $pageName, $page := $errorPages }}
|
||||||
[frontends."frontend-{{ $serviceName }}".errors.{{ $pageName }}]
|
[frontends."frontend-{{ $serviceName }}".errors.{{ $pageName }}]
|
||||||
status = [{{range $page.Status}}
|
status = [{{range $page.Status }}
|
||||||
"{{.}}",
|
"{{.}}",
|
||||||
{{end}}]
|
{{end}}]
|
||||||
backend = "{{$page.Backend}}"
|
backend = "{{ $page.Backend }}"
|
||||||
query = "{{$page.Query}}"
|
query = "{{ $page.Query }}"
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{ if hasRateLimits $instance }}
|
{{ $rateLimit := getRateLimit $instance }}
|
||||||
|
{{if $rateLimit }}
|
||||||
[frontends."frontend-{{ $serviceName }}".rateLimit]
|
[frontends."frontend-{{ $serviceName }}".rateLimit]
|
||||||
extractorFunc = "{{ getRateLimitsExtractorFunc $instance }}"
|
extractorFunc = "{{ $rateLimit.ExtractorFunc }}"
|
||||||
[frontends."frontend-{{ $serviceName }}".rateLimit.rateSet]
|
[frontends."frontend-{{ $serviceName }}".rateLimit.rateSet]
|
||||||
{{ range $limitName, $rateLimit := getRateLimits $instance }}
|
{{ range $limitName, $limit := $rateLimit.RateSet }}
|
||||||
[frontends."frontend-{{ $serviceName }}".rateLimit.rateSet.{{ $limitName }}]
|
[frontends."frontend-{{ $serviceName }}".rateLimit.rateSet.{{ $limitName }}]
|
||||||
period = "{{ $rateLimit.Period }}"
|
period = "{{ $limit.Period }}"
|
||||||
average = {{ $rateLimit.Average }}
|
average = {{ $limit.Average }}
|
||||||
burst = {{ $rateLimit.Burst }}
|
burst = {{ $limit.Burst }}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if hasHeaders $instance }}
|
{{ $headers := getHeaders $instance }}
|
||||||
|
{{if $headers }}
|
||||||
[frontends."frontend-{{ $serviceName }}".headers]
|
[frontends."frontend-{{ $serviceName }}".headers]
|
||||||
{{if hasSSLRedirectHeaders $instance}}
|
SSLRedirect = {{ $headers.SSLRedirect }}
|
||||||
SSLRedirect = {{getSSLRedirectHeaders $instance}}
|
SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }}
|
||||||
|
SSLHost = "{{ $headers.SSLHost }}"
|
||||||
|
STSSeconds = {{ $headers.STSSeconds }}
|
||||||
|
STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }}
|
||||||
|
STSPreload = {{ $headers.STSPreload }}
|
||||||
|
ForceSTSHeader = {{ $headers.ForceSTSHeader }}
|
||||||
|
FrameDeny = {{ $headers.FrameDeny }}
|
||||||
|
CustomFrameOptionsValue = "{{ $headers.CustomFrameOptionsValue }}"
|
||||||
|
ContentTypeNosniff = {{ $headers.ContentTypeNosniff }}
|
||||||
|
BrowserXSSFilter = {{ $headers.BrowserXSSFilter }}
|
||||||
|
ContentSecurityPolicy = "{{ $headers.ContentSecurityPolicy }}"
|
||||||
|
PublicKey = "{{ $headers.PublicKey }}"
|
||||||
|
ReferrerPolicy = "{{ $headers.ReferrerPolicy }}"
|
||||||
|
IsDevelopment = {{ $headers.IsDevelopment }}
|
||||||
|
|
||||||
|
{{if $headers.AllowedHosts }}
|
||||||
|
AllowedHosts = [{{range $headers.AllowedHosts }}
|
||||||
|
"{{.}}",
|
||||||
|
{{end}}]
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if hasSSLTemporaryRedirectHeaders $instance}}
|
|
||||||
SSLTemporaryRedirect = {{getSSLTemporaryRedirectHeaders $instance}}
|
{{if $headers.HostsProxyHeaders }}
|
||||||
|
HostsProxyHeaders = [{{range $headers.HostsProxyHeaders }}
|
||||||
|
"{{.}}",
|
||||||
|
{{end}}]
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if hasSSLHostHeaders $instance}}
|
|
||||||
SSLHost = "{{getSSLHostHeaders $instance}}"
|
{{if $headers.CustomRequestHeaders }}
|
||||||
{{end}}
|
[frontends."frontend-{{ $serviceName }}".headers.customRequestHeaders]
|
||||||
{{if hasSTSSecondsHeaders $instance}}
|
{{range $k, $v := $headers.CustomRequestHeaders }}
|
||||||
STSSeconds = {{getSTSSecondsHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasSTSIncludeSubdomainsHeaders $instance}}
|
|
||||||
STSIncludeSubdomains = {{getSTSIncludeSubdomainsHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasSTSPreloadHeaders $instance}}
|
|
||||||
STSPreload = {{getSTSPreloadHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasForceSTSHeaderHeaders $instance}}
|
|
||||||
ForceSTSHeader = {{getForceSTSHeaderHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasFrameDenyHeaders $instance}}
|
|
||||||
FrameDeny = {{getFrameDenyHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasCustomFrameOptionsValueHeaders $instance}}
|
|
||||||
CustomFrameOptionsValue = "{{getCustomFrameOptionsValueHeaders $instance}}"
|
|
||||||
{{end}}
|
|
||||||
{{if hasContentTypeNosniffHeaders $instance}}
|
|
||||||
ContentTypeNosniff = {{getContentTypeNosniffHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasBrowserXSSFilterHeaders $instance}}
|
|
||||||
BrowserXSSFilter = {{getBrowserXSSFilterHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasContentSecurityPolicyHeaders $instance}}
|
|
||||||
ContentSecurityPolicy = "{{getContentSecurityPolicyHeaders $instance}}"
|
|
||||||
{{end}}
|
|
||||||
{{if hasPublicKeyHeaders $instance}}
|
|
||||||
PublicKey = "{{getPublicKeyHeaders $instance}}"
|
|
||||||
{{end}}
|
|
||||||
{{if hasReferrerPolicyHeaders $instance}}
|
|
||||||
ReferrerPolicy = "{{getReferrerPolicyHeaders $instance}}"
|
|
||||||
{{end}}
|
|
||||||
{{if hasIsDevelopmentHeaders $instance}}
|
|
||||||
IsDevelopment = {{getIsDevelopmentHeaders $instance}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasRequestHeaders $instance}}
|
|
||||||
[frontends."frontend-{{ $serviceName }}".headers.customRequestHeaders]
|
|
||||||
{{range $k, $v := getRequestHeaders $instance}}
|
|
||||||
{{$k}} = "{{$v}}"
|
{{$k}} = "{{$v}}"
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if hasResponseHeaders $instance}}
|
|
||||||
|
{{if $headers.CustomResponseHeaders }}
|
||||||
[frontends."frontend-{{ $serviceName }}".headers.customResponseHeaders]
|
[frontends."frontend-{{ $serviceName }}".headers.customResponseHeaders]
|
||||||
{{range $k, $v := getResponseHeaders $instance}}
|
{{range $k, $v := $headers.CustomResponseHeaders }}
|
||||||
{{$k}} = "{{$v}}"
|
{{$k}} = "{{$v}}"
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if hasAllowedHostsHeaders $instance}}
|
|
||||||
[frontends."frontend-{{ $serviceName }}".headers.AllowedHosts]
|
{{if $headers.SSLProxyHeaders }}
|
||||||
{{range getAllowedHostsHeaders $instance}}
|
|
||||||
"{{.}}"
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasHostsProxyHeaders $instance}}
|
|
||||||
[frontends."frontend-{{ $serviceName }}".headers.HostsProxyHeaders]
|
|
||||||
{{range getHostsProxyHeaders $instance}}
|
|
||||||
"{{.}}"
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
{{if hasSSLProxyHeaders $instance}}
|
|
||||||
[frontends."frontend-{{ $serviceName }}".headers.SSLProxyHeaders]
|
[frontends."frontend-{{ $serviceName }}".headers.SSLProxyHeaders]
|
||||||
{{range $k, $v := getSSLProxyHeaders $instance}}
|
{{range $k, $v := $headers.SSLProxyHeaders }}
|
||||||
{{$k}} = "{{$v}}"
|
{{$k}} = "{{$v}}"
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue