2013-12-20 01:14:46 +00:00
|
|
|
package agent
|
|
|
|
|
2013-12-20 23:33:13 +00:00
|
|
|
import (
|
2017-05-19 09:53:41 +00:00
|
|
|
"crypto/tls"
|
2013-12-21 00:39:32 +00:00
|
|
|
"encoding/base64"
|
|
|
|
"encoding/json"
|
2017-06-06 23:11:56 +00:00
|
|
|
"errors"
|
2013-12-21 00:39:32 +00:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2014-04-11 22:22:35 +00:00
|
|
|
"net"
|
2013-12-21 00:39:32 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2013-12-27 22:49:35 +00:00
|
|
|
"sort"
|
2013-12-21 00:39:32 +00:00
|
|
|
"strings"
|
2014-01-15 22:17:40 +00:00
|
|
|
"time"
|
2014-06-16 21:36:12 +00:00
|
|
|
|
pkg refactor
command/agent/* -> agent/*
command/consul/* -> agent/consul/*
command/agent/command{,_test}.go -> command/agent{,_test}.go
command/base/command.go -> command/base.go
command/base/* -> command/*
commands.go -> command/commands.go
The script which did the refactor is:
(
cd $GOPATH/src/github.com/hashicorp/consul
git mv command/agent/command.go command/agent.go
git mv command/agent/command_test.go command/agent_test.go
git mv command/agent/flag_slice_value{,_test}.go command/
git mv command/agent .
git mv command/base/command.go command/base.go
git mv command/base/config_util{,_test}.go command/
git mv commands.go command/
git mv consul agent
rmdir command/base/
gsed -i -e 's|package agent|package command|' command/agent{,_test}.go
gsed -i -e 's|package agent|package command|' command/flag_slice_value{,_test}.go
gsed -i -e 's|package base|package command|' command/base.go command/config_util{,_test}.go
gsed -i -e 's|package main|package command|' command/commands.go
gsed -i -e 's|base.Command|BaseCommand|' command/commands.go
gsed -i -e 's|agent.Command|AgentCommand|' command/commands.go
gsed -i -e 's|\tCommand:|\tBaseCommand:|' command/commands.go
gsed -i -e 's|base\.||' command/commands.go
gsed -i -e 's|command\.||' command/commands.go
gsed -i -e 's|command|c|' main.go
gsed -i -e 's|range Commands|range command.Commands|' main.go
gsed -i -e 's|Commands: Commands|Commands: command.Commands|' main.go
gsed -i -e 's|base\.BoolValue|BoolValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.DurationValue|DurationValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.StringValue|StringValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.UintValue|UintValue|' command/operator_autopilot_set.go
gsed -i -e 's|\bCommand\b|BaseCommand|' command/base.go
gsed -i -e 's|BaseCommand Options|Command Options|' command/base.go
gsed -i -e 's|base.Command|BaseCommand|' command/*.go
gsed -i -e 's|c\.Command|c.BaseCommand|g' command/*.go
gsed -i -e 's|\tCommand:|\tBaseCommand:|' command/*_test.go
gsed -i -e 's|base\.||' command/*_test.go
gsed -i -e 's|\bCommand\b|AgentCommand|' command/agent{,_test}.go
gsed -i -e 's|cmd.AgentCommand|cmd.BaseCommand|' command/agent.go
gsed -i -e 's|cli.AgentCommand = new(Command)|cli.Command = new(AgentCommand)|' command/agent_test.go
gsed -i -e 's|exec.AgentCommand|exec.Command|' command/agent_test.go
gsed -i -e 's|exec.BaseCommand|exec.Command|' command/agent_test.go
gsed -i -e 's|NewTestAgent|agent.NewTestAgent|' command/agent_test.go
gsed -i -e 's|= TestConfig|= agent.TestConfig|' command/agent_test.go
gsed -i -e 's|: RetryJoin|: agent.RetryJoin|' command/agent_test.go
gsed -i -e 's|\.\./\.\./|../|' command/config_util_test.go
gsed -i -e 's|\bverifyUniqueListeners|VerifyUniqueListeners|' agent/config{,_test}.go command/agent.go
gsed -i -e 's|\bserfLANKeyring\b|SerfLANKeyring|g' agent/{agent,keyring,testagent}.go command/agent.go
gsed -i -e 's|\bserfWANKeyring\b|SerfWANKeyring|g' agent/{agent,keyring,testagent}.go command/agent.go
gsed -i -e 's|\bNewAgent\b|agent.New|g' command/agent{,_test}.go
gsed -i -e 's|\bNewAgent|New|' agent/{acl_test,agent,testagent}.go
gsed -i -e 's|\bAgent\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bBool\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bDefaultConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bDevConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bMergeConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bReadConfigPaths\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bParseMetaPair\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bSerfLANKeyring\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bSerfWANKeyring\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|circonus\.agent|circonus|g' command/agent{,_test}.go
gsed -i -e 's|logger\.agent|logger|g' command/agent{,_test}.go
gsed -i -e 's|metrics\.agent|metrics|g' command/agent{,_test}.go
gsed -i -e 's|// agent.Agent|// agent|' command/agent{,_test}.go
gsed -i -e 's|a\.agent\.Config|a.Config|' command/agent{,_test}.go
gsed -i -e 's|agent\.AppendSliceValue|AppendSliceValue|' command/{configtest,validate}.go
gsed -i -e 's|consul/consul|agent/consul|' GNUmakefile
gsed -i -e 's|\.\./test|../../test|' agent/consul/server_test.go
# fix imports
f=$(grep -rl 'github.com/hashicorp/consul/command/agent' * | grep '\.go')
gsed -i -e 's|github.com/hashicorp/consul/command/agent|github.com/hashicorp/consul/agent|' $f
goimports -w $f
f=$(grep -rl 'github.com/hashicorp/consul/consul' * | grep '\.go')
gsed -i -e 's|github.com/hashicorp/consul/consul|github.com/hashicorp/consul/agent/consul|' $f
goimports -w $f
goimports -w command/*.go main.go
)
2017-06-09 22:28:28 +00:00
|
|
|
"github.com/hashicorp/consul/agent/consul"
|
2016-01-29 19:42:34 +00:00
|
|
|
"github.com/hashicorp/consul/lib"
|
2017-04-27 08:29:39 +00:00
|
|
|
"github.com/hashicorp/consul/tlsutil"
|
2017-01-18 06:20:11 +00:00
|
|
|
"github.com/hashicorp/consul/types"
|
2014-08-21 20:09:13 +00:00
|
|
|
"github.com/hashicorp/consul/watch"
|
2014-06-16 21:36:12 +00:00
|
|
|
"github.com/mitchellh/mapstructure"
|
2013-12-20 23:33:13 +00:00
|
|
|
)
|
|
|
|
|
2014-04-11 22:22:35 +00:00
|
|
|
// Ports is used to simplify the configuration by
|
|
|
|
// providing default ports, and allowing the addresses
|
|
|
|
// to only be specified once
|
|
|
|
type PortConfig struct {
|
|
|
|
DNS int // DNS Query interface
|
|
|
|
HTTP int // HTTP API
|
2014-11-14 19:39:19 +00:00
|
|
|
HTTPS int // HTTPS API
|
2014-04-11 22:22:35 +00:00
|
|
|
SerfLan int `mapstructure:"serf_lan"` // LAN gossip (Client + Server)
|
2015-09-15 12:22:08 +00:00
|
|
|
SerfWan int `mapstructure:"serf_wan"` // WAN gossip (Server only)
|
2014-04-11 22:22:35 +00:00
|
|
|
Server int // Server internal RPC
|
2017-03-23 21:10:14 +00:00
|
|
|
|
|
|
|
// RPC is deprecated and is no longer used. It will be removed in a future
|
|
|
|
// version.
|
|
|
|
RPC int // CLI RPC
|
2014-04-11 22:22:35 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 19:42:14 +00:00
|
|
|
// AddressConfig is used to provide address overrides
|
|
|
|
// for specific services. By default, either ClientAddress
|
|
|
|
// or ServerAddress is used.
|
|
|
|
type AddressConfig struct {
|
2014-11-14 19:39:19 +00:00
|
|
|
DNS string // DNS Query interface
|
|
|
|
HTTP string // HTTP API
|
|
|
|
HTTPS string // HTTPS API
|
2017-03-23 21:10:14 +00:00
|
|
|
|
|
|
|
// RPC is deprecated and is no longer used. It will be removed in a future
|
|
|
|
// version.
|
|
|
|
RPC string // CLI RPC
|
2014-09-02 19:42:14 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 11:44:42 +00:00
|
|
|
type AdvertiseAddrsConfig struct {
|
|
|
|
SerfLan *net.TCPAddr `mapstructure:"-"`
|
|
|
|
SerfLanRaw string `mapstructure:"serf_lan"`
|
|
|
|
SerfWan *net.TCPAddr `mapstructure:"-"`
|
|
|
|
SerfWanRaw string `mapstructure:"serf_wan"`
|
|
|
|
RPC *net.TCPAddr `mapstructure:"-"`
|
|
|
|
RPCRaw string `mapstructure:"rpc"`
|
|
|
|
}
|
|
|
|
|
2014-06-08 20:14:07 +00:00
|
|
|
// DNSConfig is used to fine tune the DNS sub-system.
|
|
|
|
// It can be used to control cache values, and stale
|
|
|
|
// reads
|
|
|
|
type DNSConfig struct {
|
|
|
|
// NodeTTL provides the TTL value for a node query
|
|
|
|
NodeTTL time.Duration `mapstructure:"-"`
|
|
|
|
NodeTTLRaw string `mapstructure:"node_ttl" json:"-"`
|
|
|
|
|
|
|
|
// ServiceTTL provides the TTL value for a service
|
|
|
|
// query for given service. The "*" wildcard can be used
|
|
|
|
// to set a default for all services.
|
|
|
|
ServiceTTL map[string]time.Duration `mapstructure:"-"`
|
|
|
|
ServiceTTLRaw map[string]string `mapstructure:"service_ttl" json:"-"`
|
|
|
|
|
|
|
|
// AllowStale is used to enable lookups with stale
|
|
|
|
// data. This gives horizontal read scalability since
|
|
|
|
// any Consul server can service the query instead of
|
|
|
|
// only the leader.
|
2016-08-30 20:40:43 +00:00
|
|
|
AllowStale *bool `mapstructure:"allow_stale"`
|
2014-06-08 20:14:07 +00:00
|
|
|
|
2014-09-30 19:15:36 +00:00
|
|
|
// EnableTruncate is used to enable setting the truncate
|
|
|
|
// flag for UDP DNS queries. This allows unmodified
|
|
|
|
// clients to re-query the consul server using TCP
|
|
|
|
// when the total number of records exceeds the number
|
|
|
|
// returned by default for UDP.
|
|
|
|
EnableTruncate bool `mapstructure:"enable_truncate"`
|
|
|
|
|
2016-02-12 07:58:48 +00:00
|
|
|
// UDPAnswerLimit is used to limit the maximum number of DNS Resource
|
|
|
|
// Records returned in the ANSWER section of a DNS response. This is
|
|
|
|
// not normally useful and will be limited based on the querying
|
|
|
|
// protocol, however systems that implemented §6 Rule 9 in RFC3484
|
2016-03-30 08:15:40 +00:00
|
|
|
// may want to set this to `1` in order to subvert §6 Rule 9 and
|
|
|
|
// re-obtain the effect of randomized resource records (i.e. each
|
|
|
|
// answer contains only one IP, but the IP changes every request).
|
2016-02-12 07:58:48 +00:00
|
|
|
// RFC3484 sorts answers in a deterministic order, which defeats the
|
2016-03-30 08:15:40 +00:00
|
|
|
// purpose of randomized DNS responses. This RFC has been obsoleted
|
|
|
|
// by RFC6724 and restores the desired behavior of randomized
|
|
|
|
// responses, however a large number of Linux hosts using glibc(3)
|
|
|
|
// implemented §6 Rule 9 and may need this option (e.g. CentOS 5-6,
|
|
|
|
// Debian Squeeze, etc).
|
2016-02-12 07:58:48 +00:00
|
|
|
UDPAnswerLimit int `mapstructure:"udp_answer_limit"`
|
2016-01-09 06:36:38 +00:00
|
|
|
|
2014-06-08 20:14:07 +00:00
|
|
|
// MaxStale is used to bound how stale of a result is
|
|
|
|
// accepted for a DNS lookup. This can be used with
|
|
|
|
// AllowStale to limit how old of a value is served up.
|
|
|
|
// If the stale result exceeds this, another non-stale
|
|
|
|
// stale read is performed.
|
|
|
|
MaxStale time.Duration `mapstructure:"-"`
|
|
|
|
MaxStaleRaw string `mapstructure:"max_stale" json:"-"`
|
2015-01-10 12:11:32 +00:00
|
|
|
|
|
|
|
// OnlyPassing is used to determine whether to filter nodes
|
|
|
|
// whose health checks are in any non-passing state. By
|
|
|
|
// default, only nodes in a critical state are excluded.
|
|
|
|
OnlyPassing bool `mapstructure:"only_passing"`
|
2016-08-11 23:24:44 +00:00
|
|
|
|
|
|
|
// DisableCompression is used to control whether DNS responses are
|
|
|
|
// compressed. In Consul 0.7 this was turned on by default and this
|
|
|
|
// config was added as an opt-out.
|
|
|
|
DisableCompression bool `mapstructure:"disable_compression"`
|
2016-08-23 20:59:38 +00:00
|
|
|
|
2016-08-26 19:22:04 +00:00
|
|
|
// RecursorTimeout specifies the timeout in seconds
|
|
|
|
// for Consul's internal dns client used for recursion.
|
|
|
|
// This value is used for the connection, read and write timeout.
|
2016-08-23 20:59:38 +00:00
|
|
|
// Default: 2s
|
2016-09-02 05:14:19 +00:00
|
|
|
RecursorTimeout time.Duration `mapstructure:"-"`
|
|
|
|
RecursorTimeoutRaw string `mapstructure:"recursor_timeout" json:"-"`
|
2014-06-08 20:14:07 +00:00
|
|
|
}
|
|
|
|
|
2016-11-02 18:35:37 +00:00
|
|
|
// RetryJoinEC2 is used to configure discovery of instances via Amazon's EC2 api
|
|
|
|
type RetryJoinEC2 struct {
|
2016-11-01 18:45:42 +00:00
|
|
|
// The AWS region to look for instances in
|
|
|
|
Region string `mapstructure:"region"`
|
|
|
|
|
|
|
|
// The tag key and value to use when filtering instances
|
|
|
|
TagKey string `mapstructure:"tag_key"`
|
|
|
|
TagValue string `mapstructure:"tag_value"`
|
|
|
|
|
|
|
|
// The AWS credentials to use for making requests to EC2
|
2017-01-26 05:01:07 +00:00
|
|
|
AccessKeyID string `mapstructure:"access_key_id" json:"-"`
|
|
|
|
SecretAccessKey string `mapstructure:"secret_access_key" json:"-"`
|
2016-11-01 18:45:42 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 08:07:53 +00:00
|
|
|
// RetryJoinGCE is used to configure discovery of instances via Google Compute
|
|
|
|
// Engine's API.
|
|
|
|
type RetryJoinGCE struct {
|
|
|
|
// The name of the project the instances reside in.
|
|
|
|
ProjectName string `mapstructure:"project_name"`
|
|
|
|
|
|
|
|
// A regular expression (RE2) pattern for the zones you want to discover the instances in.
|
|
|
|
// Example: us-west1-.*, or us-(?west|east).*.
|
|
|
|
ZonePattern string `mapstructure:"zone_pattern"`
|
|
|
|
|
|
|
|
// The tag value to search for when filtering instances.
|
|
|
|
TagValue string `mapstructure:"tag_value"`
|
|
|
|
|
|
|
|
// A path to a JSON file with the service account credentials necessary to
|
|
|
|
// connect to GCE. If this is not defined, the following chain is respected:
|
|
|
|
// 1. A JSON file whose path is specified by the
|
|
|
|
// GOOGLE_APPLICATION_CREDENTIALS environment variable.
|
|
|
|
// 2. A JSON file in a location known to the gcloud command-line tool.
|
|
|
|
// On Windows, this is %APPDATA%/gcloud/application_default_credentials.json.
|
|
|
|
// On other systems, $HOME/.config/gcloud/application_default_credentials.json.
|
|
|
|
// 3. On Google Compute Engine, it fetches credentials from the metadata
|
|
|
|
// server. (In this final case any provided scopes are ignored.)
|
|
|
|
CredentialsFile string `mapstructure:"credentials_file"`
|
|
|
|
}
|
|
|
|
|
2017-05-24 07:19:23 +00:00
|
|
|
// RetryJoinAzure is used to configure discovery of instances via AzureRM API
|
|
|
|
type RetryJoinAzure struct {
|
|
|
|
// The tag name and value to use when filtering instances
|
|
|
|
TagName string `mapstructure:"tag_name"`
|
|
|
|
TagValue string `mapstructure:"tag_value"`
|
|
|
|
|
|
|
|
// The Azure credentials to use for making requests to AzureRM
|
|
|
|
SubscriptionID string `mapstructure:"subscription_id" json:"-"`
|
|
|
|
TenantID string `mapstructure:"tenant_id" json:"-"`
|
|
|
|
ClientID string `mapstructure:"client_id" json:"-"`
|
|
|
|
SecretAccessKey string `mapstructure:"secret_access_key" json:"-"`
|
|
|
|
}
|
|
|
|
|
2016-08-25 00:33:53 +00:00
|
|
|
// Performance is used to tune the performance of Consul's subsystems.
|
|
|
|
type Performance struct {
|
|
|
|
// RaftMultiplier is an integer multiplier used to scale Raft timing
|
2016-08-25 22:05:40 +00:00
|
|
|
// parameters: HeartbeatTimeout, ElectionTimeout, and LeaderLeaseTimeout.
|
2016-08-25 00:33:53 +00:00
|
|
|
RaftMultiplier uint `mapstructure:"raft_multiplier"`
|
2014-06-08 20:14:07 +00:00
|
|
|
}
|
|
|
|
|
2015-10-08 19:45:45 +00:00
|
|
|
// Telemetry is the telemetry configuration for the server
|
|
|
|
type Telemetry struct {
|
|
|
|
// StatsiteAddr is the address of a statsite instance. If provided,
|
|
|
|
// metrics will be streamed to that instance.
|
|
|
|
StatsiteAddr string `mapstructure:"statsite_address"`
|
|
|
|
|
|
|
|
// StatsdAddr is the address of a statsd instance. If provided,
|
|
|
|
// metrics will be sent to that instance.
|
|
|
|
StatsdAddr string `mapstructure:"statsd_address"`
|
|
|
|
|
|
|
|
// StatsitePrefix is the prefix used to write stats values to. By
|
|
|
|
// default this is set to 'consul'.
|
|
|
|
StatsitePrefix string `mapstructure:"statsite_prefix"`
|
|
|
|
|
|
|
|
// DisableHostname will disable hostname prefixing for all metrics
|
|
|
|
DisableHostname bool `mapstructure:"disable_hostname"`
|
|
|
|
|
|
|
|
// DogStatsdAddr is the address of a dogstatsd instance. If provided,
|
|
|
|
// metrics will be sent to that instance
|
|
|
|
DogStatsdAddr string `mapstructure:"dogstatsd_addr"`
|
|
|
|
|
|
|
|
// DogStatsdTags are the global tags that should be sent with each packet to dogstatsd
|
|
|
|
// It is a list of strings, where each string looks like "my_tag_name:my_tag_value"
|
|
|
|
DogStatsdTags []string `mapstructure:"dogstatsd_tags"`
|
2016-07-18 13:34:43 +00:00
|
|
|
|
|
|
|
// Circonus: see https://github.com/circonus-labs/circonus-gometrics
|
|
|
|
// for more details on the various configuration options.
|
|
|
|
// Valid configuration combinations:
|
|
|
|
// - CirconusAPIToken
|
|
|
|
// metric management enabled (search for existing check or create a new one)
|
|
|
|
// - CirconusSubmissionUrl
|
|
|
|
// metric management disabled (use check with specified submission_url,
|
|
|
|
// broker must be using a public SSL certificate)
|
|
|
|
// - CirconusAPIToken + CirconusCheckSubmissionURL
|
|
|
|
// metric management enabled (use check with specified submission_url)
|
|
|
|
// - CirconusAPIToken + CirconusCheckID
|
|
|
|
// metric management enabled (use check with specified id)
|
|
|
|
|
|
|
|
// CirconusAPIToken is a valid API Token used to create/manage check. If provided,
|
|
|
|
// metric management is enabled.
|
|
|
|
// Default: none
|
2016-08-25 06:27:25 +00:00
|
|
|
CirconusAPIToken string `mapstructure:"circonus_api_token" json:"-"`
|
2016-07-18 13:34:43 +00:00
|
|
|
// CirconusAPIApp is an app name associated with API token.
|
2016-07-18 19:46:11 +00:00
|
|
|
// Default: "consul"
|
2016-07-18 13:34:43 +00:00
|
|
|
CirconusAPIApp string `mapstructure:"circonus_api_app"`
|
|
|
|
// CirconusAPIURL is the base URL to use for contacting the Circonus API.
|
|
|
|
// Default: "https://api.circonus.com/v2"
|
|
|
|
CirconusAPIURL string `mapstructure:"circonus_api_url"`
|
2016-07-18 19:46:11 +00:00
|
|
|
// CirconusSubmissionInterval is the interval at which metrics are submitted to Circonus.
|
2016-07-18 13:34:43 +00:00
|
|
|
// Default: 10s
|
2016-07-18 19:46:11 +00:00
|
|
|
CirconusSubmissionInterval string `mapstructure:"circonus_submission_interval"`
|
2016-07-18 13:34:43 +00:00
|
|
|
// CirconusCheckSubmissionURL is the check.config.submission_url field from a
|
|
|
|
// previously created HTTPTRAP check.
|
|
|
|
// Default: none
|
|
|
|
CirconusCheckSubmissionURL string `mapstructure:"circonus_submission_url"`
|
|
|
|
// CirconusCheckID is the check id (not check bundle id) from a previously created
|
|
|
|
// HTTPTRAP check. The numeric portion of the check._cid field.
|
|
|
|
// Default: none
|
|
|
|
CirconusCheckID string `mapstructure:"circonus_check_id"`
|
|
|
|
// CirconusCheckForceMetricActivation will force enabling metrics, as they are encountered,
|
|
|
|
// if the metric already exists and is NOT active. If check management is enabled, the default
|
|
|
|
// behavior is to add new metrics as they are encoutered. If the metric already exists in the
|
|
|
|
// check, it will *NOT* be activated. This setting overrides that behavior.
|
|
|
|
// Default: "false"
|
|
|
|
CirconusCheckForceMetricActivation string `mapstructure:"circonus_check_force_metric_activation"`
|
2016-07-19 22:54:52 +00:00
|
|
|
// CirconusCheckInstanceID serves to uniquely identify the metrics coming from this "instance".
|
2016-07-18 13:34:43 +00:00
|
|
|
// It can be used to maintain metric continuity with transient or ephemeral instances as
|
|
|
|
// they move around within an infrastructure.
|
|
|
|
// Default: hostname:app
|
|
|
|
CirconusCheckInstanceID string `mapstructure:"circonus_check_instance_id"`
|
2016-07-18 19:46:11 +00:00
|
|
|
// CirconusCheckSearchTag is a special tag which, when coupled with the instance id, helps to
|
2016-07-18 13:34:43 +00:00
|
|
|
// narrow down the search results when neither a Submission URL or Check ID is provided.
|
|
|
|
// Default: service:app (e.g. service:consul)
|
|
|
|
CirconusCheckSearchTag string `mapstructure:"circonus_check_search_tag"`
|
2016-11-09 20:33:37 +00:00
|
|
|
// CirconusCheckTags is a comma separated list of tags to apply to the check. Note that
|
|
|
|
// the value of CirconusCheckSearchTag will always be added to the check.
|
|
|
|
// Default: none
|
|
|
|
CirconusCheckTags string `mapstructure:"circonus_check_tags"`
|
|
|
|
// CirconusCheckDisplayName is the name for the check which will be displayed in the Circonus UI.
|
|
|
|
// Default: value of CirconusCheckInstanceID
|
|
|
|
CirconusCheckDisplayName string `mapstructure:"circonus_check_display_name"`
|
2016-07-18 13:34:43 +00:00
|
|
|
// CirconusBrokerID is an explicit broker to use when creating a new check. The numeric portion
|
|
|
|
// of broker._cid. If metric management is enabled and neither a Submission URL nor Check ID
|
|
|
|
// is provided, an attempt will be made to search for an existing check using Instance ID and
|
|
|
|
// Search Tag. If one is not found, a new HTTPTRAP check will be created.
|
|
|
|
// Default: use Select Tag if provided, otherwise, a random Enterprise Broker associated
|
|
|
|
// with the specified API token or the default Circonus Broker.
|
|
|
|
// Default: none
|
|
|
|
CirconusBrokerID string `mapstructure:"circonus_broker_id"`
|
|
|
|
// CirconusBrokerSelectTag is a special tag which will be used to select a broker when
|
|
|
|
// a Broker ID is not provided. The best use of this is to as a hint for which broker
|
|
|
|
// should be used based on *where* this particular instance is running.
|
|
|
|
// (e.g. a specific geo location or datacenter, dc:sfo)
|
|
|
|
// Default: none
|
2016-07-19 22:46:57 +00:00
|
|
|
CirconusBrokerSelectTag string `mapstructure:"circonus_broker_select_tag"`
|
2015-10-08 19:45:45 +00:00
|
|
|
}
|
|
|
|
|
2017-02-22 20:53:32 +00:00
|
|
|
// Autopilot is used to configure helpful features for operating Consul servers.
|
|
|
|
type Autopilot struct {
|
2017-02-28 22:23:14 +00:00
|
|
|
// CleanupDeadServers enables the automatic cleanup of dead servers when new ones
|
2017-02-22 20:53:32 +00:00
|
|
|
// are added to the peer list. Defaults to true.
|
2017-02-28 22:23:14 +00:00
|
|
|
CleanupDeadServers *bool `mapstructure:"cleanup_dead_servers"`
|
2017-03-01 22:04:40 +00:00
|
|
|
|
|
|
|
// LastContactThreshold is the limit on the amount of time a server can go
|
|
|
|
// without leader contact before being considered unhealthy.
|
|
|
|
LastContactThreshold *time.Duration `mapstructure:"-" json:"-"`
|
|
|
|
LastContactThresholdRaw string `mapstructure:"last_contact_threshold"`
|
|
|
|
|
|
|
|
// MaxTrailingLogs is the amount of entries in the Raft Log that a server can
|
|
|
|
// be behind before being considered unhealthy.
|
|
|
|
MaxTrailingLogs *uint64 `mapstructure:"max_trailing_logs"`
|
|
|
|
|
|
|
|
// ServerStabilizationTime is the minimum amount of time a server must be
|
|
|
|
// in a stable, healthy state before it can be added to the cluster. Only
|
|
|
|
// applicable with Raft protocol version 3 or higher.
|
|
|
|
ServerStabilizationTime *time.Duration `mapstructure:"-" json:"-"`
|
|
|
|
ServerStabilizationTimeRaw string `mapstructure:"server_stabilization_time"`
|
2017-03-21 23:36:44 +00:00
|
|
|
|
|
|
|
// (Enterprise-only) RedundancyZoneTag is the Meta tag to use for separating servers
|
|
|
|
// into zones for redundancy. If left blank, this feature will be disabled.
|
|
|
|
RedundancyZoneTag string `mapstructure:"redundancy_zone_tag"`
|
|
|
|
|
|
|
|
// (Enterprise-only) DisableUpgradeMigration will disable Autopilot's upgrade migration
|
|
|
|
// strategy of waiting until enough newer-versioned servers have been added to the
|
|
|
|
// cluster before promoting them to voters.
|
|
|
|
DisableUpgradeMigration *bool `mapstructure:"disable_upgrade_migration"`
|
2017-02-22 20:53:32 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 01:14:46 +00:00
|
|
|
// Config is the configuration that can be set for an Agent.
|
|
|
|
// Some of this is configurable as CLI flags, but most must
|
|
|
|
// be set using a configuration file.
|
|
|
|
type Config struct {
|
2016-08-25 00:33:53 +00:00
|
|
|
// DevMode enables a fast-path mode of operation to bring up an in-memory
|
2015-11-29 04:40:05 +00:00
|
|
|
// server with minimal configuration. Useful for developing Consul.
|
|
|
|
DevMode bool `mapstructure:"-"`
|
|
|
|
|
2016-08-25 00:33:53 +00:00
|
|
|
// Performance is used to tune the performance of Consul's subsystems.
|
|
|
|
Performance Performance `mapstructure:"performance"`
|
|
|
|
|
2013-12-25 00:48:07 +00:00
|
|
|
// Bootstrap is used to bring up the first Consul server, and
|
|
|
|
// permits that node to elect itself leader
|
2014-02-07 19:49:51 +00:00
|
|
|
Bootstrap bool `mapstructure:"bootstrap"`
|
2013-12-25 00:48:07 +00:00
|
|
|
|
2014-06-20 00:08:48 +00:00
|
|
|
// BootstrapExpect tries to automatically bootstrap the Consul cluster,
|
2015-09-15 12:22:08 +00:00
|
|
|
// by withholding peers until enough servers join.
|
2014-06-20 00:08:48 +00:00
|
|
|
BootstrapExpect int `mapstructure:"bootstrap_expect"`
|
2014-06-16 21:36:12 +00:00
|
|
|
|
2014-04-11 22:22:35 +00:00
|
|
|
// Server controls if this agent acts like a Consul server,
|
|
|
|
// or merely as a client. Servers have more state, take part
|
|
|
|
// in leader election, etc.
|
|
|
|
Server bool `mapstructure:"server"`
|
|
|
|
|
2017-03-21 23:36:44 +00:00
|
|
|
// (Enterprise-only) NonVotingServer is whether this server will act as a non-voting member
|
|
|
|
// of the cluster to help provide read scalability.
|
|
|
|
NonVotingServer bool `mapstructure:"non_voting_server"`
|
|
|
|
|
2013-12-20 23:33:13 +00:00
|
|
|
// Datacenter is the datacenter this node is in. Defaults to dc1
|
2014-02-07 19:49:51 +00:00
|
|
|
Datacenter string `mapstructure:"datacenter"`
|
2013-12-20 23:33:13 +00:00
|
|
|
|
|
|
|
// DataDir is the directory to store our state in
|
2014-02-07 19:49:51 +00:00
|
|
|
DataDir string `mapstructure:"data_dir"`
|
2013-12-20 23:33:13 +00:00
|
|
|
|
2014-11-03 19:28:21 +00:00
|
|
|
// DNSRecursors can be set to allow the DNS servers to recursively
|
|
|
|
// resolve non-consul domains. It is deprecated, and merges into the
|
|
|
|
// recursors array.
|
|
|
|
DNSRecursor string `mapstructure:"recursor"`
|
|
|
|
|
2014-10-31 19:19:41 +00:00
|
|
|
// DNSRecursors can be set to allow the DNS servers to recursively
|
2014-01-03 23:43:35 +00:00
|
|
|
// resolve non-consul domains
|
2014-10-31 19:19:41 +00:00
|
|
|
DNSRecursors []string `mapstructure:"recursors"`
|
2014-01-03 23:43:35 +00:00
|
|
|
|
2014-06-08 20:14:07 +00:00
|
|
|
// DNS configuration
|
|
|
|
DNSConfig DNSConfig `mapstructure:"dns_config"`
|
|
|
|
|
2014-01-02 23:50:52 +00:00
|
|
|
// Domain is the DNS domain for the records. Defaults to "consul."
|
2014-02-07 19:49:51 +00:00
|
|
|
Domain string `mapstructure:"domain"`
|
2014-01-02 23:50:52 +00:00
|
|
|
|
2013-12-21 00:39:32 +00:00
|
|
|
// Encryption key to use for the Serf communication
|
2014-05-29 18:24:37 +00:00
|
|
|
EncryptKey string `mapstructure:"encrypt" json:"-"`
|
2013-12-21 00:39:32 +00:00
|
|
|
|
2017-05-30 15:51:37 +00:00
|
|
|
// EncryptVerifyIncoming and EncryptVerifyOutgoing are used to enforce
|
|
|
|
// incoming/outgoing gossip encryption and can be used to upshift to
|
|
|
|
// encrypted gossip on a running cluster.
|
|
|
|
EncryptVerifyIncoming *bool `mapstructure:"encrypt_verify_incoming"`
|
|
|
|
EncryptVerifyOutgoing *bool `mapstructure:"encrypt_verify_outgoing"`
|
|
|
|
|
2013-12-20 23:33:13 +00:00
|
|
|
// LogLevel is the level of the logs to putout
|
2014-02-07 19:49:51 +00:00
|
|
|
LogLevel string `mapstructure:"log_level"`
|
2013-12-20 23:33:13 +00:00
|
|
|
|
2017-01-18 06:20:11 +00:00
|
|
|
// Node ID is a unique ID for this node across space and time. Defaults
|
|
|
|
// to a randomly-generated ID that persists in the data-dir.
|
|
|
|
NodeID types.NodeID `mapstructure:"node_id"`
|
|
|
|
|
2017-04-13 05:05:38 +00:00
|
|
|
// DisableHostNodeID will prevent Consul from using information from the
|
|
|
|
// host to generate a node ID, and will cause Consul to generate a
|
|
|
|
// random ID instead.
|
|
|
|
DisableHostNodeID bool `mapstructure:"disable_host_node_id"`
|
|
|
|
|
2013-12-20 23:33:13 +00:00
|
|
|
// Node name is the name we use to advertise. Defaults to hostname.
|
2014-02-07 19:49:51 +00:00
|
|
|
NodeName string `mapstructure:"node_name"`
|
2013-12-20 23:33:13 +00:00
|
|
|
|
2014-04-11 22:22:35 +00:00
|
|
|
// ClientAddr is used to control the address we bind to for
|
2014-11-14 19:39:19 +00:00
|
|
|
// client services (DNS, HTTP, HTTPS, RPC)
|
2014-04-11 22:22:35 +00:00
|
|
|
ClientAddr string `mapstructure:"client_addr"`
|
2013-12-20 23:33:13 +00:00
|
|
|
|
2014-04-11 22:22:35 +00:00
|
|
|
// BindAddr is used to control the address we bind to.
|
|
|
|
// If not specified, the first private IP we find is used.
|
|
|
|
// This controls the address we use for cluster facing
|
|
|
|
// services (Gossip, Server RPC)
|
|
|
|
BindAddr string `mapstructure:"bind_addr"`
|
2013-12-20 23:33:13 +00:00
|
|
|
|
2016-11-03 19:58:58 +00:00
|
|
|
// SerfWanBindAddr is used to control the address we bind to.
|
|
|
|
// If not specified, the first private IP we find is used.
|
|
|
|
// This controls the address we use for cluster facing
|
|
|
|
// services (Gossip) Serf
|
|
|
|
SerfWanBindAddr string `mapstructure:"serf_wan_bind"`
|
|
|
|
|
|
|
|
// SerfLanBindAddr is used to control the address we bind to.
|
|
|
|
// If not specified, the first private IP we find is used.
|
|
|
|
// This controls the address we use for cluster facing
|
|
|
|
// services (Gossip) Serf
|
|
|
|
SerfLanBindAddr string `mapstructure:"serf_lan_bind"`
|
|
|
|
|
2014-01-01 00:45:13 +00:00
|
|
|
// AdvertiseAddr is the address we use for advertising our Serf,
|
2014-04-11 22:22:35 +00:00
|
|
|
// and Consul RPC IP. If not specified, bind address is used.
|
2014-02-07 19:49:51 +00:00
|
|
|
AdvertiseAddr string `mapstructure:"advertise_addr"`
|
2014-01-01 00:45:13 +00:00
|
|
|
|
2015-06-05 11:44:42 +00:00
|
|
|
// AdvertiseAddrs configuration
|
|
|
|
AdvertiseAddrs AdvertiseAddrsConfig `mapstructure:"advertise_addrs"`
|
|
|
|
|
2015-03-21 09:14:03 +00:00
|
|
|
// AdvertiseAddrWan is the address we use for advertising our
|
|
|
|
// Serf WAN IP. If not specified, the general advertise address is used.
|
|
|
|
AdvertiseAddrWan string `mapstructure:"advertise_addr_wan"`
|
|
|
|
|
2015-12-22 11:31:40 +00:00
|
|
|
// TranslateWanAddrs controls whether or not Consul should prefer
|
2016-02-07 18:37:34 +00:00
|
|
|
// the "wan" tagged address when doing lookups in remote datacenters.
|
|
|
|
// See TaggedAddresses below for more details.
|
2015-12-22 11:31:40 +00:00
|
|
|
TranslateWanAddrs bool `mapstructure:"translate_wan_addrs"`
|
|
|
|
|
2014-04-11 22:22:35 +00:00
|
|
|
// Port configurations
|
|
|
|
Ports PortConfig
|
2013-12-20 23:33:13 +00:00
|
|
|
|
2014-09-02 19:42:14 +00:00
|
|
|
// Address configurations
|
|
|
|
Addresses AddressConfig
|
|
|
|
|
2016-02-07 18:37:34 +00:00
|
|
|
// Tagged addresses. These are used to publish a set of addresses for
|
|
|
|
// for a node, which can be used by the remote agent. We currently
|
|
|
|
// populate only the "wan" tag based on the SerfWan advertise address,
|
|
|
|
// but this structure is here for possible future features with other
|
|
|
|
// user-defined tags. The "wan" tag will be used by remote agents if
|
|
|
|
// they are configured with TranslateWanAddrs set to true.
|
|
|
|
TaggedAddresses map[string]string
|
|
|
|
|
2017-01-11 19:41:12 +00:00
|
|
|
// Node metadata key/value pairs. These are excluded from JSON output
|
|
|
|
// because they can be reloaded and might be stale when shown from the
|
|
|
|
// config instead of the local state.
|
2017-01-05 22:10:26 +00:00
|
|
|
Meta map[string]string `mapstructure:"node_meta" json:"-"`
|
|
|
|
|
2013-12-21 00:39:32 +00:00
|
|
|
// LeaveOnTerm controls if Serf does a graceful leave when receiving
|
2016-09-01 06:39:11 +00:00
|
|
|
// the TERM signal. Defaults true on clients, false on servers. This can
|
|
|
|
// be changed on reload.
|
|
|
|
LeaveOnTerm *bool `mapstructure:"leave_on_terminate"`
|
2013-12-21 00:39:32 +00:00
|
|
|
|
2016-04-01 00:45:14 +00:00
|
|
|
// SkipLeaveOnInt controls if Serf skips a graceful leave when
|
|
|
|
// receiving the INT signal. Defaults false on clients, true on
|
|
|
|
// servers. This can be changed on reload.
|
|
|
|
SkipLeaveOnInt *bool `mapstructure:"skip_leave_on_interrupt"`
|
2013-12-21 00:39:32 +00:00
|
|
|
|
2017-02-22 20:53:32 +00:00
|
|
|
// Autopilot is used to configure helpful features for operating Consul servers.
|
|
|
|
Autopilot Autopilot `mapstructure:"autopilot"`
|
|
|
|
|
2015-10-08 19:45:45 +00:00
|
|
|
Telemetry Telemetry `mapstructure:"telemetry"`
|
2015-06-16 22:05:55 +00:00
|
|
|
|
2014-03-09 22:57:03 +00:00
|
|
|
// Protocol is the Consul protocol version to use.
|
|
|
|
Protocol int `mapstructure:"protocol"`
|
|
|
|
|
2017-02-23 21:08:40 +00:00
|
|
|
// RaftProtocol sets the Raft protocol version to use on this server.
|
|
|
|
RaftProtocol int `mapstructure:"raft_protocol"`
|
|
|
|
|
2014-03-20 00:49:57 +00:00
|
|
|
// EnableDebug is used to enable various debugging features
|
|
|
|
EnableDebug bool `mapstructure:"enable_debug"`
|
|
|
|
|
2014-04-04 23:52:39 +00:00
|
|
|
// VerifyIncoming is used to verify the authenticity of incoming connections.
|
|
|
|
// This means that TCP requests are forbidden, only allowing for TLS. TLS connections
|
|
|
|
// must match a provided certificate authority. This can be used to force client auth.
|
|
|
|
VerifyIncoming bool `mapstructure:"verify_incoming"`
|
|
|
|
|
2017-04-28 23:15:55 +00:00
|
|
|
// VerifyIncomingRPC is used to verify the authenticity of incoming RPC connections.
|
|
|
|
// This means that TCP requests are forbidden, only allowing for TLS. TLS connections
|
|
|
|
// must match a provided certificate authority. This can be used to force client auth.
|
|
|
|
VerifyIncomingRPC bool `mapstructure:"verify_incoming_rpc"`
|
|
|
|
|
|
|
|
// VerifyIncomingHTTPS is used to verify the authenticity of incoming HTTPS connections.
|
|
|
|
// This means that TCP requests are forbidden, only allowing for TLS. TLS connections
|
|
|
|
// must match a provided certificate authority. This can be used to force client auth.
|
|
|
|
VerifyIncomingHTTPS bool `mapstructure:"verify_incoming_https"`
|
|
|
|
|
2014-04-04 23:52:39 +00:00
|
|
|
// VerifyOutgoing is used to verify the authenticity of outgoing connections.
|
|
|
|
// This means that TLS requests are used. TLS connections must match a provided
|
|
|
|
// certificate authority. This is used to verify authenticity of server nodes.
|
|
|
|
VerifyOutgoing bool `mapstructure:"verify_outgoing"`
|
|
|
|
|
2015-05-11 22:13:58 +00:00
|
|
|
// VerifyServerHostname is used to enable hostname verification of servers. This
|
|
|
|
// ensures that the certificate presented is valid for server.<datacenter>.<domain>.
|
|
|
|
// This prevents a compromised client from being restarted as a server, and then
|
|
|
|
// intercepting request traffic as well as being added as a raft peer. This should be
|
|
|
|
// enabled by default with VerifyOutgoing, but for legacy reasons we cannot break
|
|
|
|
// existing clients.
|
|
|
|
VerifyServerHostname bool `mapstructure:"verify_server_hostname"`
|
|
|
|
|
2014-04-04 23:52:39 +00:00
|
|
|
// CAFile is a path to a certificate authority file. This is used with VerifyIncoming
|
|
|
|
// or VerifyOutgoing to verify the TLS connection.
|
|
|
|
CAFile string `mapstructure:"ca_file"`
|
|
|
|
|
2017-04-27 08:29:39 +00:00
|
|
|
// CAPath is a path to a directory of certificate authority files. This is used with
|
|
|
|
// VerifyIncoming or VerifyOutgoing to verify the TLS connection.
|
|
|
|
CAPath string `mapstructure:"ca_path"`
|
|
|
|
|
2014-04-04 23:52:39 +00:00
|
|
|
// CertFile is used to provide a TLS certificate that is used for serving TLS connections.
|
|
|
|
// Must be provided to serve TLS connections.
|
|
|
|
CertFile string `mapstructure:"cert_file"`
|
|
|
|
|
|
|
|
// KeyFile is used to provide a TLS key that is used for serving TLS connections.
|
|
|
|
// Must be provided to serve TLS connections.
|
|
|
|
KeyFile string `mapstructure:"key_file"`
|
|
|
|
|
2014-06-13 18:10:27 +00:00
|
|
|
// ServerName is used with the TLS certificates to ensure the name we
|
2015-09-15 12:22:08 +00:00
|
|
|
// provide matches the certificate
|
2014-06-13 18:10:27 +00:00
|
|
|
ServerName string `mapstructure:"server_name"`
|
|
|
|
|
2017-02-01 20:52:04 +00:00
|
|
|
// TLSMinVersion is used to set the minimum TLS version used for TLS connections.
|
|
|
|
TLSMinVersion string `mapstructure:"tls_min_version"`
|
|
|
|
|
2017-04-27 08:29:39 +00:00
|
|
|
// TLSCipherSuites is used to specify the list of supported ciphersuites.
|
|
|
|
TLSCipherSuites []uint16 `mapstructure:"-" json:"-"`
|
|
|
|
TLSCipherSuitesRaw string `mapstructure:"tls_cipher_suites"`
|
|
|
|
|
|
|
|
// TLSPreferServerCipherSuites specifies whether to prefer the server's ciphersuite
|
|
|
|
// over the client ciphersuites.
|
|
|
|
TLSPreferServerCipherSuites bool `mapstructure:"tls_prefer_server_cipher_suites"`
|
|
|
|
|
2014-04-11 23:59:16 +00:00
|
|
|
// StartJoin is a list of addresses to attempt to join when the
|
|
|
|
// agent starts. If Serf is unable to communicate with any of these
|
|
|
|
// addresses, then the agent will error and exit.
|
|
|
|
StartJoin []string `mapstructure:"start_join"`
|
|
|
|
|
2014-11-17 22:14:59 +00:00
|
|
|
// StartJoinWan is a list of addresses to attempt to join -wan when the
|
2014-11-14 15:02:42 +00:00
|
|
|
// agent starts. If Serf is unable to communicate with any of these
|
|
|
|
// addresses, then the agent will error and exit.
|
2014-11-17 22:14:59 +00:00
|
|
|
StartJoinWan []string `mapstructure:"start_join_wan"`
|
2014-11-14 15:02:42 +00:00
|
|
|
|
2014-10-12 17:50:15 +00:00
|
|
|
// RetryJoin is a list of addresses to join with retry enabled.
|
|
|
|
RetryJoin []string `mapstructure:"retry_join"`
|
|
|
|
|
|
|
|
// RetryMaxAttempts specifies the maximum number of times to retry joining a
|
|
|
|
// host on startup. This is useful for cases where we know the node will be
|
|
|
|
// online eventually.
|
|
|
|
RetryMaxAttempts int `mapstructure:"retry_max"`
|
|
|
|
|
|
|
|
// RetryInterval specifies the amount of time to wait in between join
|
|
|
|
// attempts on agent start. The minimum allowed value is 1 second and
|
|
|
|
// the default is 30s.
|
|
|
|
RetryInterval time.Duration `mapstructure:"-" json:"-"`
|
|
|
|
RetryIntervalRaw string `mapstructure:"retry_interval"`
|
|
|
|
|
2017-05-24 08:20:28 +00:00
|
|
|
// RetryJoinEC2 specifies the configuration for auto-join on EC2.
|
2016-11-02 18:35:37 +00:00
|
|
|
RetryJoinEC2 RetryJoinEC2 `mapstructure:"retry_join_ec2"`
|
|
|
|
|
2017-05-24 08:20:28 +00:00
|
|
|
// RetryJoinGCE specifies the configuration for auto-join on GCE.
|
2016-12-05 08:07:53 +00:00
|
|
|
RetryJoinGCE RetryJoinGCE `mapstructure:"retry_join_gce"`
|
|
|
|
|
2017-05-24 08:20:28 +00:00
|
|
|
// RetryJoinAzure specifies the configuration for auto-join on Azure.
|
2017-05-24 07:19:23 +00:00
|
|
|
RetryJoinAzure RetryJoinAzure `mapstructure:"retry_join_azure"`
|
|
|
|
|
2014-11-17 22:14:59 +00:00
|
|
|
// RetryJoinWan is a list of addresses to join -wan with retry enabled.
|
|
|
|
RetryJoinWan []string `mapstructure:"retry_join_wan"`
|
2014-11-14 15:02:42 +00:00
|
|
|
|
2014-11-17 22:14:59 +00:00
|
|
|
// RetryMaxAttemptsWan specifies the maximum number of times to retry joining a
|
2014-11-14 15:02:42 +00:00
|
|
|
// -wan host on startup. This is useful for cases where we know the node will be
|
|
|
|
// online eventually.
|
2014-11-17 22:14:59 +00:00
|
|
|
RetryMaxAttemptsWan int `mapstructure:"retry_max_wan"`
|
2014-11-14 15:02:42 +00:00
|
|
|
|
2014-11-17 22:14:59 +00:00
|
|
|
// RetryIntervalWan specifies the amount of time to wait in between join
|
2014-11-14 15:02:42 +00:00
|
|
|
// -wan attempts on agent start. The minimum allowed value is 1 second and
|
|
|
|
// the default is 30s.
|
2014-11-17 22:14:59 +00:00
|
|
|
RetryIntervalWan time.Duration `mapstructure:"-" json:"-"`
|
|
|
|
RetryIntervalWanRaw string `mapstructure:"retry_interval_wan"`
|
2014-11-14 15:02:42 +00:00
|
|
|
|
2016-04-11 05:46:07 +00:00
|
|
|
// ReconnectTimeout* specify the amount of time to wait to reconnect with
|
|
|
|
// another agent before deciding it's permanently gone. This can be used to
|
|
|
|
// control the time it takes to reap failed nodes from the cluster.
|
|
|
|
ReconnectTimeoutLan time.Duration `mapstructure:"-"`
|
|
|
|
ReconnectTimeoutLanRaw string `mapstructure:"reconnect_timeout"`
|
|
|
|
ReconnectTimeoutWan time.Duration `mapstructure:"-"`
|
|
|
|
ReconnectTimeoutWanRaw string `mapstructure:"reconnect_timeout_wan"`
|
|
|
|
|
2017-04-21 00:02:42 +00:00
|
|
|
// EnableUI enables the statically-compiled assets for the Consul web UI and
|
2015-12-22 17:30:19 +00:00
|
|
|
// serves them at the default /ui/ endpoint automatically.
|
2017-04-21 00:02:42 +00:00
|
|
|
EnableUI bool `mapstructure:"ui"`
|
2015-12-22 17:30:19 +00:00
|
|
|
|
2017-04-21 00:02:42 +00:00
|
|
|
// UIDir is the directory containing the Web UI resources.
|
2014-04-23 19:36:49 +00:00
|
|
|
// If provided, the UI endpoints will be enabled.
|
2017-04-21 00:02:42 +00:00
|
|
|
UIDir string `mapstructure:"ui_dir"`
|
2014-04-23 19:36:49 +00:00
|
|
|
|
2014-05-06 03:29:50 +00:00
|
|
|
// PidFile is the file to store our PID in
|
|
|
|
PidFile string `mapstructure:"pid_file"`
|
|
|
|
|
2014-05-21 19:06:03 +00:00
|
|
|
// EnableSyslog is used to also tee all the logs over to syslog. Only supported
|
|
|
|
// on linux and OSX. Other platforms will generate an error.
|
|
|
|
EnableSyslog bool `mapstructure:"enable_syslog"`
|
|
|
|
|
2014-06-11 17:18:19 +00:00
|
|
|
// SyslogFacility is used to control where the syslog messages go
|
|
|
|
// By default, goes to LOCAL0
|
|
|
|
SyslogFacility string `mapstructure:"syslog_facility"`
|
|
|
|
|
2014-05-21 19:32:24 +00:00
|
|
|
// RejoinAfterLeave controls our interaction with the cluster after leave.
|
|
|
|
// When set to false (default), a leave causes Consul to not rejoin
|
|
|
|
// the cluster until an explicit join is received. If this is set to
|
|
|
|
// true, we ignore the leave, and rejoin the cluster on start.
|
|
|
|
RejoinAfterLeave bool `mapstructure:"rejoin_after_leave"`
|
|
|
|
|
2014-06-09 19:13:14 +00:00
|
|
|
// CheckUpdateInterval controls the interval on which the output of a health check
|
|
|
|
// is updated if there is no change to the state. For example, a check in a steady
|
|
|
|
// state may run every 5 second generating a unique output (timestamp, etc), forcing
|
|
|
|
// constant writes. This allows Consul to defer the write for some period of time,
|
|
|
|
// reducing the write pressure when the state is steady.
|
|
|
|
CheckUpdateInterval time.Duration `mapstructure:"-"`
|
|
|
|
CheckUpdateIntervalRaw string `mapstructure:"check_update_interval" json:"-"`
|
|
|
|
|
2016-08-16 07:05:55 +00:00
|
|
|
// CheckReapInterval controls the interval on which we will look for
|
|
|
|
// failed checks and reap their associated services, if so configured.
|
|
|
|
CheckReapInterval time.Duration `mapstructure:"-"`
|
|
|
|
|
|
|
|
// CheckDeregisterIntervalMin is the smallest allowed interval to set
|
|
|
|
// a check's DeregisterCriticalServiceAfter value to.
|
|
|
|
CheckDeregisterIntervalMin time.Duration `mapstructure:"-"`
|
|
|
|
|
2014-08-05 18:05:55 +00:00
|
|
|
// ACLToken is the default token used to make requests if a per-request
|
|
|
|
// token is not provided. If not configured the 'anonymous' token is used.
|
|
|
|
ACLToken string `mapstructure:"acl_token" json:"-"`
|
|
|
|
|
2016-12-14 07:21:14 +00:00
|
|
|
// ACLAgentMasterToken is a special token that has full read and write
|
|
|
|
// privileges for this agent, and can be used to call agent endpoints
|
|
|
|
// when no servers are available.
|
|
|
|
ACLAgentMasterToken string `mapstructure:"acl_agent_master_token" json:"-"`
|
|
|
|
|
2016-12-11 19:24:44 +00:00
|
|
|
// ACLAgentToken is the default token used to make requests for the agent
|
|
|
|
// itself, such as for registering itself with the catalog. If not
|
|
|
|
// configured, the 'acl_token' will be used.
|
|
|
|
ACLAgentToken string `mapstructure:"acl_agent_token" json:"-"`
|
|
|
|
|
2014-08-05 22:36:08 +00:00
|
|
|
// ACLMasterToken is used to bootstrap the ACL system. It should be specified
|
|
|
|
// on the servers in the ACLDatacenter. When the leader comes online, it ensures
|
|
|
|
// that the Master token is available. This provides the initial token.
|
|
|
|
ACLMasterToken string `mapstructure:"acl_master_token" json:"-"`
|
|
|
|
|
2014-08-05 18:05:55 +00:00
|
|
|
// ACLDatacenter is the central datacenter that holds authoritative
|
|
|
|
// ACL records. This must be the same for the entire cluster.
|
|
|
|
// If this is not set, ACLs are not enabled. Off by default.
|
|
|
|
ACLDatacenter string `mapstructure:"acl_datacenter"`
|
|
|
|
|
2014-08-05 22:03:47 +00:00
|
|
|
// ACLTTL is used to control the time-to-live of cached ACLs . This has
|
2014-08-05 18:05:55 +00:00
|
|
|
// a major impact on performance. By default, it is set to 30 seconds.
|
2014-08-05 22:03:47 +00:00
|
|
|
ACLTTL time.Duration `mapstructure:"-"`
|
|
|
|
ACLTTLRaw string `mapstructure:"acl_ttl"`
|
|
|
|
|
|
|
|
// ACLDefaultPolicy is used to control the ACL interaction when
|
|
|
|
// there is no defined policy. This can be "allow" which means
|
|
|
|
// ACLs are used to black-list, or "deny" which means ACLs are
|
|
|
|
// white-lists.
|
|
|
|
ACLDefaultPolicy string `mapstructure:"acl_default_policy"`
|
2014-08-05 18:05:55 +00:00
|
|
|
|
2016-12-14 07:21:14 +00:00
|
|
|
// ACLDisabledTTL is used by clients to determine how long they will
|
|
|
|
// wait to check again with the servers if they discover ACLs are not
|
|
|
|
// enabled.
|
|
|
|
ACLDisabledTTL time.Duration `mapstructure:"-"`
|
|
|
|
|
2014-08-05 18:05:55 +00:00
|
|
|
// ACLDownPolicy is used to control the ACL interaction when we cannot
|
|
|
|
// reach the ACLDatacenter and the token is not in the cache.
|
|
|
|
// There are two modes:
|
2016-12-14 07:21:14 +00:00
|
|
|
// * allow - Allow all requests
|
2014-08-05 18:05:55 +00:00
|
|
|
// * deny - Deny all requests
|
|
|
|
// * extend-cache - Ignore the cache expiration, and allow cached
|
|
|
|
// ACL's to be used to service requests. This
|
2016-02-18 23:19:28 +00:00
|
|
|
// is the default. If the ACL is not in the cache,
|
2014-08-05 18:05:55 +00:00
|
|
|
// this acts like deny.
|
|
|
|
ACLDownPolicy string `mapstructure:"acl_down_policy"`
|
|
|
|
|
2016-08-03 05:04:11 +00:00
|
|
|
// ACLReplicationToken is used to fetch ACLs from the ACLDatacenter in
|
|
|
|
// order to replicate them locally. Setting this to a non-empty value
|
|
|
|
// also enables replication. Replication is only available in datacenters
|
|
|
|
// other than the ACLDatacenter.
|
2016-08-04 00:00:59 +00:00
|
|
|
ACLReplicationToken string `mapstructure:"acl_replication_token" json:"-"`
|
2016-08-03 05:04:11 +00:00
|
|
|
|
2016-12-02 03:14:08 +00:00
|
|
|
// ACLEnforceVersion8 is used to gate a set of ACL policy features that
|
|
|
|
// are opt-in prior to Consul 0.8 and opt-out in Consul 0.8 and later.
|
|
|
|
ACLEnforceVersion8 *bool `mapstructure:"acl_enforce_version_8"`
|
|
|
|
|
2014-08-19 21:19:31 +00:00
|
|
|
// Watches are used to monitor various endpoints and to invoke a
|
|
|
|
// handler to act appropriately. These are managed entirely in the
|
|
|
|
// agent layer using the standard APIs.
|
2014-08-21 18:52:36 +00:00
|
|
|
Watches []map[string]interface{} `mapstructure:"watches"`
|
2014-08-19 21:19:31 +00:00
|
|
|
|
2014-08-29 18:24:01 +00:00
|
|
|
// DisableRemoteExec is used to turn off the remote execution
|
|
|
|
// feature. This is for security to prevent unknown scripts from running.
|
2017-03-30 16:25:12 +00:00
|
|
|
DisableRemoteExec *bool `mapstructure:"disable_remote_exec"`
|
2014-08-29 18:24:01 +00:00
|
|
|
|
2014-09-02 21:23:43 +00:00
|
|
|
// DisableUpdateCheck is used to turn off the automatic update and
|
|
|
|
// security bulletin checking.
|
|
|
|
DisableUpdateCheck bool `mapstructure:"disable_update_check"`
|
|
|
|
|
|
|
|
// DisableAnonymousSignature is used to turn off the anonymous signature
|
|
|
|
// send with the update check. This is used to deduplicate messages.
|
|
|
|
DisableAnonymousSignature bool `mapstructure:"disable_anonymous_signature"`
|
|
|
|
|
2014-12-28 04:53:19 +00:00
|
|
|
// HTTPAPIResponseHeaders are used to add HTTP header response fields to the HTTP API responses.
|
|
|
|
HTTPAPIResponseHeaders map[string]string `mapstructure:"http_api_response_headers"`
|
|
|
|
|
2014-04-11 22:22:35 +00:00
|
|
|
// AEInterval controls the anti-entropy interval. This is how often
|
2015-06-06 03:31:33 +00:00
|
|
|
// the agent attempts to reconcile its local state with the server's
|
2014-04-11 22:22:35 +00:00
|
|
|
// representation of our state. Defaults to every 60s.
|
2014-05-29 18:24:37 +00:00
|
|
|
AEInterval time.Duration `mapstructure:"-" json:"-"`
|
2014-04-11 22:22:35 +00:00
|
|
|
|
2015-06-20 00:47:42 +00:00
|
|
|
// DisableCoordinates controls features related to network coordinates.
|
2015-07-30 18:22:56 +00:00
|
|
|
DisableCoordinates bool `mapstructure:"disable_coordinates"`
|
2015-06-06 03:31:33 +00:00
|
|
|
|
2015-06-30 19:02:05 +00:00
|
|
|
// SyncCoordinateRateTarget controls the rate for sending network
|
|
|
|
// coordinates to the server, in updates per second. This is the max rate
|
|
|
|
// that the server supports, so we scale our interval based on the size
|
|
|
|
// of the cluster to try to achieve this in aggregate at the server.
|
|
|
|
SyncCoordinateRateTarget float64 `mapstructure:"-" json:"-"`
|
|
|
|
|
|
|
|
// SyncCoordinateIntervalMin sets the minimum interval that coordinates
|
|
|
|
// will be sent to the server. We scale the interval based on the cluster
|
|
|
|
// size, but below a certain interval it doesn't make sense send them any
|
|
|
|
// faster.
|
|
|
|
SyncCoordinateIntervalMin time.Duration `mapstructure:"-" json:"-"`
|
2015-04-15 23:12:45 +00:00
|
|
|
|
2014-02-03 23:15:35 +00:00
|
|
|
// Checks holds the provided check definitions
|
2014-05-29 18:24:37 +00:00
|
|
|
Checks []*CheckDefinition `mapstructure:"-" json:"-"`
|
2014-02-03 23:15:35 +00:00
|
|
|
|
|
|
|
// Services holds the provided service definitions
|
2014-05-29 18:24:37 +00:00
|
|
|
Services []*ServiceDefinition `mapstructure:"-" json:"-"`
|
2014-02-03 23:15:35 +00:00
|
|
|
|
2013-12-20 23:33:13 +00:00
|
|
|
// ConsulConfig can either be provided or a default one created
|
2014-05-29 18:24:37 +00:00
|
|
|
ConsulConfig *consul.Config `mapstructure:"-" json:"-"`
|
2014-06-06 21:40:22 +00:00
|
|
|
|
|
|
|
// Revision is the GitCommit this maps to
|
|
|
|
Revision string `mapstructure:"-"`
|
|
|
|
|
|
|
|
// Version is the release version number
|
|
|
|
Version string `mapstructure:"-"`
|
|
|
|
|
|
|
|
// VersionPrerelease is a label for pre-release builds
|
|
|
|
VersionPrerelease string `mapstructure:"-"`
|
2014-08-21 20:09:13 +00:00
|
|
|
|
|
|
|
// WatchPlans contains the compiled watches
|
2017-04-21 00:46:29 +00:00
|
|
|
WatchPlans []*watch.Plan `mapstructure:"-" json:"-"`
|
2015-01-20 21:44:27 +00:00
|
|
|
|
|
|
|
// UnixSockets is a map of socket configuration data
|
2015-01-21 02:53:18 +00:00
|
|
|
UnixSockets UnixSocketConfig `mapstructure:"unix_sockets"`
|
2015-03-27 05:30:04 +00:00
|
|
|
|
|
|
|
// Minimum Session TTL
|
|
|
|
SessionTTLMin time.Duration `mapstructure:"-"`
|
|
|
|
SessionTTLMinRaw string `mapstructure:"session_ttl_min"`
|
2017-05-10 15:45:17 +00:00
|
|
|
|
|
|
|
// deprecated fields
|
|
|
|
// keep them exported since otherwise the error messages don't show up
|
|
|
|
DeprecatedAtlasInfrastructure string `mapstructure:"atlas_infrastructure" json:"-"`
|
|
|
|
DeprecatedAtlasToken string `mapstructure:"atlas_token" json:"-"`
|
|
|
|
DeprecatedAtlasACLToken string `mapstructure:"atlas_acl_token" json:"-"`
|
|
|
|
DeprecatedAtlasJoin bool `mapstructure:"atlas_join" json:"-"`
|
|
|
|
DeprecatedAtlasEndpoint string `mapstructure:"atlas_endpoint" json:"-"`
|
2015-01-21 02:53:18 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 23:05:21 +00:00
|
|
|
// IncomingHTTPSConfig returns the TLS configuration for HTTPS
|
2017-05-19 09:53:41 +00:00
|
|
|
// connections to consul.
|
2017-05-30 23:05:21 +00:00
|
|
|
func (c *Config) IncomingHTTPSConfig() (*tls.Config, error) {
|
2017-05-19 09:53:41 +00:00
|
|
|
tc := &tlsutil.Config{
|
|
|
|
VerifyIncoming: c.VerifyIncoming || c.VerifyIncomingHTTPS,
|
|
|
|
VerifyOutgoing: c.VerifyOutgoing,
|
|
|
|
CAFile: c.CAFile,
|
|
|
|
CAPath: c.CAPath,
|
|
|
|
CertFile: c.CertFile,
|
|
|
|
KeyFile: c.KeyFile,
|
|
|
|
NodeName: c.NodeName,
|
|
|
|
ServerName: c.ServerName,
|
|
|
|
TLSMinVersion: c.TLSMinVersion,
|
|
|
|
CipherSuites: c.TLSCipherSuites,
|
|
|
|
PreferServerCipherSuites: c.TLSPreferServerCipherSuites,
|
|
|
|
}
|
|
|
|
return tc.IncomingTLSConfig()
|
|
|
|
}
|
|
|
|
|
2017-05-24 13:22:56 +00:00
|
|
|
type ProtoAddr struct {
|
|
|
|
Proto, Net, Addr string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p ProtoAddr) String() string {
|
|
|
|
return p.Proto + "+" + p.Net + "://" + p.Addr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) DNSAddrs() ([]ProtoAddr, error) {
|
2017-06-09 22:50:06 +00:00
|
|
|
if c.Ports.DNS <= 0 {
|
2017-05-24 13:22:56 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
a, err := c.ClientListener(c.Addresses.DNS, c.Ports.DNS)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
addrs := []ProtoAddr{
|
|
|
|
{"dns", "tcp", a.String()},
|
|
|
|
{"dns", "udp", a.String()},
|
|
|
|
}
|
|
|
|
return addrs, nil
|
|
|
|
}
|
|
|
|
|
2017-05-19 09:53:41 +00:00
|
|
|
// HTTPAddrs returns the bind addresses for the HTTP server and
|
|
|
|
// the application protocol which should be served, e.g. 'http'
|
|
|
|
// or 'https'.
|
2017-05-24 13:22:56 +00:00
|
|
|
func (c *Config) HTTPAddrs() ([]ProtoAddr, error) {
|
|
|
|
var addrs []ProtoAddr
|
2017-05-19 09:53:41 +00:00
|
|
|
if c.Ports.HTTP > 0 {
|
|
|
|
a, err := c.ClientListener(c.Addresses.HTTP, c.Ports.HTTP)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-05-24 13:22:56 +00:00
|
|
|
addrs = append(addrs, ProtoAddr{"http", a.Network(), a.String()})
|
2017-05-19 09:53:41 +00:00
|
|
|
}
|
2017-05-24 22:06:38 +00:00
|
|
|
if c.Ports.HTTPS > 0 && c.CertFile != "" && c.KeyFile != "" {
|
2017-05-19 09:53:41 +00:00
|
|
|
a, err := c.ClientListener(c.Addresses.HTTPS, c.Ports.HTTPS)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-05-24 13:22:56 +00:00
|
|
|
addrs = append(addrs, ProtoAddr{"https", a.Network(), a.String()})
|
2017-05-19 09:53:41 +00:00
|
|
|
}
|
2017-05-24 13:22:56 +00:00
|
|
|
return addrs, nil
|
2017-05-19 09:53:41 +00:00
|
|
|
}
|
|
|
|
|
2015-12-22 18:43:32 +00:00
|
|
|
// Bool is used to initialize bool pointers in struct literals.
|
|
|
|
func Bool(b bool) *bool {
|
|
|
|
return &b
|
|
|
|
}
|
|
|
|
|
2017-03-01 22:04:40 +00:00
|
|
|
// Uint64 is used to initialize uint64 pointers in struct literals.
|
|
|
|
func Uint64(i uint64) *uint64 {
|
|
|
|
return &i
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duration is used to initialize time.Duration pointers in struct literals.
|
|
|
|
func Duration(d time.Duration) *time.Duration {
|
|
|
|
return &d
|
|
|
|
}
|
|
|
|
|
2015-01-21 04:30:59 +00:00
|
|
|
// UnixSocketPermissions contains information about a unix socket, and
|
2015-01-21 02:53:18 +00:00
|
|
|
// implements the FilePermissions interface.
|
2015-01-21 04:30:59 +00:00
|
|
|
type UnixSocketPermissions struct {
|
2015-01-21 02:53:18 +00:00
|
|
|
Usr string `mapstructure:"user"`
|
|
|
|
Grp string `mapstructure:"group"`
|
|
|
|
Perms string `mapstructure:"mode"`
|
|
|
|
}
|
|
|
|
|
2015-01-21 04:30:59 +00:00
|
|
|
func (u UnixSocketPermissions) User() string {
|
2015-01-21 02:53:18 +00:00
|
|
|
return u.Usr
|
|
|
|
}
|
|
|
|
|
2015-01-21 04:30:59 +00:00
|
|
|
func (u UnixSocketPermissions) Group() string {
|
2015-01-21 02:53:18 +00:00
|
|
|
return u.Grp
|
|
|
|
}
|
|
|
|
|
2015-01-21 04:30:59 +00:00
|
|
|
func (u UnixSocketPermissions) Mode() string {
|
2015-01-21 02:53:18 +00:00
|
|
|
return u.Perms
|
2013-12-20 01:14:46 +00:00
|
|
|
}
|
|
|
|
|
2015-10-08 19:45:45 +00:00
|
|
|
func (s *Telemetry) GoString() string {
|
|
|
|
return fmt.Sprintf("*%#v", *s)
|
|
|
|
}
|
|
|
|
|
2015-01-21 04:30:59 +00:00
|
|
|
// UnixSocketConfig stores information about various unix sockets which
|
|
|
|
// Consul creates and uses for communication.
|
|
|
|
type UnixSocketConfig struct {
|
|
|
|
UnixSocketPermissions `mapstructure:",squash"`
|
2013-12-20 01:14:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 18:43:56 +00:00
|
|
|
// socketPath tests if a given address describes a domain socket,
|
2015-01-16 01:24:15 +00:00
|
|
|
// and returns the relevant path part of the string if it is.
|
2017-05-11 18:43:56 +00:00
|
|
|
func socketPath(addr string) string {
|
2015-01-08 16:38:09 +00:00
|
|
|
if !strings.HasPrefix(addr, "unix://") {
|
2017-05-11 18:43:56 +00:00
|
|
|
return ""
|
2015-01-08 16:38:09 +00:00
|
|
|
}
|
2017-05-11 18:43:56 +00:00
|
|
|
return strings.TrimPrefix(addr, "unix://")
|
2015-01-08 16:38:09 +00:00
|
|
|
}
|
|
|
|
|
2013-12-27 22:49:35 +00:00
|
|
|
type dirEnts []os.FileInfo
|
|
|
|
|
2013-12-20 01:14:46 +00:00
|
|
|
// DefaultConfig is used to return a sane default configuration
|
|
|
|
func DefaultConfig() *Config {
|
2013-12-20 23:33:13 +00:00
|
|
|
return &Config{
|
2014-06-20 00:08:48 +00:00
|
|
|
Bootstrap: false,
|
|
|
|
BootstrapExpect: 0,
|
|
|
|
Server: false,
|
|
|
|
Datacenter: consul.DefaultDC,
|
|
|
|
Domain: "consul.",
|
|
|
|
LogLevel: "INFO",
|
|
|
|
ClientAddr: "127.0.0.1",
|
|
|
|
BindAddr: "0.0.0.0",
|
2014-04-11 22:22:35 +00:00
|
|
|
Ports: PortConfig{
|
|
|
|
DNS: 8600,
|
|
|
|
HTTP: 8500,
|
2014-11-14 19:39:19 +00:00
|
|
|
HTTPS: -1,
|
2014-04-11 22:22:35 +00:00
|
|
|
SerfLan: consul.DefaultLANSerfPort,
|
|
|
|
SerfWan: consul.DefaultWANSerfPort,
|
|
|
|
Server: 8300,
|
|
|
|
},
|
2014-06-08 22:26:33 +00:00
|
|
|
DNSConfig: DNSConfig{
|
2016-09-01 14:15:32 +00:00
|
|
|
AllowStale: Bool(true),
|
2016-08-29 21:29:23 +00:00
|
|
|
UDPAnswerLimit: 3,
|
2016-11-08 19:45:12 +00:00
|
|
|
MaxStale: 10 * 365 * 24 * time.Hour,
|
2016-08-26 19:22:04 +00:00
|
|
|
RecursorTimeout: 2 * time.Second,
|
2014-06-08 22:26:33 +00:00
|
|
|
},
|
2015-10-08 19:45:45 +00:00
|
|
|
Telemetry: Telemetry{
|
|
|
|
StatsitePrefix: "consul",
|
|
|
|
},
|
2017-01-06 01:21:56 +00:00
|
|
|
Meta: make(map[string]string),
|
2016-08-16 07:05:55 +00:00
|
|
|
SyslogFacility: "LOCAL0",
|
|
|
|
Protocol: consul.ProtocolVersion2Compatible,
|
|
|
|
CheckUpdateInterval: 5 * time.Minute,
|
|
|
|
CheckDeregisterIntervalMin: time.Minute,
|
|
|
|
CheckReapInterval: 30 * time.Second,
|
|
|
|
AEInterval: time.Minute,
|
|
|
|
DisableCoordinates: false,
|
2015-06-30 19:02:05 +00:00
|
|
|
|
|
|
|
// SyncCoordinateRateTarget is set based on the rate that we want
|
|
|
|
// the server to handle as an aggregate across the entire cluster.
|
|
|
|
// If you update this, you'll need to adjust CoordinateUpdate* in
|
|
|
|
// the server-side config accordingly.
|
2015-07-01 00:12:31 +00:00
|
|
|
SyncCoordinateRateTarget: 64.0, // updates / second
|
|
|
|
SyncCoordinateIntervalMin: 15 * time.Second,
|
2015-06-30 19:02:05 +00:00
|
|
|
|
2016-12-02 03:14:08 +00:00
|
|
|
ACLTTL: 30 * time.Second,
|
|
|
|
ACLDownPolicy: "extend-cache",
|
|
|
|
ACLDefaultPolicy: "allow",
|
2016-12-14 07:21:14 +00:00
|
|
|
ACLDisabledTTL: 120 * time.Second,
|
2017-03-24 16:23:25 +00:00
|
|
|
ACLEnforceVersion8: Bool(true),
|
2017-03-30 16:25:12 +00:00
|
|
|
DisableRemoteExec: Bool(true),
|
2016-12-02 03:14:08 +00:00
|
|
|
RetryInterval: 30 * time.Second,
|
|
|
|
RetryIntervalWan: 30 * time.Second,
|
2017-02-01 20:52:04 +00:00
|
|
|
|
|
|
|
TLSMinVersion: "tls10",
|
2017-05-30 15:51:37 +00:00
|
|
|
|
|
|
|
EncryptVerifyIncoming: Bool(true),
|
|
|
|
EncryptVerifyOutgoing: Bool(true),
|
2013-12-20 23:33:13 +00:00
|
|
|
}
|
2013-12-20 01:14:46 +00:00
|
|
|
}
|
2013-12-21 00:39:32 +00:00
|
|
|
|
2015-11-29 04:40:05 +00:00
|
|
|
// DevConfig is used to return a set of configuration to use for dev mode.
|
|
|
|
func DevConfig() *Config {
|
|
|
|
conf := DefaultConfig()
|
|
|
|
conf.DevMode = true
|
|
|
|
conf.LogLevel = "DEBUG"
|
|
|
|
conf.Server = true
|
|
|
|
conf.EnableDebug = true
|
|
|
|
conf.DisableAnonymousSignature = true
|
2017-04-21 00:02:42 +00:00
|
|
|
conf.EnableUI = true
|
2016-04-07 18:25:33 +00:00
|
|
|
conf.BindAddr = "127.0.0.1"
|
2017-04-28 19:10:57 +00:00
|
|
|
|
|
|
|
conf.ConsulConfig = consul.DefaultConfig()
|
|
|
|
conf.ConsulConfig.SerfLANConfig.MemberlistConfig.ProbeTimeout = 100 * time.Millisecond
|
|
|
|
conf.ConsulConfig.SerfLANConfig.MemberlistConfig.ProbeInterval = 100 * time.Millisecond
|
|
|
|
conf.ConsulConfig.SerfLANConfig.MemberlistConfig.GossipInterval = 100 * time.Millisecond
|
|
|
|
|
|
|
|
conf.ConsulConfig.SerfWANConfig.MemberlistConfig.SuspicionMult = 3
|
|
|
|
conf.ConsulConfig.SerfWANConfig.MemberlistConfig.ProbeTimeout = 100 * time.Millisecond
|
|
|
|
conf.ConsulConfig.SerfWANConfig.MemberlistConfig.ProbeInterval = 100 * time.Millisecond
|
|
|
|
conf.ConsulConfig.SerfWANConfig.MemberlistConfig.GossipInterval = 100 * time.Millisecond
|
|
|
|
|
|
|
|
conf.ConsulConfig.RaftConfig.LeaderLeaseTimeout = 20 * time.Millisecond
|
|
|
|
conf.ConsulConfig.RaftConfig.HeartbeatTimeout = 40 * time.Millisecond
|
|
|
|
conf.ConsulConfig.RaftConfig.ElectionTimeout = 40 * time.Millisecond
|
|
|
|
|
|
|
|
conf.ConsulConfig.CoordinateUpdatePeriod = 100 * time.Millisecond
|
|
|
|
|
2015-11-29 04:40:05 +00:00
|
|
|
return conf
|
|
|
|
}
|
|
|
|
|
2013-12-21 00:39:32 +00:00
|
|
|
// EncryptBytes returns the encryption key configured.
|
|
|
|
func (c *Config) EncryptBytes() ([]byte, error) {
|
|
|
|
return base64.StdEncoding.DecodeString(c.EncryptKey)
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:22:35 +00:00
|
|
|
// ClientListener is used to format a listener for a
|
|
|
|
// port on a ClientAddr
|
2015-01-08 16:38:09 +00:00
|
|
|
func (c *Config) ClientListener(override string, port int) (net.Addr, error) {
|
2017-05-19 09:53:41 +00:00
|
|
|
addr := c.ClientAddr
|
2014-09-02 19:47:40 +00:00
|
|
|
if override != "" {
|
|
|
|
addr = override
|
|
|
|
}
|
2017-05-11 18:43:56 +00:00
|
|
|
if path := socketPath(addr); path != "" {
|
2015-01-16 01:24:15 +00:00
|
|
|
return &net.UnixAddr{Name: path, Net: "unix"}, nil
|
|
|
|
}
|
|
|
|
ip := net.ParseIP(addr)
|
|
|
|
if ip == nil {
|
|
|
|
return nil, fmt.Errorf("Failed to parse IP: %v", addr)
|
2014-08-21 20:09:13 +00:00
|
|
|
}
|
2015-01-16 01:24:15 +00:00
|
|
|
return &net.TCPAddr{IP: ip, Port: port}, nil
|
2014-08-21 20:09:13 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 19:24:44 +00:00
|
|
|
// GetTokenForAgent returns the token the agent should use for its own internal
|
|
|
|
// operations, such as registering itself with the catalog.
|
|
|
|
func (c *Config) GetTokenForAgent() string {
|
|
|
|
if c.ACLAgentToken != "" {
|
|
|
|
return c.ACLAgentToken
|
2017-05-03 19:12:30 +00:00
|
|
|
}
|
|
|
|
if c.ACLToken != "" {
|
2016-12-11 19:24:44 +00:00
|
|
|
return c.ACLToken
|
|
|
|
}
|
2017-05-03 19:12:30 +00:00
|
|
|
return ""
|
2016-12-11 19:24:44 +00:00
|
|
|
}
|
|
|
|
|
pkg refactor
command/agent/* -> agent/*
command/consul/* -> agent/consul/*
command/agent/command{,_test}.go -> command/agent{,_test}.go
command/base/command.go -> command/base.go
command/base/* -> command/*
commands.go -> command/commands.go
The script which did the refactor is:
(
cd $GOPATH/src/github.com/hashicorp/consul
git mv command/agent/command.go command/agent.go
git mv command/agent/command_test.go command/agent_test.go
git mv command/agent/flag_slice_value{,_test}.go command/
git mv command/agent .
git mv command/base/command.go command/base.go
git mv command/base/config_util{,_test}.go command/
git mv commands.go command/
git mv consul agent
rmdir command/base/
gsed -i -e 's|package agent|package command|' command/agent{,_test}.go
gsed -i -e 's|package agent|package command|' command/flag_slice_value{,_test}.go
gsed -i -e 's|package base|package command|' command/base.go command/config_util{,_test}.go
gsed -i -e 's|package main|package command|' command/commands.go
gsed -i -e 's|base.Command|BaseCommand|' command/commands.go
gsed -i -e 's|agent.Command|AgentCommand|' command/commands.go
gsed -i -e 's|\tCommand:|\tBaseCommand:|' command/commands.go
gsed -i -e 's|base\.||' command/commands.go
gsed -i -e 's|command\.||' command/commands.go
gsed -i -e 's|command|c|' main.go
gsed -i -e 's|range Commands|range command.Commands|' main.go
gsed -i -e 's|Commands: Commands|Commands: command.Commands|' main.go
gsed -i -e 's|base\.BoolValue|BoolValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.DurationValue|DurationValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.StringValue|StringValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.UintValue|UintValue|' command/operator_autopilot_set.go
gsed -i -e 's|\bCommand\b|BaseCommand|' command/base.go
gsed -i -e 's|BaseCommand Options|Command Options|' command/base.go
gsed -i -e 's|base.Command|BaseCommand|' command/*.go
gsed -i -e 's|c\.Command|c.BaseCommand|g' command/*.go
gsed -i -e 's|\tCommand:|\tBaseCommand:|' command/*_test.go
gsed -i -e 's|base\.||' command/*_test.go
gsed -i -e 's|\bCommand\b|AgentCommand|' command/agent{,_test}.go
gsed -i -e 's|cmd.AgentCommand|cmd.BaseCommand|' command/agent.go
gsed -i -e 's|cli.AgentCommand = new(Command)|cli.Command = new(AgentCommand)|' command/agent_test.go
gsed -i -e 's|exec.AgentCommand|exec.Command|' command/agent_test.go
gsed -i -e 's|exec.BaseCommand|exec.Command|' command/agent_test.go
gsed -i -e 's|NewTestAgent|agent.NewTestAgent|' command/agent_test.go
gsed -i -e 's|= TestConfig|= agent.TestConfig|' command/agent_test.go
gsed -i -e 's|: RetryJoin|: agent.RetryJoin|' command/agent_test.go
gsed -i -e 's|\.\./\.\./|../|' command/config_util_test.go
gsed -i -e 's|\bverifyUniqueListeners|VerifyUniqueListeners|' agent/config{,_test}.go command/agent.go
gsed -i -e 's|\bserfLANKeyring\b|SerfLANKeyring|g' agent/{agent,keyring,testagent}.go command/agent.go
gsed -i -e 's|\bserfWANKeyring\b|SerfWANKeyring|g' agent/{agent,keyring,testagent}.go command/agent.go
gsed -i -e 's|\bNewAgent\b|agent.New|g' command/agent{,_test}.go
gsed -i -e 's|\bNewAgent|New|' agent/{acl_test,agent,testagent}.go
gsed -i -e 's|\bAgent\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bBool\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bDefaultConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bDevConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bMergeConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bReadConfigPaths\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bParseMetaPair\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bSerfLANKeyring\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bSerfWANKeyring\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|circonus\.agent|circonus|g' command/agent{,_test}.go
gsed -i -e 's|logger\.agent|logger|g' command/agent{,_test}.go
gsed -i -e 's|metrics\.agent|metrics|g' command/agent{,_test}.go
gsed -i -e 's|// agent.Agent|// agent|' command/agent{,_test}.go
gsed -i -e 's|a\.agent\.Config|a.Config|' command/agent{,_test}.go
gsed -i -e 's|agent\.AppendSliceValue|AppendSliceValue|' command/{configtest,validate}.go
gsed -i -e 's|consul/consul|agent/consul|' GNUmakefile
gsed -i -e 's|\.\./test|../../test|' agent/consul/server_test.go
# fix imports
f=$(grep -rl 'github.com/hashicorp/consul/command/agent' * | grep '\.go')
gsed -i -e 's|github.com/hashicorp/consul/command/agent|github.com/hashicorp/consul/agent|' $f
goimports -w $f
f=$(grep -rl 'github.com/hashicorp/consul/consul' * | grep '\.go')
gsed -i -e 's|github.com/hashicorp/consul/consul|github.com/hashicorp/consul/agent/consul|' $f
goimports -w $f
goimports -w command/*.go main.go
)
2017-06-09 22:28:28 +00:00
|
|
|
// VerifyUniqueListeners checks to see if an address was used more than once in
|
2017-05-03 20:46:00 +00:00
|
|
|
// the config
|
pkg refactor
command/agent/* -> agent/*
command/consul/* -> agent/consul/*
command/agent/command{,_test}.go -> command/agent{,_test}.go
command/base/command.go -> command/base.go
command/base/* -> command/*
commands.go -> command/commands.go
The script which did the refactor is:
(
cd $GOPATH/src/github.com/hashicorp/consul
git mv command/agent/command.go command/agent.go
git mv command/agent/command_test.go command/agent_test.go
git mv command/agent/flag_slice_value{,_test}.go command/
git mv command/agent .
git mv command/base/command.go command/base.go
git mv command/base/config_util{,_test}.go command/
git mv commands.go command/
git mv consul agent
rmdir command/base/
gsed -i -e 's|package agent|package command|' command/agent{,_test}.go
gsed -i -e 's|package agent|package command|' command/flag_slice_value{,_test}.go
gsed -i -e 's|package base|package command|' command/base.go command/config_util{,_test}.go
gsed -i -e 's|package main|package command|' command/commands.go
gsed -i -e 's|base.Command|BaseCommand|' command/commands.go
gsed -i -e 's|agent.Command|AgentCommand|' command/commands.go
gsed -i -e 's|\tCommand:|\tBaseCommand:|' command/commands.go
gsed -i -e 's|base\.||' command/commands.go
gsed -i -e 's|command\.||' command/commands.go
gsed -i -e 's|command|c|' main.go
gsed -i -e 's|range Commands|range command.Commands|' main.go
gsed -i -e 's|Commands: Commands|Commands: command.Commands|' main.go
gsed -i -e 's|base\.BoolValue|BoolValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.DurationValue|DurationValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.StringValue|StringValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.UintValue|UintValue|' command/operator_autopilot_set.go
gsed -i -e 's|\bCommand\b|BaseCommand|' command/base.go
gsed -i -e 's|BaseCommand Options|Command Options|' command/base.go
gsed -i -e 's|base.Command|BaseCommand|' command/*.go
gsed -i -e 's|c\.Command|c.BaseCommand|g' command/*.go
gsed -i -e 's|\tCommand:|\tBaseCommand:|' command/*_test.go
gsed -i -e 's|base\.||' command/*_test.go
gsed -i -e 's|\bCommand\b|AgentCommand|' command/agent{,_test}.go
gsed -i -e 's|cmd.AgentCommand|cmd.BaseCommand|' command/agent.go
gsed -i -e 's|cli.AgentCommand = new(Command)|cli.Command = new(AgentCommand)|' command/agent_test.go
gsed -i -e 's|exec.AgentCommand|exec.Command|' command/agent_test.go
gsed -i -e 's|exec.BaseCommand|exec.Command|' command/agent_test.go
gsed -i -e 's|NewTestAgent|agent.NewTestAgent|' command/agent_test.go
gsed -i -e 's|= TestConfig|= agent.TestConfig|' command/agent_test.go
gsed -i -e 's|: RetryJoin|: agent.RetryJoin|' command/agent_test.go
gsed -i -e 's|\.\./\.\./|../|' command/config_util_test.go
gsed -i -e 's|\bverifyUniqueListeners|VerifyUniqueListeners|' agent/config{,_test}.go command/agent.go
gsed -i -e 's|\bserfLANKeyring\b|SerfLANKeyring|g' agent/{agent,keyring,testagent}.go command/agent.go
gsed -i -e 's|\bserfWANKeyring\b|SerfWANKeyring|g' agent/{agent,keyring,testagent}.go command/agent.go
gsed -i -e 's|\bNewAgent\b|agent.New|g' command/agent{,_test}.go
gsed -i -e 's|\bNewAgent|New|' agent/{acl_test,agent,testagent}.go
gsed -i -e 's|\bAgent\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bBool\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bDefaultConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bDevConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bMergeConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bReadConfigPaths\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bParseMetaPair\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bSerfLANKeyring\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bSerfWANKeyring\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|circonus\.agent|circonus|g' command/agent{,_test}.go
gsed -i -e 's|logger\.agent|logger|g' command/agent{,_test}.go
gsed -i -e 's|metrics\.agent|metrics|g' command/agent{,_test}.go
gsed -i -e 's|// agent.Agent|// agent|' command/agent{,_test}.go
gsed -i -e 's|a\.agent\.Config|a.Config|' command/agent{,_test}.go
gsed -i -e 's|agent\.AppendSliceValue|AppendSliceValue|' command/{configtest,validate}.go
gsed -i -e 's|consul/consul|agent/consul|' GNUmakefile
gsed -i -e 's|\.\./test|../../test|' agent/consul/server_test.go
# fix imports
f=$(grep -rl 'github.com/hashicorp/consul/command/agent' * | grep '\.go')
gsed -i -e 's|github.com/hashicorp/consul/command/agent|github.com/hashicorp/consul/agent|' $f
goimports -w $f
f=$(grep -rl 'github.com/hashicorp/consul/consul' * | grep '\.go')
gsed -i -e 's|github.com/hashicorp/consul/consul|github.com/hashicorp/consul/agent/consul|' $f
goimports -w $f
goimports -w command/*.go main.go
)
2017-06-09 22:28:28 +00:00
|
|
|
func (c *Config) VerifyUniqueListeners() error {
|
2017-05-03 20:46:00 +00:00
|
|
|
listeners := []struct {
|
|
|
|
host string
|
|
|
|
port int
|
|
|
|
descr string
|
|
|
|
}{
|
|
|
|
{c.Addresses.DNS, c.Ports.DNS, "DNS"},
|
|
|
|
{c.Addresses.HTTP, c.Ports.HTTP, "HTTP"},
|
|
|
|
{c.Addresses.HTTPS, c.Ports.HTTPS, "HTTPS"},
|
|
|
|
{c.AdvertiseAddr, c.Ports.Server, "Server RPC"},
|
|
|
|
{c.AdvertiseAddr, c.Ports.SerfLan, "Serf LAN"},
|
|
|
|
{c.AdvertiseAddr, c.Ports.SerfWan, "Serf WAN"},
|
|
|
|
}
|
|
|
|
|
|
|
|
type key struct {
|
|
|
|
host string
|
|
|
|
port int
|
|
|
|
}
|
|
|
|
m := make(map[key]string, len(listeners))
|
|
|
|
|
|
|
|
for _, l := range listeners {
|
|
|
|
if l.host == "" {
|
|
|
|
l.host = "0.0.0.0"
|
|
|
|
} else if strings.HasPrefix(l.host, "unix") {
|
|
|
|
// Don't compare ports on unix sockets
|
|
|
|
l.port = 0
|
|
|
|
}
|
|
|
|
if l.host == "0.0.0.0" && l.port <= 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
k := key{l.host, l.port}
|
|
|
|
v, ok := m[k]
|
|
|
|
if ok {
|
|
|
|
return fmt.Errorf("%s address already configured for %s", l.descr, v)
|
|
|
|
}
|
|
|
|
m[k] = l.descr
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-12-21 00:39:32 +00:00
|
|
|
// DecodeConfig reads the configuration from the given reader in JSON
|
|
|
|
// format and decodes it into a proper Config structure.
|
|
|
|
func DecodeConfig(r io.Reader) (*Config, error) {
|
|
|
|
var raw interface{}
|
2017-05-03 19:12:30 +00:00
|
|
|
if err := json.NewDecoder(r).Decode(&raw); err != nil {
|
2013-12-21 00:39:32 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:15:35 +00:00
|
|
|
// Check the result type
|
2017-05-03 19:12:30 +00:00
|
|
|
var result Config
|
2014-02-03 23:15:35 +00:00
|
|
|
if obj, ok := raw.(map[string]interface{}); ok {
|
2014-10-24 02:22:25 +00:00
|
|
|
// Check for a "services", "service" or "check" key, meaning
|
2014-02-03 23:15:35 +00:00
|
|
|
// this is actually a definition entry
|
2014-10-24 02:22:25 +00:00
|
|
|
if sub, ok := obj["services"]; ok {
|
|
|
|
if list, ok := sub.([]interface{}); ok {
|
|
|
|
for _, srv := range list {
|
|
|
|
service, err := DecodeServiceDefinition(srv)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
result.Services = append(result.Services, service)
|
|
|
|
}
|
|
|
|
}
|
2014-10-26 20:11:25 +00:00
|
|
|
}
|
|
|
|
if sub, ok := obj["service"]; ok {
|
2014-02-03 23:15:35 +00:00
|
|
|
service, err := DecodeServiceDefinition(sub)
|
2014-10-26 20:11:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-02-03 23:15:35 +00:00
|
|
|
result.Services = append(result.Services, service)
|
2014-10-26 20:11:25 +00:00
|
|
|
}
|
|
|
|
if sub, ok := obj["checks"]; ok {
|
|
|
|
if list, ok := sub.([]interface{}); ok {
|
|
|
|
for _, chk := range list {
|
|
|
|
check, err := DecodeCheckDefinition(chk)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
result.Checks = append(result.Checks, check)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if sub, ok := obj["check"]; ok {
|
2014-02-03 23:15:35 +00:00
|
|
|
check, err := DecodeCheckDefinition(sub)
|
2014-10-26 20:11:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-02-03 23:15:35 +00:00
|
|
|
result.Checks = append(result.Checks, check)
|
|
|
|
}
|
2015-10-08 19:45:45 +00:00
|
|
|
|
|
|
|
// A little hacky but upgrades the old stats config directives to the new way
|
|
|
|
if sub, ok := obj["statsd_addr"]; ok && result.Telemetry.StatsdAddr == "" {
|
|
|
|
result.Telemetry.StatsdAddr = sub.(string)
|
|
|
|
}
|
|
|
|
|
|
|
|
if sub, ok := obj["statsite_addr"]; ok && result.Telemetry.StatsiteAddr == "" {
|
|
|
|
result.Telemetry.StatsiteAddr = sub.(string)
|
|
|
|
}
|
|
|
|
|
|
|
|
if sub, ok := obj["statsite_prefix"]; ok && result.Telemetry.StatsitePrefix == "" {
|
|
|
|
result.Telemetry.StatsitePrefix = sub.(string)
|
|
|
|
}
|
|
|
|
|
|
|
|
if sub, ok := obj["dogstatsd_addr"]; ok && result.Telemetry.DogStatsdAddr == "" {
|
|
|
|
result.Telemetry.DogStatsdAddr = sub.(string)
|
|
|
|
}
|
|
|
|
|
|
|
|
if sub, ok := obj["dogstatsd_tags"].([]interface{}); ok && len(result.Telemetry.DogStatsdTags) == 0 {
|
|
|
|
result.Telemetry.DogStatsdTags = make([]string, len(sub))
|
|
|
|
for i := range sub {
|
|
|
|
result.Telemetry.DogStatsdTags[i] = sub[i].(string)
|
|
|
|
}
|
|
|
|
}
|
2014-02-03 23:15:35 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 00:39:32 +00:00
|
|
|
// Decode
|
|
|
|
var md mapstructure.Metadata
|
|
|
|
msdec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
|
|
|
Metadata: &md,
|
|
|
|
Result: &result,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := msdec.Decode(raw); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-03-23 21:10:14 +00:00
|
|
|
// Check for deprecations
|
|
|
|
if result.Ports.RPC != 0 {
|
|
|
|
fmt.Fprintln(os.Stderr, "==> DEPRECATION: ports.rpc is deprecated and is "+
|
|
|
|
"no longer used. Please remove it from your configuration.")
|
|
|
|
}
|
|
|
|
if result.Addresses.RPC != "" {
|
|
|
|
fmt.Fprintln(os.Stderr, "==> DEPRECATION: addresses.rpc is deprecated and "+
|
|
|
|
"is no longer used. Please remove it from your configuration.")
|
|
|
|
}
|
2017-05-10 15:45:17 +00:00
|
|
|
if result.DeprecatedAtlasInfrastructure != "" {
|
|
|
|
fmt.Fprintln(os.Stderr, "==> DEPRECATION: atlas_infrastructure is deprecated and "+
|
|
|
|
"is no longer used. Please remove it from your configuration.")
|
|
|
|
}
|
|
|
|
if result.DeprecatedAtlasToken != "" {
|
|
|
|
fmt.Fprintln(os.Stderr, "==> DEPRECATION: atlas_token is deprecated and "+
|
|
|
|
"is no longer used. Please remove it from your configuration.")
|
|
|
|
}
|
|
|
|
if result.DeprecatedAtlasACLToken != "" {
|
|
|
|
fmt.Fprintln(os.Stderr, "==> DEPRECATION: atlas_acl_token is deprecated and "+
|
|
|
|
"is no longer used. Please remove it from your configuration.")
|
|
|
|
}
|
|
|
|
if result.DeprecatedAtlasJoin != false {
|
|
|
|
fmt.Fprintln(os.Stderr, "==> DEPRECATION: atlas_join is deprecated and "+
|
|
|
|
"is no longer used. Please remove it from your configuration.")
|
|
|
|
}
|
|
|
|
if result.DeprecatedAtlasEndpoint != "" {
|
|
|
|
fmt.Fprintln(os.Stderr, "==> DEPRECATION: atlas_endpoint is deprecated and "+
|
|
|
|
"is no longer used. Please remove it from your configuration.")
|
|
|
|
}
|
2017-03-23 21:10:14 +00:00
|
|
|
|
2015-01-05 22:41:19 +00:00
|
|
|
// Check unused fields and verify that no bad configuration options were
|
|
|
|
// passed to Consul. There are a few additional fields which don't directly
|
2016-07-19 22:46:57 +00:00
|
|
|
// use mapstructure decoding, so we need to account for those as well. These
|
|
|
|
// telemetry-related fields used to be available as top-level keys, so they
|
|
|
|
// are here for backward compatibility with the old format.
|
2015-10-08 19:45:45 +00:00
|
|
|
allowedKeys := []string{
|
|
|
|
"service", "services", "check", "checks", "statsd_addr", "statsite_addr", "statsite_prefix",
|
|
|
|
"dogstatsd_addr", "dogstatsd_tags",
|
|
|
|
}
|
|
|
|
|
2015-01-05 22:41:19 +00:00
|
|
|
var unused []string
|
|
|
|
for _, field := range md.Unused {
|
2016-01-29 19:42:34 +00:00
|
|
|
if !lib.StrContains(allowedKeys, field) {
|
2015-01-05 22:41:19 +00:00
|
|
|
unused = append(unused, field)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(unused) > 0 {
|
|
|
|
return nil, fmt.Errorf("Config has invalid keys: %s", strings.Join(unused, ","))
|
|
|
|
}
|
|
|
|
|
2014-06-08 22:26:33 +00:00
|
|
|
// Handle time conversions
|
|
|
|
if raw := result.DNSConfig.NodeTTLRaw; raw != "" {
|
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("NodeTTL invalid: %v", err)
|
|
|
|
}
|
|
|
|
result.DNSConfig.NodeTTL = dur
|
|
|
|
}
|
|
|
|
|
|
|
|
if raw := result.DNSConfig.MaxStaleRaw; raw != "" {
|
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("MaxStale invalid: %v", err)
|
|
|
|
}
|
|
|
|
result.DNSConfig.MaxStale = dur
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:22:04 +00:00
|
|
|
if raw := result.DNSConfig.RecursorTimeoutRaw; raw != "" {
|
2016-08-23 20:59:38 +00:00
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
2016-08-26 19:22:04 +00:00
|
|
|
return nil, fmt.Errorf("RecursorTimeout invalid: %v", err)
|
2016-08-23 20:59:38 +00:00
|
|
|
}
|
2016-08-26 19:22:04 +00:00
|
|
|
result.DNSConfig.RecursorTimeout = dur
|
2016-08-23 20:59:38 +00:00
|
|
|
}
|
|
|
|
|
2014-06-08 22:26:33 +00:00
|
|
|
if len(result.DNSConfig.ServiceTTLRaw) != 0 {
|
|
|
|
if result.DNSConfig.ServiceTTL == nil {
|
|
|
|
result.DNSConfig.ServiceTTL = make(map[string]time.Duration)
|
|
|
|
}
|
|
|
|
for service, raw := range result.DNSConfig.ServiceTTLRaw {
|
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("ServiceTTL %s invalid: %v", service, err)
|
|
|
|
}
|
|
|
|
result.DNSConfig.ServiceTTL[service] = dur
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-09 19:13:14 +00:00
|
|
|
if raw := result.CheckUpdateIntervalRaw; raw != "" {
|
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("CheckUpdateInterval invalid: %v", err)
|
|
|
|
}
|
|
|
|
result.CheckUpdateInterval = dur
|
|
|
|
}
|
|
|
|
|
2014-08-05 22:03:47 +00:00
|
|
|
if raw := result.ACLTTLRaw; raw != "" {
|
2014-08-05 18:05:55 +00:00
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
2014-08-05 22:03:47 +00:00
|
|
|
return nil, fmt.Errorf("ACL TTL invalid: %v", err)
|
2014-08-05 18:05:55 +00:00
|
|
|
}
|
2014-08-05 22:03:47 +00:00
|
|
|
result.ACLTTL = dur
|
2014-08-05 18:05:55 +00:00
|
|
|
}
|
|
|
|
|
2014-10-12 17:50:15 +00:00
|
|
|
if raw := result.RetryIntervalRaw; raw != "" {
|
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("RetryInterval invalid: %v", err)
|
|
|
|
}
|
|
|
|
result.RetryInterval = dur
|
|
|
|
}
|
|
|
|
|
2014-11-17 22:14:59 +00:00
|
|
|
if raw := result.RetryIntervalWanRaw; raw != "" {
|
2014-11-14 15:02:42 +00:00
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
2014-11-17 22:14:59 +00:00
|
|
|
return nil, fmt.Errorf("RetryIntervalWan invalid: %v", err)
|
2014-11-14 15:02:42 +00:00
|
|
|
}
|
2014-11-17 22:14:59 +00:00
|
|
|
result.RetryIntervalWan = dur
|
2014-11-14 15:02:42 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 06:31:16 +00:00
|
|
|
const reconnectTimeoutMin = 8 * time.Hour
|
2016-04-11 05:46:07 +00:00
|
|
|
if raw := result.ReconnectTimeoutLanRaw; raw != "" {
|
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("ReconnectTimeoutLan invalid: %v", err)
|
|
|
|
}
|
2016-04-11 06:31:16 +00:00
|
|
|
if dur < reconnectTimeoutMin {
|
|
|
|
return nil, fmt.Errorf("ReconnectTimeoutLan must be >= %s", reconnectTimeoutMin.String())
|
|
|
|
}
|
2016-04-11 05:46:07 +00:00
|
|
|
result.ReconnectTimeoutLan = dur
|
|
|
|
}
|
|
|
|
if raw := result.ReconnectTimeoutWanRaw; raw != "" {
|
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("ReconnectTimeoutWan invalid: %v", err)
|
|
|
|
}
|
2016-04-11 06:31:16 +00:00
|
|
|
if dur < reconnectTimeoutMin {
|
|
|
|
return nil, fmt.Errorf("ReconnectTimeoutWan must be >= %s", reconnectTimeoutMin.String())
|
|
|
|
}
|
2016-04-11 05:46:07 +00:00
|
|
|
result.ReconnectTimeoutWan = dur
|
|
|
|
}
|
|
|
|
|
2017-03-01 22:04:40 +00:00
|
|
|
if raw := result.Autopilot.LastContactThresholdRaw; raw != "" {
|
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("LastContactThreshold invalid: %v", err)
|
|
|
|
}
|
|
|
|
result.Autopilot.LastContactThreshold = &dur
|
|
|
|
}
|
|
|
|
if raw := result.Autopilot.ServerStabilizationTimeRaw; raw != "" {
|
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("ServerStabilizationTime invalid: %v", err)
|
|
|
|
}
|
|
|
|
result.Autopilot.ServerStabilizationTime = &dur
|
|
|
|
}
|
|
|
|
|
2014-11-03 19:28:21 +00:00
|
|
|
// Merge the single recursor
|
|
|
|
if result.DNSRecursor != "" {
|
|
|
|
result.DNSRecursors = append(result.DNSRecursors, result.DNSRecursor)
|
|
|
|
}
|
|
|
|
|
2015-03-27 05:30:04 +00:00
|
|
|
if raw := result.SessionTTLMinRaw; raw != "" {
|
|
|
|
dur, err := time.ParseDuration(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Session TTL Min invalid: %v", err)
|
|
|
|
}
|
|
|
|
result.SessionTTLMin = dur
|
|
|
|
}
|
|
|
|
|
2015-06-05 11:44:42 +00:00
|
|
|
if result.AdvertiseAddrs.SerfLanRaw != "" {
|
2016-12-02 05:35:38 +00:00
|
|
|
ipStr, err := parseSingleIPTemplate(result.AdvertiseAddrs.SerfLanRaw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Serf Advertise LAN address resolution failed: %v", err)
|
|
|
|
}
|
|
|
|
result.AdvertiseAddrs.SerfLanRaw = ipStr
|
|
|
|
|
2015-06-05 11:44:42 +00:00
|
|
|
addr, err := net.ResolveTCPAddr("tcp", result.AdvertiseAddrs.SerfLanRaw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("AdvertiseAddrs.SerfLan is invalid: %v", err)
|
|
|
|
}
|
|
|
|
result.AdvertiseAddrs.SerfLan = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.AdvertiseAddrs.SerfWanRaw != "" {
|
2016-12-02 05:35:38 +00:00
|
|
|
ipStr, err := parseSingleIPTemplate(result.AdvertiseAddrs.SerfWanRaw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Serf Advertise WAN address resolution failed: %v", err)
|
|
|
|
}
|
|
|
|
result.AdvertiseAddrs.SerfWanRaw = ipStr
|
|
|
|
|
2015-06-05 11:44:42 +00:00
|
|
|
addr, err := net.ResolveTCPAddr("tcp", result.AdvertiseAddrs.SerfWanRaw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("AdvertiseAddrs.SerfWan is invalid: %v", err)
|
|
|
|
}
|
|
|
|
result.AdvertiseAddrs.SerfWan = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.AdvertiseAddrs.RPCRaw != "" {
|
2016-12-02 05:35:38 +00:00
|
|
|
ipStr, err := parseSingleIPTemplate(result.AdvertiseAddrs.RPCRaw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("RPC Advertise address resolution failed: %v", err)
|
|
|
|
}
|
|
|
|
result.AdvertiseAddrs.RPCRaw = ipStr
|
|
|
|
|
2015-06-05 11:44:42 +00:00
|
|
|
addr, err := net.ResolveTCPAddr("tcp", result.AdvertiseAddrs.RPCRaw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("AdvertiseAddrs.RPC is invalid: %v", err)
|
|
|
|
}
|
|
|
|
result.AdvertiseAddrs.RPC = addr
|
|
|
|
}
|
|
|
|
|
2016-08-25 22:36:05 +00:00
|
|
|
// Enforce the max Raft multiplier.
|
|
|
|
if result.Performance.RaftMultiplier > consul.MaxRaftMultiplier {
|
|
|
|
return nil, fmt.Errorf("Performance.RaftMultiplier must be <= %d", consul.MaxRaftMultiplier)
|
|
|
|
}
|
|
|
|
|
2017-04-27 08:29:39 +00:00
|
|
|
if raw := result.TLSCipherSuitesRaw; raw != "" {
|
|
|
|
ciphers, err := tlsutil.ParseCiphers(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("TLSCipherSuites invalid: %v", err)
|
|
|
|
}
|
|
|
|
result.TLSCipherSuites = ciphers
|
|
|
|
}
|
|
|
|
|
2013-12-21 00:39:32 +00:00
|
|
|
return &result, nil
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:15:35 +00:00
|
|
|
// DecodeServiceDefinition is used to decode a service definition
|
|
|
|
func DecodeServiceDefinition(raw interface{}) (*ServiceDefinition, error) {
|
|
|
|
rawMap, ok := raw.(map[string]interface{})
|
|
|
|
if !ok {
|
|
|
|
goto AFTER_FIX
|
|
|
|
}
|
2014-04-03 21:22:43 +00:00
|
|
|
|
|
|
|
// If no 'tags', handle the deprecated 'tag' value.
|
|
|
|
if _, ok := rawMap["tags"]; !ok {
|
|
|
|
if tag, ok := rawMap["tag"]; ok {
|
|
|
|
rawMap["tags"] = []interface{}{tag}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-01 02:27:37 +00:00
|
|
|
for k, v := range rawMap {
|
2015-01-14 01:52:17 +00:00
|
|
|
switch strings.ToLower(k) {
|
|
|
|
case "check":
|
|
|
|
if err := FixupCheckType(v); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
case "checks":
|
|
|
|
chkTypes, ok := v.([]interface{})
|
|
|
|
if !ok {
|
|
|
|
goto AFTER_FIX
|
|
|
|
}
|
|
|
|
for _, chkType := range chkTypes {
|
|
|
|
if err := FixupCheckType(chkType); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2014-12-01 02:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-03 23:15:35 +00:00
|
|
|
AFTER_FIX:
|
|
|
|
var md mapstructure.Metadata
|
|
|
|
var result ServiceDefinition
|
|
|
|
msdec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
|
|
|
Metadata: &md,
|
|
|
|
Result: &result,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := msdec.Decode(raw); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &result, nil
|
|
|
|
}
|
|
|
|
|
2017-06-06 23:11:56 +00:00
|
|
|
var errInvalidHeaderFormat = errors.New("agent: invalid format of 'header' field")
|
2015-01-14 01:52:17 +00:00
|
|
|
|
2017-06-06 23:11:56 +00:00
|
|
|
func FixupCheckType(raw interface{}) error {
|
2014-02-03 23:15:35 +00:00
|
|
|
rawMap, ok := raw.(map[string]interface{})
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
2014-04-25 02:44:27 +00:00
|
|
|
|
2017-06-06 23:11:56 +00:00
|
|
|
parseDuration := func(v interface{}) (time.Duration, error) {
|
|
|
|
if v == nil {
|
|
|
|
return 0, nil
|
|
|
|
}
|
2017-06-08 20:34:08 +00:00
|
|
|
switch x := v.(type) {
|
|
|
|
case time.Duration:
|
|
|
|
return x, nil
|
|
|
|
case float64:
|
|
|
|
return time.Duration(x), nil
|
|
|
|
case string:
|
|
|
|
return time.ParseDuration(x)
|
|
|
|
default:
|
2017-06-06 23:11:56 +00:00
|
|
|
return 0, fmt.Errorf("invalid format")
|
|
|
|
}
|
2014-04-25 02:44:27 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 23:11:56 +00:00
|
|
|
parseHeaderMap := func(v interface{}) (map[string][]string, error) {
|
|
|
|
if v == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
vm, ok := v.(map[string]interface{})
|
|
|
|
if !ok {
|
|
|
|
return nil, errInvalidHeaderFormat
|
|
|
|
}
|
|
|
|
m := map[string][]string{}
|
|
|
|
for k, vv := range vm {
|
|
|
|
vs, ok := vv.([]interface{})
|
|
|
|
if !ok {
|
|
|
|
return nil, errInvalidHeaderFormat
|
|
|
|
}
|
|
|
|
for _, vs := range vs {
|
|
|
|
s, ok := vs.(string)
|
|
|
|
if !ok {
|
|
|
|
return nil, errInvalidHeaderFormat
|
|
|
|
}
|
|
|
|
m[k] = append(m[k], s)
|
2014-02-03 23:15:35 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-06 23:11:56 +00:00
|
|
|
return m, nil
|
2014-02-03 23:15:35 +00:00
|
|
|
}
|
2014-04-25 02:44:27 +00:00
|
|
|
|
2017-06-06 23:11:56 +00:00
|
|
|
replace := func(oldKey, newKey string, val interface{}) {
|
|
|
|
rawMap[newKey] = val
|
|
|
|
if oldKey != newKey {
|
|
|
|
delete(rawMap, oldKey)
|
2014-02-03 23:15:35 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-02 08:29:42 +00:00
|
|
|
|
2017-06-06 23:11:56 +00:00
|
|
|
for k, v := range rawMap {
|
|
|
|
switch strings.ToLower(k) {
|
|
|
|
case "header":
|
|
|
|
h, err := parseHeaderMap(v)
|
2017-04-21 01:59:42 +00:00
|
|
|
if err != nil {
|
2017-06-06 23:11:56 +00:00
|
|
|
return fmt.Errorf("invalid %q: %s", k, err)
|
2015-02-02 08:29:42 +00:00
|
|
|
}
|
2017-06-06 23:11:56 +00:00
|
|
|
rawMap[k] = h
|
2015-02-02 08:29:42 +00:00
|
|
|
|
2017-06-06 23:11:56 +00:00
|
|
|
case "ttl", "interval", "timeout":
|
|
|
|
d, err := parseDuration(v)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("invalid %q: %v", k, err)
|
|
|
|
}
|
|
|
|
rawMap[k] = d
|
|
|
|
|
|
|
|
case "deregister_critical_service_after", "deregistercriticalserviceafter":
|
|
|
|
d, err := parseDuration(v)
|
2017-04-21 01:59:42 +00:00
|
|
|
if err != nil {
|
2017-06-06 23:11:56 +00:00
|
|
|
return fmt.Errorf("invalid %q: %v", k, err)
|
2016-08-16 07:05:55 +00:00
|
|
|
}
|
2017-06-06 23:11:56 +00:00
|
|
|
replace(k, "DeregisterCriticalServiceAfter", d)
|
|
|
|
|
|
|
|
case "docker_container_id":
|
|
|
|
replace(k, "DockerContainerID", v)
|
|
|
|
|
|
|
|
case "service_id":
|
|
|
|
replace(k, "ServiceID", v)
|
|
|
|
|
|
|
|
case "tls_skip_verify":
|
|
|
|
replace(k, "TLSSkipVerify", v)
|
2016-08-16 07:05:55 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-03 23:15:35 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeCheckDefinition is used to decode a check definition
|
|
|
|
func DecodeCheckDefinition(raw interface{}) (*CheckDefinition, error) {
|
|
|
|
if err := FixupCheckType(raw); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var md mapstructure.Metadata
|
|
|
|
var result CheckDefinition
|
|
|
|
msdec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
|
|
|
Metadata: &md,
|
|
|
|
Result: &result,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := msdec.Decode(raw); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &result, nil
|
|
|
|
}
|
|
|
|
|
2013-12-21 00:39:32 +00:00
|
|
|
// MergeConfig merges two configurations together to make a single new
|
|
|
|
// configuration.
|
|
|
|
func MergeConfig(a, b *Config) *Config {
|
|
|
|
var result Config = *a
|
|
|
|
|
2016-08-25 00:33:53 +00:00
|
|
|
// Propagate non-default performance settings
|
|
|
|
if b.Performance.RaftMultiplier > 0 {
|
|
|
|
result.Performance.RaftMultiplier = b.Performance.RaftMultiplier
|
|
|
|
}
|
|
|
|
|
2013-12-21 00:39:32 +00:00
|
|
|
// Copy the strings if they're set
|
2013-12-25 00:48:07 +00:00
|
|
|
if b.Bootstrap {
|
|
|
|
result.Bootstrap = true
|
|
|
|
}
|
2014-06-20 00:08:48 +00:00
|
|
|
if b.BootstrapExpect != 0 {
|
|
|
|
result.BootstrapExpect = b.BootstrapExpect
|
2014-06-16 21:36:12 +00:00
|
|
|
}
|
2013-12-21 00:39:32 +00:00
|
|
|
if b.Datacenter != "" {
|
|
|
|
result.Datacenter = b.Datacenter
|
|
|
|
}
|
|
|
|
if b.DataDir != "" {
|
|
|
|
result.DataDir = b.DataDir
|
|
|
|
}
|
2014-10-31 19:19:41 +00:00
|
|
|
|
|
|
|
// Copy the dns recursors
|
|
|
|
result.DNSRecursors = make([]string, 0, len(a.DNSRecursors)+len(b.DNSRecursors))
|
|
|
|
result.DNSRecursors = append(result.DNSRecursors, a.DNSRecursors...)
|
|
|
|
result.DNSRecursors = append(result.DNSRecursors, b.DNSRecursors...)
|
|
|
|
|
2014-01-02 23:50:52 +00:00
|
|
|
if b.Domain != "" {
|
|
|
|
result.Domain = b.Domain
|
|
|
|
}
|
2013-12-21 00:39:32 +00:00
|
|
|
if b.EncryptKey != "" {
|
|
|
|
result.EncryptKey = b.EncryptKey
|
|
|
|
}
|
2017-05-30 15:51:37 +00:00
|
|
|
if b.EncryptVerifyIncoming != nil {
|
|
|
|
result.EncryptVerifyIncoming = b.EncryptVerifyIncoming
|
|
|
|
}
|
|
|
|
if b.EncryptVerifyOutgoing != nil {
|
|
|
|
result.EncryptVerifyOutgoing = b.EncryptVerifyOutgoing
|
|
|
|
}
|
2013-12-21 00:39:32 +00:00
|
|
|
if b.LogLevel != "" {
|
|
|
|
result.LogLevel = b.LogLevel
|
|
|
|
}
|
2014-03-09 22:57:03 +00:00
|
|
|
if b.Protocol > 0 {
|
|
|
|
result.Protocol = b.Protocol
|
|
|
|
}
|
2017-03-01 22:04:40 +00:00
|
|
|
if b.RaftProtocol > 0 {
|
2017-02-23 21:08:40 +00:00
|
|
|
result.RaftProtocol = b.RaftProtocol
|
|
|
|
}
|
2017-01-18 06:20:11 +00:00
|
|
|
if b.NodeID != "" {
|
|
|
|
result.NodeID = b.NodeID
|
|
|
|
}
|
2017-04-13 05:05:38 +00:00
|
|
|
if b.DisableHostNodeID == true {
|
|
|
|
result.DisableHostNodeID = b.DisableHostNodeID
|
|
|
|
}
|
2014-01-02 23:50:52 +00:00
|
|
|
if b.NodeName != "" {
|
|
|
|
result.NodeName = b.NodeName
|
|
|
|
}
|
2014-04-11 22:22:35 +00:00
|
|
|
if b.ClientAddr != "" {
|
|
|
|
result.ClientAddr = b.ClientAddr
|
2013-12-21 00:39:32 +00:00
|
|
|
}
|
2014-04-11 22:22:35 +00:00
|
|
|
if b.BindAddr != "" {
|
|
|
|
result.BindAddr = b.BindAddr
|
2013-12-21 00:39:32 +00:00
|
|
|
}
|
2014-01-02 23:50:52 +00:00
|
|
|
if b.AdvertiseAddr != "" {
|
|
|
|
result.AdvertiseAddr = b.AdvertiseAddr
|
|
|
|
}
|
2015-03-21 09:14:03 +00:00
|
|
|
if b.AdvertiseAddrWan != "" {
|
|
|
|
result.AdvertiseAddrWan = b.AdvertiseAddrWan
|
|
|
|
}
|
2016-11-03 19:58:58 +00:00
|
|
|
if b.SerfWanBindAddr != "" {
|
|
|
|
result.SerfWanBindAddr = b.SerfWanBindAddr
|
|
|
|
}
|
|
|
|
if b.SerfLanBindAddr != "" {
|
|
|
|
result.SerfLanBindAddr = b.SerfLanBindAddr
|
|
|
|
}
|
2015-12-22 11:31:40 +00:00
|
|
|
if b.TranslateWanAddrs == true {
|
|
|
|
result.TranslateWanAddrs = true
|
|
|
|
}
|
2015-06-05 11:44:42 +00:00
|
|
|
if b.AdvertiseAddrs.SerfLan != nil {
|
|
|
|
result.AdvertiseAddrs.SerfLan = b.AdvertiseAddrs.SerfLan
|
|
|
|
result.AdvertiseAddrs.SerfLanRaw = b.AdvertiseAddrs.SerfLanRaw
|
|
|
|
}
|
|
|
|
if b.AdvertiseAddrs.SerfWan != nil {
|
|
|
|
result.AdvertiseAddrs.SerfWan = b.AdvertiseAddrs.SerfWan
|
|
|
|
result.AdvertiseAddrs.SerfWanRaw = b.AdvertiseAddrs.SerfWanRaw
|
|
|
|
}
|
|
|
|
if b.AdvertiseAddrs.RPC != nil {
|
|
|
|
result.AdvertiseAddrs.RPC = b.AdvertiseAddrs.RPC
|
|
|
|
result.AdvertiseAddrs.RPCRaw = b.AdvertiseAddrs.RPCRaw
|
|
|
|
}
|
2013-12-21 00:39:32 +00:00
|
|
|
if b.Server == true {
|
|
|
|
result.Server = b.Server
|
|
|
|
}
|
2017-03-21 23:36:44 +00:00
|
|
|
if b.NonVotingServer == true {
|
|
|
|
result.NonVotingServer = b.NonVotingServer
|
|
|
|
}
|
2016-09-01 06:39:11 +00:00
|
|
|
if b.LeaveOnTerm != nil {
|
|
|
|
result.LeaveOnTerm = b.LeaveOnTerm
|
2013-12-21 00:39:32 +00:00
|
|
|
}
|
2016-04-01 00:45:14 +00:00
|
|
|
if b.SkipLeaveOnInt != nil {
|
|
|
|
result.SkipLeaveOnInt = b.SkipLeaveOnInt
|
2013-12-21 00:39:32 +00:00
|
|
|
}
|
2017-02-28 22:23:14 +00:00
|
|
|
if b.Autopilot.CleanupDeadServers != nil {
|
|
|
|
result.Autopilot.CleanupDeadServers = b.Autopilot.CleanupDeadServers
|
2017-02-22 20:53:32 +00:00
|
|
|
}
|
2017-03-01 22:04:40 +00:00
|
|
|
if b.Autopilot.LastContactThreshold != nil {
|
|
|
|
result.Autopilot.LastContactThreshold = b.Autopilot.LastContactThreshold
|
|
|
|
}
|
|
|
|
if b.Autopilot.MaxTrailingLogs != nil {
|
|
|
|
result.Autopilot.MaxTrailingLogs = b.Autopilot.MaxTrailingLogs
|
|
|
|
}
|
|
|
|
if b.Autopilot.ServerStabilizationTime != nil {
|
|
|
|
result.Autopilot.ServerStabilizationTime = b.Autopilot.ServerStabilizationTime
|
|
|
|
}
|
2017-03-21 23:36:44 +00:00
|
|
|
if b.Autopilot.RedundancyZoneTag != "" {
|
|
|
|
result.Autopilot.RedundancyZoneTag = b.Autopilot.RedundancyZoneTag
|
|
|
|
}
|
|
|
|
if b.Autopilot.DisableUpgradeMigration != nil {
|
|
|
|
result.Autopilot.DisableUpgradeMigration = b.Autopilot.DisableUpgradeMigration
|
|
|
|
}
|
2015-10-08 19:45:45 +00:00
|
|
|
if b.Telemetry.DisableHostname == true {
|
|
|
|
result.Telemetry.DisableHostname = true
|
|
|
|
}
|
|
|
|
if b.Telemetry.StatsdAddr != "" {
|
|
|
|
result.Telemetry.StatsdAddr = b.Telemetry.StatsdAddr
|
2014-07-11 01:16:47 +00:00
|
|
|
}
|
2015-10-08 19:45:45 +00:00
|
|
|
if b.Telemetry.StatsiteAddr != "" {
|
|
|
|
result.Telemetry.StatsiteAddr = b.Telemetry.StatsiteAddr
|
2015-05-03 23:46:20 +00:00
|
|
|
}
|
2015-10-08 19:45:45 +00:00
|
|
|
if b.Telemetry.StatsitePrefix != "" {
|
|
|
|
result.Telemetry.StatsitePrefix = b.Telemetry.StatsitePrefix
|
2014-09-02 18:26:08 +00:00
|
|
|
}
|
2015-10-08 19:45:45 +00:00
|
|
|
if b.Telemetry.DogStatsdAddr != "" {
|
|
|
|
result.Telemetry.DogStatsdAddr = b.Telemetry.DogStatsdAddr
|
2015-06-16 22:05:55 +00:00
|
|
|
}
|
2015-10-08 19:45:45 +00:00
|
|
|
if b.Telemetry.DogStatsdTags != nil {
|
|
|
|
result.Telemetry.DogStatsdTags = b.Telemetry.DogStatsdTags
|
2015-06-16 22:05:55 +00:00
|
|
|
}
|
2016-07-18 13:34:43 +00:00
|
|
|
if b.Telemetry.CirconusAPIToken != "" {
|
|
|
|
result.Telemetry.CirconusAPIToken = b.Telemetry.CirconusAPIToken
|
|
|
|
}
|
|
|
|
if b.Telemetry.CirconusAPIApp != "" {
|
|
|
|
result.Telemetry.CirconusAPIApp = b.Telemetry.CirconusAPIApp
|
|
|
|
}
|
|
|
|
if b.Telemetry.CirconusAPIURL != "" {
|
|
|
|
result.Telemetry.CirconusAPIURL = b.Telemetry.CirconusAPIURL
|
|
|
|
}
|
|
|
|
if b.Telemetry.CirconusCheckSubmissionURL != "" {
|
|
|
|
result.Telemetry.CirconusCheckSubmissionURL = b.Telemetry.CirconusCheckSubmissionURL
|
|
|
|
}
|
2016-07-18 19:46:11 +00:00
|
|
|
if b.Telemetry.CirconusSubmissionInterval != "" {
|
|
|
|
result.Telemetry.CirconusSubmissionInterval = b.Telemetry.CirconusSubmissionInterval
|
2016-07-18 13:34:43 +00:00
|
|
|
}
|
|
|
|
if b.Telemetry.CirconusCheckID != "" {
|
|
|
|
result.Telemetry.CirconusCheckID = b.Telemetry.CirconusCheckID
|
|
|
|
}
|
|
|
|
if b.Telemetry.CirconusCheckForceMetricActivation != "" {
|
|
|
|
result.Telemetry.CirconusCheckForceMetricActivation = b.Telemetry.CirconusCheckForceMetricActivation
|
|
|
|
}
|
|
|
|
if b.Telemetry.CirconusCheckInstanceID != "" {
|
|
|
|
result.Telemetry.CirconusCheckInstanceID = b.Telemetry.CirconusCheckInstanceID
|
|
|
|
}
|
|
|
|
if b.Telemetry.CirconusCheckSearchTag != "" {
|
|
|
|
result.Telemetry.CirconusCheckSearchTag = b.Telemetry.CirconusCheckSearchTag
|
|
|
|
}
|
2016-11-09 20:33:37 +00:00
|
|
|
if b.Telemetry.CirconusCheckDisplayName != "" {
|
|
|
|
result.Telemetry.CirconusCheckDisplayName = b.Telemetry.CirconusCheckDisplayName
|
|
|
|
}
|
|
|
|
if b.Telemetry.CirconusCheckTags != "" {
|
|
|
|
result.Telemetry.CirconusCheckTags = b.Telemetry.CirconusCheckTags
|
|
|
|
}
|
2016-07-18 13:34:43 +00:00
|
|
|
if b.Telemetry.CirconusBrokerID != "" {
|
|
|
|
result.Telemetry.CirconusBrokerID = b.Telemetry.CirconusBrokerID
|
|
|
|
}
|
|
|
|
if b.Telemetry.CirconusBrokerSelectTag != "" {
|
|
|
|
result.Telemetry.CirconusBrokerSelectTag = b.Telemetry.CirconusBrokerSelectTag
|
|
|
|
}
|
2014-03-20 00:49:57 +00:00
|
|
|
if b.EnableDebug {
|
|
|
|
result.EnableDebug = true
|
|
|
|
}
|
2014-04-04 23:52:39 +00:00
|
|
|
if b.VerifyIncoming {
|
|
|
|
result.VerifyIncoming = true
|
|
|
|
}
|
2017-04-28 23:15:55 +00:00
|
|
|
if b.VerifyIncomingRPC {
|
|
|
|
result.VerifyIncomingRPC = true
|
|
|
|
}
|
|
|
|
if b.VerifyIncomingHTTPS {
|
|
|
|
result.VerifyIncomingHTTPS = true
|
|
|
|
}
|
2014-04-04 23:52:39 +00:00
|
|
|
if b.VerifyOutgoing {
|
|
|
|
result.VerifyOutgoing = true
|
|
|
|
}
|
2015-05-11 22:13:58 +00:00
|
|
|
if b.VerifyServerHostname {
|
|
|
|
result.VerifyServerHostname = true
|
|
|
|
}
|
2014-04-04 23:52:39 +00:00
|
|
|
if b.CAFile != "" {
|
|
|
|
result.CAFile = b.CAFile
|
|
|
|
}
|
2017-04-27 08:29:39 +00:00
|
|
|
if b.CAPath != "" {
|
|
|
|
result.CAPath = b.CAPath
|
|
|
|
}
|
2014-04-04 23:52:39 +00:00
|
|
|
if b.CertFile != "" {
|
|
|
|
result.CertFile = b.CertFile
|
|
|
|
}
|
|
|
|
if b.KeyFile != "" {
|
|
|
|
result.KeyFile = b.KeyFile
|
|
|
|
}
|
2014-06-13 18:10:27 +00:00
|
|
|
if b.ServerName != "" {
|
|
|
|
result.ServerName = b.ServerName
|
|
|
|
}
|
2017-02-01 20:52:04 +00:00
|
|
|
if b.TLSMinVersion != "" {
|
|
|
|
result.TLSMinVersion = b.TLSMinVersion
|
|
|
|
}
|
2017-04-27 08:29:39 +00:00
|
|
|
if len(b.TLSCipherSuites) != 0 {
|
|
|
|
result.TLSCipherSuites = append(result.TLSCipherSuites, b.TLSCipherSuites...)
|
|
|
|
}
|
|
|
|
if b.TLSPreferServerCipherSuites {
|
|
|
|
result.TLSPreferServerCipherSuites = true
|
|
|
|
}
|
2014-02-03 23:15:35 +00:00
|
|
|
if b.Checks != nil {
|
|
|
|
result.Checks = append(result.Checks, b.Checks...)
|
|
|
|
}
|
|
|
|
if b.Services != nil {
|
|
|
|
result.Services = append(result.Services, b.Services...)
|
|
|
|
}
|
2014-04-11 22:22:35 +00:00
|
|
|
if b.Ports.DNS != 0 {
|
|
|
|
result.Ports.DNS = b.Ports.DNS
|
|
|
|
}
|
|
|
|
if b.Ports.HTTP != 0 {
|
|
|
|
result.Ports.HTTP = b.Ports.HTTP
|
|
|
|
}
|
2014-11-14 19:39:19 +00:00
|
|
|
if b.Ports.HTTPS != 0 {
|
|
|
|
result.Ports.HTTPS = b.Ports.HTTPS
|
|
|
|
}
|
2017-03-23 21:10:14 +00:00
|
|
|
if b.Ports.RPC != 0 {
|
|
|
|
result.Ports.RPC = b.Ports.RPC
|
|
|
|
}
|
2014-04-11 22:22:35 +00:00
|
|
|
if b.Ports.SerfLan != 0 {
|
|
|
|
result.Ports.SerfLan = b.Ports.SerfLan
|
|
|
|
}
|
|
|
|
if b.Ports.SerfWan != 0 {
|
|
|
|
result.Ports.SerfWan = b.Ports.SerfWan
|
|
|
|
}
|
|
|
|
if b.Ports.Server != 0 {
|
|
|
|
result.Ports.Server = b.Ports.Server
|
|
|
|
}
|
2014-09-02 19:42:14 +00:00
|
|
|
if b.Addresses.DNS != "" {
|
|
|
|
result.Addresses.DNS = b.Addresses.DNS
|
|
|
|
}
|
|
|
|
if b.Addresses.HTTP != "" {
|
|
|
|
result.Addresses.HTTP = b.Addresses.HTTP
|
|
|
|
}
|
2014-11-14 19:39:19 +00:00
|
|
|
if b.Addresses.HTTPS != "" {
|
|
|
|
result.Addresses.HTTPS = b.Addresses.HTTPS
|
|
|
|
}
|
2017-03-23 21:10:14 +00:00
|
|
|
if b.Addresses.RPC != "" {
|
|
|
|
result.Addresses.RPC = b.Addresses.RPC
|
|
|
|
}
|
2017-04-21 00:02:42 +00:00
|
|
|
if b.EnableUI {
|
|
|
|
result.EnableUI = true
|
2015-12-22 17:30:19 +00:00
|
|
|
}
|
2017-04-21 00:02:42 +00:00
|
|
|
if b.UIDir != "" {
|
|
|
|
result.UIDir = b.UIDir
|
2014-04-23 19:36:49 +00:00
|
|
|
}
|
2014-05-06 03:29:50 +00:00
|
|
|
if b.PidFile != "" {
|
|
|
|
result.PidFile = b.PidFile
|
|
|
|
}
|
2014-05-21 19:06:03 +00:00
|
|
|
if b.EnableSyslog {
|
|
|
|
result.EnableSyslog = true
|
|
|
|
}
|
2014-05-21 19:32:24 +00:00
|
|
|
if b.RejoinAfterLeave {
|
|
|
|
result.RejoinAfterLeave = true
|
|
|
|
}
|
2014-10-12 17:50:15 +00:00
|
|
|
if b.RetryMaxAttempts != 0 {
|
|
|
|
result.RetryMaxAttempts = b.RetryMaxAttempts
|
|
|
|
}
|
2014-10-12 17:54:53 +00:00
|
|
|
if b.RetryInterval != 0 {
|
|
|
|
result.RetryInterval = b.RetryInterval
|
|
|
|
}
|
2016-11-02 18:35:37 +00:00
|
|
|
if b.RetryJoinEC2.AccessKeyID != "" {
|
|
|
|
result.RetryJoinEC2.AccessKeyID = b.RetryJoinEC2.AccessKeyID
|
|
|
|
}
|
|
|
|
if b.RetryJoinEC2.SecretAccessKey != "" {
|
|
|
|
result.RetryJoinEC2.SecretAccessKey = b.RetryJoinEC2.SecretAccessKey
|
|
|
|
}
|
|
|
|
if b.RetryJoinEC2.Region != "" {
|
|
|
|
result.RetryJoinEC2.Region = b.RetryJoinEC2.Region
|
|
|
|
}
|
|
|
|
if b.RetryJoinEC2.TagKey != "" {
|
|
|
|
result.RetryJoinEC2.TagKey = b.RetryJoinEC2.TagKey
|
|
|
|
}
|
|
|
|
if b.RetryJoinEC2.TagValue != "" {
|
|
|
|
result.RetryJoinEC2.TagValue = b.RetryJoinEC2.TagValue
|
|
|
|
}
|
2016-12-05 08:07:53 +00:00
|
|
|
if b.RetryJoinGCE.ProjectName != "" {
|
|
|
|
result.RetryJoinGCE.ProjectName = b.RetryJoinGCE.ProjectName
|
|
|
|
}
|
|
|
|
if b.RetryJoinGCE.ZonePattern != "" {
|
|
|
|
result.RetryJoinGCE.ZonePattern = b.RetryJoinGCE.ZonePattern
|
|
|
|
}
|
|
|
|
if b.RetryJoinGCE.TagValue != "" {
|
|
|
|
result.RetryJoinGCE.TagValue = b.RetryJoinGCE.TagValue
|
|
|
|
}
|
|
|
|
if b.RetryJoinGCE.CredentialsFile != "" {
|
|
|
|
result.RetryJoinGCE.CredentialsFile = b.RetryJoinGCE.CredentialsFile
|
|
|
|
}
|
2017-05-24 07:19:23 +00:00
|
|
|
if b.RetryJoinAzure.TagName != "" {
|
|
|
|
result.RetryJoinAzure.TagName = b.RetryJoinAzure.TagName
|
|
|
|
}
|
|
|
|
if b.RetryJoinAzure.TagValue != "" {
|
|
|
|
result.RetryJoinAzure.TagValue = b.RetryJoinAzure.TagValue
|
|
|
|
}
|
|
|
|
if b.RetryJoinAzure.SubscriptionID != "" {
|
|
|
|
result.RetryJoinAzure.SubscriptionID = b.RetryJoinAzure.SubscriptionID
|
|
|
|
}
|
|
|
|
if b.RetryJoinAzure.TenantID != "" {
|
|
|
|
result.RetryJoinAzure.TenantID = b.RetryJoinAzure.TenantID
|
|
|
|
}
|
|
|
|
if b.RetryJoinAzure.ClientID != "" {
|
|
|
|
result.RetryJoinAzure.ClientID = b.RetryJoinAzure.ClientID
|
|
|
|
}
|
|
|
|
if b.RetryJoinAzure.SecretAccessKey != "" {
|
|
|
|
result.RetryJoinAzure.SecretAccessKey = b.RetryJoinAzure.SecretAccessKey
|
|
|
|
}
|
2014-11-17 22:14:59 +00:00
|
|
|
if b.RetryMaxAttemptsWan != 0 {
|
|
|
|
result.RetryMaxAttemptsWan = b.RetryMaxAttemptsWan
|
2014-11-14 15:02:42 +00:00
|
|
|
}
|
2014-11-17 22:14:59 +00:00
|
|
|
if b.RetryIntervalWan != 0 {
|
|
|
|
result.RetryIntervalWan = b.RetryIntervalWan
|
2014-11-14 15:02:42 +00:00
|
|
|
}
|
2016-04-11 05:46:07 +00:00
|
|
|
if b.ReconnectTimeoutLan != 0 {
|
|
|
|
result.ReconnectTimeoutLan = b.ReconnectTimeoutLan
|
|
|
|
result.ReconnectTimeoutLanRaw = b.ReconnectTimeoutLanRaw
|
|
|
|
}
|
|
|
|
if b.ReconnectTimeoutWan != 0 {
|
|
|
|
result.ReconnectTimeoutWan = b.ReconnectTimeoutWan
|
|
|
|
result.ReconnectTimeoutWanRaw = b.ReconnectTimeoutWanRaw
|
|
|
|
}
|
2014-06-08 22:26:33 +00:00
|
|
|
if b.DNSConfig.NodeTTL != 0 {
|
|
|
|
result.DNSConfig.NodeTTL = b.DNSConfig.NodeTTL
|
|
|
|
}
|
|
|
|
if len(b.DNSConfig.ServiceTTL) != 0 {
|
|
|
|
if result.DNSConfig.ServiceTTL == nil {
|
|
|
|
result.DNSConfig.ServiceTTL = make(map[string]time.Duration)
|
|
|
|
}
|
|
|
|
for service, dur := range b.DNSConfig.ServiceTTL {
|
|
|
|
result.DNSConfig.ServiceTTL[service] = dur
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 20:40:43 +00:00
|
|
|
if b.DNSConfig.AllowStale != nil {
|
|
|
|
result.DNSConfig.AllowStale = b.DNSConfig.AllowStale
|
2014-06-08 22:26:33 +00:00
|
|
|
}
|
2016-02-12 07:58:48 +00:00
|
|
|
if b.DNSConfig.UDPAnswerLimit != 0 {
|
|
|
|
result.DNSConfig.UDPAnswerLimit = b.DNSConfig.UDPAnswerLimit
|
|
|
|
}
|
2014-09-30 19:15:36 +00:00
|
|
|
if b.DNSConfig.EnableTruncate {
|
|
|
|
result.DNSConfig.EnableTruncate = true
|
|
|
|
}
|
2014-06-08 22:26:33 +00:00
|
|
|
if b.DNSConfig.MaxStale != 0 {
|
|
|
|
result.DNSConfig.MaxStale = b.DNSConfig.MaxStale
|
|
|
|
}
|
2015-01-10 12:11:32 +00:00
|
|
|
if b.DNSConfig.OnlyPassing {
|
|
|
|
result.DNSConfig.OnlyPassing = true
|
|
|
|
}
|
2016-08-11 23:24:44 +00:00
|
|
|
if b.DNSConfig.DisableCompression {
|
|
|
|
result.DNSConfig.DisableCompression = true
|
2015-01-10 12:11:32 +00:00
|
|
|
}
|
2016-08-26 19:22:04 +00:00
|
|
|
if b.DNSConfig.RecursorTimeout != 0 {
|
|
|
|
result.DNSConfig.RecursorTimeout = b.DNSConfig.RecursorTimeout
|
2016-08-23 20:59:38 +00:00
|
|
|
}
|
2014-06-10 04:34:19 +00:00
|
|
|
if b.CheckUpdateIntervalRaw != "" || b.CheckUpdateInterval != 0 {
|
2014-06-09 19:13:14 +00:00
|
|
|
result.CheckUpdateInterval = b.CheckUpdateInterval
|
|
|
|
}
|
2014-06-11 17:18:19 +00:00
|
|
|
if b.SyslogFacility != "" {
|
|
|
|
result.SyslogFacility = b.SyslogFacility
|
|
|
|
}
|
2014-08-05 18:05:55 +00:00
|
|
|
if b.ACLToken != "" {
|
|
|
|
result.ACLToken = b.ACLToken
|
|
|
|
}
|
2016-12-14 07:21:14 +00:00
|
|
|
if b.ACLAgentMasterToken != "" {
|
|
|
|
result.ACLAgentMasterToken = b.ACLAgentMasterToken
|
|
|
|
}
|
2016-12-11 19:24:44 +00:00
|
|
|
if b.ACLAgentToken != "" {
|
|
|
|
result.ACLAgentToken = b.ACLAgentToken
|
|
|
|
}
|
2014-08-05 22:36:08 +00:00
|
|
|
if b.ACLMasterToken != "" {
|
|
|
|
result.ACLMasterToken = b.ACLMasterToken
|
|
|
|
}
|
2014-08-05 18:05:55 +00:00
|
|
|
if b.ACLDatacenter != "" {
|
|
|
|
result.ACLDatacenter = b.ACLDatacenter
|
|
|
|
}
|
2014-08-05 22:03:47 +00:00
|
|
|
if b.ACLTTLRaw != "" {
|
|
|
|
result.ACLTTL = b.ACLTTL
|
|
|
|
result.ACLTTLRaw = b.ACLTTLRaw
|
2014-08-05 18:05:55 +00:00
|
|
|
}
|
|
|
|
if b.ACLDownPolicy != "" {
|
|
|
|
result.ACLDownPolicy = b.ACLDownPolicy
|
|
|
|
}
|
2014-08-05 22:03:47 +00:00
|
|
|
if b.ACLDefaultPolicy != "" {
|
|
|
|
result.ACLDefaultPolicy = b.ACLDefaultPolicy
|
|
|
|
}
|
2016-08-03 05:04:11 +00:00
|
|
|
if b.ACLReplicationToken != "" {
|
|
|
|
result.ACLReplicationToken = b.ACLReplicationToken
|
|
|
|
}
|
2016-12-02 03:14:08 +00:00
|
|
|
if b.ACLEnforceVersion8 != nil {
|
|
|
|
result.ACLEnforceVersion8 = b.ACLEnforceVersion8
|
|
|
|
}
|
2014-08-19 21:19:31 +00:00
|
|
|
if len(b.Watches) != 0 {
|
|
|
|
result.Watches = append(result.Watches, b.Watches...)
|
|
|
|
}
|
2014-08-21 20:09:13 +00:00
|
|
|
if len(b.WatchPlans) != 0 {
|
|
|
|
result.WatchPlans = append(result.WatchPlans, b.WatchPlans...)
|
|
|
|
}
|
2017-03-30 16:25:12 +00:00
|
|
|
if b.DisableRemoteExec != nil {
|
|
|
|
result.DisableRemoteExec = b.DisableRemoteExec
|
2014-08-29 18:24:01 +00:00
|
|
|
}
|
2014-09-02 21:49:23 +00:00
|
|
|
if b.DisableUpdateCheck {
|
|
|
|
result.DisableUpdateCheck = true
|
|
|
|
}
|
|
|
|
if b.DisableAnonymousSignature {
|
|
|
|
result.DisableAnonymousSignature = true
|
|
|
|
}
|
2015-01-21 02:53:18 +00:00
|
|
|
if b.UnixSockets.Usr != "" {
|
|
|
|
result.UnixSockets.Usr = b.UnixSockets.Usr
|
|
|
|
}
|
|
|
|
if b.UnixSockets.Grp != "" {
|
|
|
|
result.UnixSockets.Grp = b.UnixSockets.Grp
|
|
|
|
}
|
|
|
|
if b.UnixSockets.Perms != "" {
|
|
|
|
result.UnixSockets.Perms = b.UnixSockets.Perms
|
|
|
|
}
|
2015-07-30 18:22:56 +00:00
|
|
|
if b.DisableCoordinates {
|
|
|
|
result.DisableCoordinates = true
|
|
|
|
}
|
2015-03-27 05:30:04 +00:00
|
|
|
if b.SessionTTLMinRaw != "" {
|
|
|
|
result.SessionTTLMin = b.SessionTTLMin
|
|
|
|
result.SessionTTLMinRaw = b.SessionTTLMinRaw
|
|
|
|
}
|
2014-12-28 04:53:19 +00:00
|
|
|
if len(b.HTTPAPIResponseHeaders) != 0 {
|
|
|
|
if result.HTTPAPIResponseHeaders == nil {
|
|
|
|
result.HTTPAPIResponseHeaders = make(map[string]string)
|
|
|
|
}
|
|
|
|
for field, value := range b.HTTPAPIResponseHeaders {
|
|
|
|
result.HTTPAPIResponseHeaders[field] = value
|
|
|
|
}
|
|
|
|
}
|
2017-01-05 22:10:26 +00:00
|
|
|
if len(b.Meta) != 0 {
|
|
|
|
if result.Meta == nil {
|
|
|
|
result.Meta = make(map[string]string)
|
|
|
|
}
|
|
|
|
for field, value := range b.Meta {
|
|
|
|
result.Meta[field] = value
|
|
|
|
}
|
|
|
|
}
|
2014-12-28 04:53:19 +00:00
|
|
|
|
2014-04-11 23:59:16 +00:00
|
|
|
// Copy the start join addresses
|
|
|
|
result.StartJoin = make([]string, 0, len(a.StartJoin)+len(b.StartJoin))
|
|
|
|
result.StartJoin = append(result.StartJoin, a.StartJoin...)
|
|
|
|
result.StartJoin = append(result.StartJoin, b.StartJoin...)
|
|
|
|
|
2014-11-14 15:02:42 +00:00
|
|
|
// Copy the start join addresses
|
2014-11-17 22:14:59 +00:00
|
|
|
result.StartJoinWan = make([]string, 0, len(a.StartJoinWan)+len(b.StartJoinWan))
|
|
|
|
result.StartJoinWan = append(result.StartJoinWan, a.StartJoinWan...)
|
|
|
|
result.StartJoinWan = append(result.StartJoinWan, b.StartJoinWan...)
|
2014-11-14 15:02:42 +00:00
|
|
|
|
2014-10-12 17:50:15 +00:00
|
|
|
// Copy the retry join addresses
|
|
|
|
result.RetryJoin = make([]string, 0, len(a.RetryJoin)+len(b.RetryJoin))
|
|
|
|
result.RetryJoin = append(result.RetryJoin, a.RetryJoin...)
|
|
|
|
result.RetryJoin = append(result.RetryJoin, b.RetryJoin...)
|
|
|
|
|
2014-11-14 15:02:42 +00:00
|
|
|
// Copy the retry join -wan addresses
|
2014-11-17 22:14:59 +00:00
|
|
|
result.RetryJoinWan = make([]string, 0, len(a.RetryJoinWan)+len(b.RetryJoinWan))
|
|
|
|
result.RetryJoinWan = append(result.RetryJoinWan, a.RetryJoinWan...)
|
|
|
|
result.RetryJoinWan = append(result.RetryJoinWan, b.RetryJoinWan...)
|
2014-11-14 15:02:42 +00:00
|
|
|
|
2013-12-21 00:39:32 +00:00
|
|
|
return &result
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadConfigPaths reads the paths in the given order to load configurations.
|
|
|
|
// The paths can be to files or directories. If the path is a directory,
|
|
|
|
// we read one directory deep and read any files ending in ".json" as
|
|
|
|
// configuration files.
|
|
|
|
func ReadConfigPaths(paths []string) (*Config, error) {
|
|
|
|
result := new(Config)
|
|
|
|
for _, path := range paths {
|
|
|
|
f, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error reading '%s': %s", path, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fi, err := f.Stat()
|
|
|
|
if err != nil {
|
|
|
|
f.Close()
|
|
|
|
return nil, fmt.Errorf("Error reading '%s': %s", path, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !fi.IsDir() {
|
|
|
|
config, err := DecodeConfig(f)
|
|
|
|
f.Close()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error decoding '%s': %s", path, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
result = MergeConfig(result, config)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
contents, err := f.Readdir(-1)
|
|
|
|
f.Close()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error reading '%s': %s", path, err)
|
|
|
|
}
|
|
|
|
|
2013-12-27 22:49:35 +00:00
|
|
|
// Sort the contents, ensures lexical order
|
|
|
|
sort.Sort(dirEnts(contents))
|
|
|
|
|
2013-12-21 00:39:32 +00:00
|
|
|
for _, fi := range contents {
|
|
|
|
// Don't recursively read contents
|
|
|
|
if fi.IsDir() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it isn't a JSON file, ignore it
|
|
|
|
if !strings.HasSuffix(fi.Name(), ".json") {
|
|
|
|
continue
|
|
|
|
}
|
2016-02-09 15:35:39 +00:00
|
|
|
// If the config file is empty, ignore it
|
|
|
|
if fi.Size() == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2013-12-21 00:39:32 +00:00
|
|
|
|
|
|
|
subpath := filepath.Join(path, fi.Name())
|
|
|
|
f, err := os.Open(subpath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error reading '%s': %s", subpath, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
config, err := DecodeConfig(f)
|
|
|
|
f.Close()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error decoding '%s': %s", subpath, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
result = MergeConfig(result, config)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
2013-12-27 22:49:35 +00:00
|
|
|
|
|
|
|
// Implement the sort interface for dirEnts
|
|
|
|
func (d dirEnts) Len() int {
|
|
|
|
return len(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d dirEnts) Less(i, j int) bool {
|
|
|
|
return d[i].Name() < d[j].Name()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d dirEnts) Swap(i, j int) {
|
|
|
|
d[i], d[j] = d[j], d[i]
|
|
|
|
}
|
2017-06-02 10:04:04 +00:00
|
|
|
|
|
|
|
// ParseMetaPair parses a key/value pair of the form key:value
|
|
|
|
func ParseMetaPair(raw string) (string, string) {
|
|
|
|
pair := strings.SplitN(raw, ":", 2)
|
|
|
|
if len(pair) == 2 {
|
|
|
|
return pair[0], pair[1]
|
|
|
|
}
|
|
|
|
return pair[0], ""
|
|
|
|
}
|