2017-12-02 18:30:16 +00:00
|
|
|
package ecs
|
|
|
|
|
|
|
|
import (
|
2018-01-10 17:28:03 +00:00
|
|
|
"fmt"
|
2017-12-16 18:57:40 +00:00
|
|
|
"math"
|
2017-12-02 18:30:16 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"github.com/BurntSushi/ty/fun"
|
2018-01-10 17:28:03 +00:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
2017-12-02 18:30:16 +00:00
|
|
|
"github.com/containous/traefik/log"
|
2018-01-10 17:28:03 +00:00
|
|
|
"github.com/containous/traefik/provider"
|
2017-12-02 18:30:16 +00:00
|
|
|
"github.com/containous/traefik/provider/label"
|
|
|
|
"github.com/containous/traefik/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// buildConfiguration fills the config template with the given instances
|
|
|
|
func (p *Provider) buildConfiguration(services map[string][]ecsInstance) (*types.Configuration, error) {
|
|
|
|
var ecsFuncMap = template.FuncMap{
|
2017-12-20 21:14:51 +00:00
|
|
|
// Backend functions
|
2018-01-10 17:28:03 +00:00
|
|
|
"getHost": getHost,
|
|
|
|
"getPort": getPort,
|
|
|
|
"getCircuitBreaker": getCircuitBreaker,
|
|
|
|
"getLoadBalancer": getLoadBalancer,
|
|
|
|
"getMaxConn": getMaxConn,
|
|
|
|
"getHealthCheck": getHealthCheck,
|
2018-01-31 14:32:04 +00:00
|
|
|
"getBuffering": getBuffering,
|
2018-01-10 17:28:03 +00:00
|
|
|
"getServers": getServers,
|
|
|
|
|
|
|
|
// TODO Deprecated [breaking]
|
|
|
|
"getProtocol": getFuncStringValue(label.TraefikProtocol, label.DefaultProtocol),
|
|
|
|
// TODO Deprecated [breaking]
|
|
|
|
"getWeight": getFuncIntValue(label.TraefikWeight, label.DefaultWeightInt),
|
|
|
|
// TODO Deprecated [breaking]
|
|
|
|
"getLoadBalancerMethod": getFuncFirstStringValue(label.TraefikBackendLoadBalancerMethod, label.DefaultBackendLoadBalancerMethod),
|
|
|
|
// TODO Deprecated [breaking]
|
|
|
|
"getSticky": getSticky,
|
|
|
|
// TODO Deprecated [breaking]
|
|
|
|
"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, ""),
|
2017-12-16 19:24:30 +00:00
|
|
|
|
2017-12-20 21:14:51 +00:00
|
|
|
// Frontend functions
|
2018-01-10 17:28:03 +00:00
|
|
|
"filterFrontends": filterFrontends,
|
|
|
|
"getFrontendRule": p.getFrontendRule,
|
|
|
|
"getPassHostHeader": getFuncBoolValue(label.TraefikFrontendPassHostHeader, label.DefaultPassHostHeaderBool),
|
|
|
|
"getPassTLSCert": getFuncBoolValue(label.TraefikFrontendPassTLSCert, label.DefaultPassTLSCert),
|
|
|
|
"getPriority": getFuncIntValue(label.TraefikFrontendPriority, label.DefaultFrontendPriorityInt),
|
|
|
|
"getBasicAuth": getFuncSliceString(label.TraefikFrontendAuthBasic),
|
|
|
|
"getEntryPoints": getFuncSliceString(label.TraefikFrontendEntryPoints),
|
|
|
|
"getWhitelistSourceRange": getFuncSliceString(label.TraefikFrontendWhitelistSourceRange),
|
|
|
|
"getRedirect": getRedirect,
|
|
|
|
"getErrorPages": getErrorPages,
|
|
|
|
"getRateLimit": getRateLimit,
|
|
|
|
"getHeaders": getHeaders,
|
2017-12-02 18:30:16 +00:00
|
|
|
}
|
|
|
|
return p.GetConfiguration("templates/ecs.tmpl", ecsFuncMap, struct {
|
|
|
|
Services map[string][]ecsInstance
|
|
|
|
}{
|
2018-01-10 17:28:03 +00:00
|
|
|
Services: services,
|
2017-12-02 18:30:16 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Provider) getFrontendRule(i ecsInstance) string {
|
|
|
|
defaultRule := "Host:" + strings.ToLower(strings.Replace(i.Name, "_", "-", -1)) + "." + p.Domain
|
|
|
|
return getStringValue(i, label.TraefikFrontendRule, defaultRule)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Deprecated
|
2018-01-10 17:28:03 +00:00
|
|
|
// replaced by Stickiness
|
|
|
|
// Deprecated
|
|
|
|
func getSticky(instances []ecsInstance) bool {
|
2017-12-02 18:30:16 +00:00
|
|
|
if hasFirst(instances, label.TraefikBackendLoadBalancerSticky) {
|
|
|
|
log.Warnf("Deprecated configuration found: %s. Please use %s.", label.TraefikBackendLoadBalancerSticky, label.TraefikBackendLoadBalancerStickiness)
|
|
|
|
}
|
2018-01-10 17:28:03 +00:00
|
|
|
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)
|
2017-12-02 18:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getHost(i ecsInstance) string {
|
2018-01-10 17:28:03 +00:00
|
|
|
return aws.StringValue(i.machine.PrivateIpAddress)
|
2017-12-02 18:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getPort(i ecsInstance) string {
|
|
|
|
if value := getStringValue(i, label.TraefikPort, ""); len(value) > 0 {
|
|
|
|
return value
|
|
|
|
}
|
2018-01-10 17:28:03 +00:00
|
|
|
return strconv.FormatInt(aws.Int64Value(i.container.NetworkBindings[0].HostPort), 10)
|
2017-12-02 18:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func filterFrontends(instances []ecsInstance) []ecsInstance {
|
|
|
|
byName := make(map[string]struct{})
|
|
|
|
|
|
|
|
return fun.Filter(func(i ecsInstance) bool {
|
|
|
|
_, found := byName[i.Name]
|
|
|
|
if !found {
|
|
|
|
byName[i.Name] = struct{}{}
|
|
|
|
}
|
|
|
|
return !found
|
|
|
|
}, instances).([]ecsInstance)
|
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
func getCircuitBreaker(instance ecsInstance) *types.CircuitBreaker {
|
|
|
|
expression := getStringValue(instance, label.TraefikBackendCircuitBreakerExpression, "")
|
|
|
|
if len(expression) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2017-12-16 18:38:12 +00:00
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
return &types.CircuitBreaker{Expression: expression}
|
2017-12-16 18:38:12 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
func getLoadBalancer(instance ecsInstance) *types.LoadBalancer {
|
|
|
|
if !hasPrefix(instance, label.TraefikBackendLoadBalancer) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
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 getMaxConn(instance ecsInstance) *types.MaxConn {
|
|
|
|
amount := getInt64Value(instance, label.TraefikBackendMaxConnAmount, math.MinInt64)
|
|
|
|
extractorFunc := getStringValue(instance, label.TraefikBackendMaxConnExtractorFunc, label.DefaultBackendMaxconnExtractorFunc)
|
|
|
|
|
|
|
|
if amount == math.MinInt64 || len(extractorFunc) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.MaxConn{
|
|
|
|
Amount: amount,
|
|
|
|
ExtractorFunc: extractorFunc,
|
|
|
|
}
|
2017-12-16 18:57:40 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-31 14:32:04 +00:00
|
|
|
func getBuffering(instance ecsInstance) *types.Buffering {
|
|
|
|
if !hasPrefix(instance, label.TraefikBackendBuffering) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.Buffering{
|
|
|
|
MaxRequestBodyBytes: getInt64Value(instance, label.TraefikBackendBufferingMaxRequestBodyBytes, 0),
|
|
|
|
MaxResponseBodyBytes: getInt64Value(instance, label.TraefikBackendBufferingMaxResponseBodyBytes, 0),
|
|
|
|
MemRequestBodyBytes: getInt64Value(instance, label.TraefikBackendBufferingMemRequestBodyBytes, 0),
|
|
|
|
MemResponseBodyBytes: getInt64Value(instance, label.TraefikBackendBufferingMemResponseBodyBytes, 0),
|
|
|
|
RetryExpression: getStringValue(instance, label.TraefikBackendBufferingRetryExpression, ""),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
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 {
|
2018-01-31 18:10:04 +00:00
|
|
|
permanent := getBoolValue(instance, label.TraefikFrontendRedirectPermanent, false)
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
if hasLabel(instance, label.TraefikFrontendRedirectEntryPoint) {
|
|
|
|
return &types.Redirect{
|
|
|
|
EntryPoint: getStringValue(instance, label.TraefikFrontendRedirectEntryPoint, ""),
|
2018-01-31 18:10:04 +00:00
|
|
|
Permanent: permanent,
|
2018-01-10 17:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-31 18:10:04 +00:00
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
if hasLabel(instance, label.TraefikFrontendRedirectRegex) &&
|
|
|
|
hasLabel(instance, label.TraefikFrontendRedirectReplacement) {
|
|
|
|
return &types.Redirect{
|
|
|
|
Regex: getStringValue(instance, label.TraefikFrontendRedirectRegex, ""),
|
|
|
|
Replacement: getStringValue(instance, label.TraefikFrontendRedirectReplacement, ""),
|
2018-01-31 18:10:04 +00:00
|
|
|
Permanent: permanent,
|
2018-01-10 17:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2017-12-16 19:12:44 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 21:59:57 +00:00
|
|
|
func getErrorPages(instance ecsInstance) map[string]*types.ErrorPage {
|
|
|
|
labels := mapPToMap(instance.containerDefinition.DockerLabels)
|
2018-01-10 17:28:03 +00:00
|
|
|
if len(labels) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2017-12-20 21:59:57 +00:00
|
|
|
|
|
|
|
prefix := label.Prefix + label.BaseFrontendErrorPage
|
|
|
|
return label.ParseErrorPages(labels, prefix, label.RegexpFrontendErrorPage)
|
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
func getRateLimit(instance ecsInstance) *types.RateLimit {
|
|
|
|
extractorFunc := getStringValue(instance, label.TraefikFrontendRateLimitExtractorFunc, "")
|
|
|
|
if len(extractorFunc) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2017-12-20 21:59:57 +00:00
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
labels := mapPToMap(instance.containerDefinition.DockerLabels)
|
2017-12-20 21:59:57 +00:00
|
|
|
prefix := label.Prefix + label.BaseFrontendRateLimit
|
2018-01-10 17:28:03 +00:00
|
|
|
limits := label.ParseRateSets(labels, prefix, label.RegexpFrontendRateLimit)
|
2017-12-02 18:30:16 +00:00
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
return &types.RateLimit{
|
|
|
|
ExtractorFunc: extractorFunc,
|
|
|
|
RateSet: limits,
|
2017-12-16 19:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
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, ""),
|
2018-03-02 13:24:03 +00:00
|
|
|
CustomBrowserXSSValue: getStringValue(instance, label.TraefikFrontendCustomBrowserXSSValue, ""),
|
2017-12-20 21:59:57 +00:00
|
|
|
}
|
2018-01-10 17:28:03 +00:00
|
|
|
|
|
|
|
if !headers.HasSecureHeadersDefined() && !headers.HasCustomHeadersDefined() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return headers
|
2017-12-20 21:59:57 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
// Label functions
|
|
|
|
|
2017-12-02 18:30:16 +00:00
|
|
|
func getFuncStringValue(labelName string, defaultValue string) func(i ecsInstance) string {
|
|
|
|
return func(i ecsInstance) string {
|
|
|
|
return getStringValue(i, labelName, defaultValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 19:00:36 +00:00
|
|
|
func getFuncBoolValue(labelName string, defaultValue bool) func(i ecsInstance) bool {
|
|
|
|
return func(i ecsInstance) bool {
|
|
|
|
return getBoolValue(i, labelName, defaultValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
func getFuncIntValue(labelName string, defaultValue int) func(i ecsInstance) int {
|
|
|
|
return func(i ecsInstance) int {
|
|
|
|
return getIntValue(i, labelName, defaultValue)
|
2017-12-16 19:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-02 18:30:16 +00:00
|
|
|
func getFuncSliceString(labelName string) func(i ecsInstance) []string {
|
|
|
|
return func(i ecsInstance) []string {
|
|
|
|
return getSliceString(i, labelName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
// Deprecated
|
2017-12-02 18:30:16 +00:00
|
|
|
func hasFuncFirst(labelName string) func(instances []ecsInstance) bool {
|
|
|
|
return func(instances []ecsInstance) bool {
|
|
|
|
return hasFirst(instances, labelName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
// Deprecated
|
2017-12-02 18:30:16 +00:00
|
|
|
func getFuncFirstStringValue(labelName string, defaultValue string) func(instances []ecsInstance) string {
|
|
|
|
return func(instances []ecsInstance) string {
|
|
|
|
return getFirstStringValue(instances, labelName, defaultValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
// Deprecated
|
2017-12-02 18:30:16 +00:00
|
|
|
func getFuncFirstBoolValue(labelName string, defaultValue bool) func(instances []ecsInstance) bool {
|
|
|
|
return func(instances []ecsInstance) bool {
|
|
|
|
if len(instances) < 0 {
|
|
|
|
return defaultValue
|
|
|
|
}
|
|
|
|
return getBoolValue(instances[0], labelName, defaultValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 19:12:44 +00:00
|
|
|
func hasLabel(i ecsInstance, labelName string) bool {
|
|
|
|
value, ok := i.containerDefinition.DockerLabels[labelName]
|
2018-01-10 17:28:03 +00:00
|
|
|
return ok && value != nil && len(aws.StringValue(value)) > 0
|
2017-12-16 19:12:44 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 21:59:57 +00:00
|
|
|
func hasPrefix(i ecsInstance, prefix string) bool {
|
|
|
|
for name, value := range i.containerDefinition.DockerLabels {
|
2018-01-10 17:28:03 +00:00
|
|
|
if strings.HasPrefix(name, prefix) && value != nil && len(aws.StringValue(value)) > 0 {
|
2017-12-20 21:59:57 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-12-02 18:30:16 +00:00
|
|
|
func getStringValue(i ecsInstance, labelName string, defaultValue string) string {
|
|
|
|
if v, ok := i.containerDefinition.DockerLabels[labelName]; ok {
|
|
|
|
if v == nil {
|
|
|
|
return defaultValue
|
|
|
|
}
|
2018-01-10 17:28:03 +00:00
|
|
|
if len(aws.StringValue(v)) == 0 {
|
2017-12-02 18:30:16 +00:00
|
|
|
return defaultValue
|
|
|
|
}
|
2018-01-10 17:28:03 +00:00
|
|
|
return aws.StringValue(v)
|
2017-12-02 18:30:16 +00:00
|
|
|
}
|
|
|
|
return defaultValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func getBoolValue(i ecsInstance, labelName string, defaultValue bool) bool {
|
|
|
|
rawValue, ok := i.containerDefinition.DockerLabels[labelName]
|
|
|
|
if ok {
|
|
|
|
if rawValue != nil {
|
2018-03-09 11:02:29 +00:00
|
|
|
v, err := strconv.ParseBool(aws.StringValue(rawValue))
|
2017-12-02 18:30:16 +00:00
|
|
|
if err == nil {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return defaultValue
|
|
|
|
}
|
|
|
|
|
2017-12-16 18:29:30 +00:00
|
|
|
func getIntValue(i ecsInstance, labelName string, defaultValue int) int {
|
|
|
|
rawValue, ok := i.containerDefinition.DockerLabels[labelName]
|
|
|
|
if ok {
|
|
|
|
if rawValue != nil {
|
2018-01-10 17:28:03 +00:00
|
|
|
v, err := strconv.Atoi(aws.StringValue(rawValue))
|
2017-12-16 18:29:30 +00:00
|
|
|
if err == nil {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return defaultValue
|
|
|
|
}
|
|
|
|
|
2017-12-16 18:57:40 +00:00
|
|
|
func getInt64Value(i ecsInstance, labelName string, defaultValue int64) int64 {
|
|
|
|
rawValue, ok := i.containerDefinition.DockerLabels[labelName]
|
|
|
|
if ok {
|
|
|
|
if rawValue != nil {
|
2018-01-10 17:28:03 +00:00
|
|
|
v, err := strconv.ParseInt(aws.StringValue(rawValue), 10, 64)
|
2017-12-16 18:57:40 +00:00
|
|
|
if err == nil {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return defaultValue
|
|
|
|
}
|
|
|
|
|
2017-12-02 18:30:16 +00:00
|
|
|
func getSliceString(i ecsInstance, labelName string) []string {
|
|
|
|
if value, ok := i.containerDefinition.DockerLabels[labelName]; ok {
|
|
|
|
if value == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-01-10 17:28:03 +00:00
|
|
|
if len(aws.StringValue(value)) == 0 {
|
2017-12-02 18:30:16 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-01-10 17:28:03 +00:00
|
|
|
return label.SplitAndTrimString(aws.StringValue(value), ",")
|
2017-12-02 18:30:16 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-12-16 19:24:30 +00:00
|
|
|
func getMapString(i ecsInstance, labelName string) map[string]string {
|
|
|
|
if value, ok := i.containerDefinition.DockerLabels[labelName]; ok {
|
|
|
|
if value == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-01-10 17:28:03 +00:00
|
|
|
if len(aws.StringValue(value)) == 0 {
|
2017-12-16 19:24:30 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-01-10 17:28:03 +00:00
|
|
|
return label.ParseMapValue(labelName, aws.StringValue(value))
|
2017-12-16 19:24:30 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
// Deprecated
|
2017-12-02 18:30:16 +00:00
|
|
|
func hasFirst(instances []ecsInstance, labelName string) bool {
|
2017-12-16 19:24:30 +00:00
|
|
|
if len(instances) == 0 {
|
|
|
|
return false
|
2017-12-02 18:30:16 +00:00
|
|
|
}
|
2017-12-16 19:24:30 +00:00
|
|
|
return hasLabel(instances[0], labelName)
|
2017-12-02 18:30:16 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
// Deprecated
|
2017-12-02 18:30:16 +00:00
|
|
|
func getFirstStringValue(instances []ecsInstance, labelName string, defaultValue string) string {
|
|
|
|
if len(instances) == 0 {
|
|
|
|
return defaultValue
|
|
|
|
}
|
|
|
|
return getStringValue(instances[0], labelName, defaultValue)
|
|
|
|
}
|
|
|
|
|
2018-01-10 17:28:03 +00:00
|
|
|
// Deprecated
|
|
|
|
func getFirstBoolValue(instances []ecsInstance, labelName string, defaultValue bool) bool {
|
|
|
|
if len(instances) == 0 {
|
|
|
|
return defaultValue
|
|
|
|
}
|
|
|
|
return getBoolValue(instances[0], labelName, defaultValue)
|
|
|
|
}
|
|
|
|
|
2017-12-20 21:59:57 +00:00
|
|
|
func mapPToMap(src map[string]*string) map[string]string {
|
|
|
|
result := make(map[string]string)
|
|
|
|
for key, value := range src {
|
2018-01-10 17:28:03 +00:00
|
|
|
if value != nil && len(aws.StringValue(value)) > 0 {
|
|
|
|
result[key] = aws.StringValue(value)
|
2017-12-20 21:59:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2017-12-02 18:30:16 +00:00
|
|
|
func isEnabled(i ecsInstance, exposedByDefault bool) bool {
|
|
|
|
return getBoolValue(i, label.TraefikEnable, exposedByDefault)
|
|
|
|
}
|