From 35b01b982c5f180b68c6cdf2e3789efc6a8a04f3 Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Mon, 26 Mar 2018 11:06:31 -0700 Subject: [PATCH] etcdmain: use NewUniqueURLsWithExceptions Signed-off-by: Gyuho Lee --- etcdmain/config.go | 53 ++++++++++++++++++++++++++++++++++------------ etcdmain/help.go | 11 +++------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/etcdmain/config.go b/etcdmain/config.go index 6a74c4737..921374321 100644 --- a/etcdmain/config.go +++ b/etcdmain/config.go @@ -128,12 +128,22 @@ func newConfig() *config { fs.StringVar(&cfg.configFile, "config-file", "", "Path to the server configuration file") // member - fs.Var(cfg.ec.CorsInfo, "cors", "Comma-separated white list of origins for CORS (cross-origin resource sharing).") fs.StringVar(&cfg.ec.Dir, "data-dir", cfg.ec.Dir, "Path to the data directory.") fs.StringVar(&cfg.ec.WalDir, "wal-dir", cfg.ec.WalDir, "Path to the dedicated wal directory.") - fs.Var(flags.NewURLsValue(embed.DefaultListenPeerURLs), "listen-peer-urls", "List of URLs to listen on for peer traffic.") - fs.Var(flags.NewURLsValue(embed.DefaultListenClientURLs), "listen-client-urls", "List of URLs to listen on for client traffic.") - fs.Var(flags.NewURLsValue(""), "listen-metrics-urls", "List of URLs to listen on for metrics.") + fs.Var( + flags.NewUniqueURLsWithExceptions(embed.DefaultListenPeerURLs, ""), + "listen-peer-urls", + "List of URLs to listen on for peer traffic.", + ) + fs.Var( + flags.NewUniqueURLsWithExceptions(embed.DefaultListenClientURLs, ""), "listen-client-urls", + "List of URLs to listen on for client traffic.", + ) + fs.Var( + flags.NewUniqueURLsWithExceptions("", ""), + "listen-metrics-urls", + "List of URLs to listen on for metrics.", + ) fs.UintVar(&cfg.ec.MaxSnapFiles, "max-snapshots", cfg.ec.MaxSnapFiles, "Maximum number of snapshot files to retain (0 is unlimited).") fs.UintVar(&cfg.ec.MaxWalFiles, "max-wals", cfg.ec.MaxWalFiles, "Maximum number of wal files to retain (0 is unlimited).") fs.StringVar(&cfg.ec.Name, "name", cfg.ec.Name, "Human-readable name for this member.") @@ -148,8 +158,16 @@ func newConfig() *config { fs.DurationVar(&cfg.ec.GRPCKeepAliveTimeout, "grpc-keepalive-timeout", cfg.ec.GRPCKeepAliveTimeout, "Additional duration of wait before closing a non-responsive connection (0 to disable).") // clustering - fs.Var(flags.NewURLsValue(embed.DefaultInitialAdvertisePeerURLs), "initial-advertise-peer-urls", "List of this member's peer URLs to advertise to the rest of the cluster.") - fs.Var(flags.NewURLsValue(embed.DefaultAdvertiseClientURLs), "advertise-client-urls", "List of this member's client URLs to advertise to the public.") + fs.Var( + flags.NewUniqueURLsWithExceptions(embed.DefaultInitialAdvertisePeerURLs, ""), + "initial-advertise-peer-urls", + "List of this member's peer URLs to advertise to the rest of the cluster.", + ) + fs.Var( + flags.NewUniqueURLsWithExceptions(embed.DefaultAdvertiseClientURLs, ""), + "advertise-client-urls", + "List of this member's client URLs to advertise to the public.", + ) fs.StringVar(&cfg.ec.Durl, "discovery", cfg.ec.Durl, "Discovery URL used to bootstrap the cluster.") fs.Var(cfg.cf.fallback, "discovery-fallback", fmt.Sprintf("Valid values include %q", cfg.cf.fallback.Valids())) @@ -186,7 +204,13 @@ func newConfig() *config { fs.BoolVar(&cfg.ec.PeerAutoTLS, "peer-auto-tls", false, "Peer TLS using generated certificates") fs.StringVar(&cfg.ec.PeerTLSInfo.CRLFile, "peer-crl-file", "", "Path to the peer certificate revocation list file.") fs.StringVar(&cfg.ec.PeerTLSInfo.AllowedCN, "peer-cert-allowed-cn", "", "Allowed CN for inter peer authentication.") - fs.Var(flags.NewStringsValue(""), "host-whitelist", "Comma-separated acceptable hostnames from HTTP client requests, if server is not secure (empty means allow all).") + + fs.Var( + flags.NewUniqueURLsWithExceptions("*", "*"), + "cors", + "Comma-separated white list of origins for CORS, or cross-origin resource sharing, (empty or * means allow all)", + ) + fs.Var(flags.NewUniqueStringsValue("*"), "host-whitelist", "Comma-separated acceptable hostnames from HTTP client requests, if server is not secure (empty means allow all).") // logging fs.BoolVar(&cfg.ec.Debug, "debug", false, "Enable debug-level logging for etcd.") @@ -261,12 +285,15 @@ func (cfg *config) configFromCmdLine() error { plog.Fatalf("%v", err) } - cfg.ec.LPUrls = flags.URLsFromFlag(cfg.cf.flagSet, "listen-peer-urls") - cfg.ec.APUrls = flags.URLsFromFlag(cfg.cf.flagSet, "initial-advertise-peer-urls") - cfg.ec.LCUrls = flags.URLsFromFlag(cfg.cf.flagSet, "listen-client-urls") - cfg.ec.ACUrls = flags.URLsFromFlag(cfg.cf.flagSet, "advertise-client-urls") - cfg.ec.HostWhitelist = flags.StringsFromFlag(cfg.cf.flagSet, "host-whitelist") - cfg.ec.ListenMetricsUrls = flags.URLsFromFlag(cfg.cf.flagSet, "listen-metrics-urls") + cfg.ec.LPUrls = flags.UniqueURLsFromFlag(cfg.cf.flagSet, "listen-peer-urls") + cfg.ec.APUrls = flags.UniqueURLsFromFlag(cfg.cf.flagSet, "initial-advertise-peer-urls") + cfg.ec.LCUrls = flags.UniqueURLsFromFlag(cfg.cf.flagSet, "listen-client-urls") + cfg.ec.ACUrls = flags.UniqueURLsFromFlag(cfg.cf.flagSet, "advertise-client-urls") + cfg.ec.ListenMetricsUrls = flags.UniqueURLsFromFlag(cfg.cf.flagSet, "listen-metrics-urls") + + cv := flags.UniqueURLsMapFromFlag(cfg.cf.flagSet, "cors") + cfg.ec.CorsInfo = &cv + cfg.ec.HostWhitelist = flags.UniqueStringsFromFlag(cfg.cf.flagSet, "host-whitelist") cfg.ec.ClusterState = cfg.cf.clusterState.String() cfg.cp.Fallback = cfg.cf.fallback.String() diff --git a/etcdmain/help.go b/etcdmain/help.go index 88c5870fe..ca3f3ccbf 100644 --- a/etcdmain/help.go +++ b/etcdmain/help.go @@ -41,7 +41,6 @@ var ( ` flagsline = ` member flags: - --name 'default' human-readable name for this member. --data-dir '${name}.etcd' @@ -62,8 +61,6 @@ member flags: maximum number of snapshot files to retain (0 is unlimited). --max-wals '` + strconv.Itoa(embed.DefaultMaxWALs) + `' maximum number of wal files to retain (0 is unlimited). - --cors '' - comma-separated whitelist of origins for CORS (cross-origin resource sharing). --quota-backend-bytes '0' raise alarms when backend size exceeds the given quota (0 defaults to low space quota). --max-txn-ops '128' @@ -78,7 +75,6 @@ member flags: additional duration of wait before closing a non-responsive connection (0 to disable). clustering flags: - --initial-advertise-peer-urls 'http://localhost:2380' list of this member's peer URLs to advertise to the rest of the cluster. --initial-cluster 'default=http://localhost:2380' @@ -114,7 +110,6 @@ clustering flags: Accept etcd V2 client requests. proxy flags (v2 API only): - --proxy 'off' proxy mode setting ('off', 'readonly' or 'on'). --proxy-failure-wait 5000 @@ -129,7 +124,6 @@ proxy flags (v2 API only): time (in milliseconds) for a read to timeout. security flags: - --cert-file '' path to the client server TLS cert file. --key-file '' @@ -154,11 +148,12 @@ security flags: peer TLS using self-generated certificates if --peer-key-file and --peer-cert-file are not provided. --peer-crl-file '' path to the peer certificate revocation list file. + --cors '*' + comma-separated whitelist of origins for CORS, or cross-origin resource sharing, (empty or * means allow all). --host-whitelist '' - acceptable hostnames from HTTP client requests, if server is not secure (empty means allow all). + acceptable hostnames from HTTP client requests, if server is not secure (empty or * means allow all). logging flags - --debug 'false' enable debug-level logging for etcd. --log-package-levels ''