|
|
@@ -3,7 +3,9 @@ package main
|
|
|
import (
|
|
|
"crypto/tls"
|
|
|
"flag"
|
|
|
+ "fmt"
|
|
|
"io/ioutil"
|
|
|
+ "net/url"
|
|
|
"os"
|
|
|
"strings"
|
|
|
"time"
|
|
|
@@ -41,6 +43,9 @@ var (
|
|
|
maxClusterSize int
|
|
|
|
|
|
cpuprofile string
|
|
|
+
|
|
|
+ cors string
|
|
|
+ corsList map[string]bool
|
|
|
)
|
|
|
|
|
|
func init() {
|
|
|
@@ -51,8 +56,10 @@ func init() {
|
|
|
flag.StringVar(&machinesFile, "CF", "", "the file contains a list of existing machines in the cluster, seperate by comma")
|
|
|
|
|
|
flag.StringVar(&argInfo.Name, "n", "default-name", "the node name (required)")
|
|
|
- flag.StringVar(&argInfo.EtcdURL, "c", "127.0.0.1:4001", "the hostname:port for etcd client communication")
|
|
|
- flag.StringVar(&argInfo.RaftURL, "s", "127.0.0.1:7001", "the hostname:port for raft server communication")
|
|
|
+ flag.StringVar(&argInfo.EtcdURL, "c", "127.0.0.1:4001", "the advertised public hostname:port for etcd client communication")
|
|
|
+ flag.StringVar(&argInfo.RaftURL, "s", "127.0.0.1:7001", "the advertised public hostname:port for raft server communication")
|
|
|
+ flag.StringVar(&argInfo.EtcdListenHost, "cl", "", "the listening hostname for etcd client communication (defaults to advertised ip)")
|
|
|
+ flag.StringVar(&argInfo.RaftListenHost, "sl", "", "the listening hostname for raft server communication (defaults to advertised ip)")
|
|
|
flag.StringVar(&argInfo.WebURL, "w", "", "the hostname:port of web interface")
|
|
|
|
|
|
flag.StringVar(&argInfo.RaftTLS.CAFile, "serverCAFile", "", "the path of the CAFile")
|
|
|
@@ -76,6 +83,8 @@ func init() {
|
|
|
flag.IntVar(&maxClusterSize, "maxsize", 9, "the max size of the cluster")
|
|
|
|
|
|
flag.StringVar(&cpuprofile, "cpuprofile", "", "write cpu profile to file")
|
|
|
+
|
|
|
+ flag.StringVar(&cors, "cors", "", "whitelist origins for cross-origin resource sharing (e.g. '*' or 'http://localhost:8001,etc')")
|
|
|
}
|
|
|
|
|
|
const (
|
|
|
@@ -108,6 +117,9 @@ type Info struct {
|
|
|
EtcdURL string `json:"etcdURL"`
|
|
|
WebURL string `json:"webURL"`
|
|
|
|
|
|
+ RaftListenHost string `json:"raftListenHost"`
|
|
|
+ EtcdListenHost string `json:"etcdListenHost"`
|
|
|
+
|
|
|
RaftTLS TLSInfo `json:"raftTLS"`
|
|
|
EtcdTLS TLSInfo `json:"etcdTLS"`
|
|
|
}
|
|
|
@@ -148,6 +160,8 @@ func main() {
|
|
|
raft.SetLogLevel(raft.Debug)
|
|
|
}
|
|
|
|
|
|
+ parseCorsFlag()
|
|
|
+
|
|
|
if machines != "" {
|
|
|
cluster = strings.Split(machines, ",")
|
|
|
} else if machinesFile != "" {
|
|
|
@@ -179,6 +193,9 @@ func main() {
|
|
|
argInfo.EtcdURL = sanitizeURL(argInfo.EtcdURL, etcdTLSConfig.Scheme)
|
|
|
argInfo.WebURL = sanitizeURL(argInfo.WebURL, "http")
|
|
|
|
|
|
+ argInfo.RaftListenHost = sanitizeListenHost(argInfo.RaftListenHost, argInfo.RaftURL)
|
|
|
+ argInfo.EtcdListenHost = sanitizeListenHost(argInfo.EtcdListenHost, argInfo.EtcdURL)
|
|
|
+
|
|
|
// Read server info from file or grab it from user.
|
|
|
if err := os.MkdirAll(dirPath, 0744); err != nil {
|
|
|
fatalf("Unable to create path: %s", err)
|
|
|
@@ -191,11 +208,29 @@ func main() {
|
|
|
snapConf = newSnapshotConf()
|
|
|
|
|
|
// Create etcd and raft server
|
|
|
- e = newEtcdServer(info.Name, info.EtcdURL, &etcdTLSConfig, &info.EtcdTLS)
|
|
|
- r = newRaftServer(info.Name, info.RaftURL, &raftTLSConfig, &info.RaftTLS)
|
|
|
+ e = newEtcdServer(info.Name, info.EtcdURL, info.EtcdListenHost, &etcdTLSConfig, &info.EtcdTLS)
|
|
|
+ r = newRaftServer(info.Name, info.RaftURL, info.RaftListenHost, &raftTLSConfig, &info.RaftTLS)
|
|
|
|
|
|
startWebInterface()
|
|
|
r.ListenAndServe()
|
|
|
e.ListenAndServe()
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+// parseCorsFlag gathers up the cors whitelist and puts it into the corsList.
|
|
|
+func parseCorsFlag() {
|
|
|
+ if cors != "" {
|
|
|
+ corsList = make(map[string]bool)
|
|
|
+ list := strings.Split(cors, ",")
|
|
|
+ for _, v := range list {
|
|
|
+ fmt.Println(v)
|
|
|
+ if v != "*" {
|
|
|
+ _, err := url.Parse(v)
|
|
|
+ if err != nil {
|
|
|
+ panic(fmt.Sprintf("bad cors url: %s", err))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ corsList[v] = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|